Showing posts with label products. Show all posts
Showing posts with label products. Show all posts

Thursday, March 29, 2012

Session Variable

I'm using on my shopping cart a session variable to store all products that user have put in to the cart.
The script that I use is writen from a book that I bought. I managed to edit the script so that It suites me.
But I have a problem., The book don't tell how to do the checkoutfunction. How can I get all values from the session variable and storethem to my database.
Major problem is that I don't know how to do the for loop that shouldreed the session variable and give value to the parameters.
Session variable (cart) have following variables stored (cartid:integer, PID:integer , PAKID:Integer , Productname:String , Quantity:integer ,Price:Decimal)
Please Help me with this.
If you download the source code for the Commerce Starter Kit from the "Starter Kits" tab on this web site, it has a great example on how to handle storing items in a shopping cart, and then handling the checkout.
smtraber
It's prity big I'm not so good at coding. I have mostly of my time used Dreamweaver.


<%
For Each Cartid in Session("cart")
       Response.Write cartid & "=" & Session("cart") & "<br>"
Next
%>
Wuold this work to print the cartid in the session cart.
I have in the session following strings also: PID,PAKID,quantity all integer and price as decimal and productname as string
How should I insert the code into this for each loop so I would get value of all the variables in the session varibale

Thursday, March 22, 2012

Session variables

I'm designing like a shopping cart and have a product list which is an xml file consisting of products and prices which is loaded into a dataset then bound to a datagrid

There are buttons next to each product by clicking one of these should direct the user to another form showing the choice of product and price in textboxes, I can't load the info into the next form using session variables

My code is below

1st form code

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the path of XML file and schema
Dim strPath As String = Server.MapPath(".")
' Declare a dataset
Dim dsProducts As New DataSet
' Apply the XML schema to the dataset
dsProducts.ReadXmlSchema(strPath & "\Products.xsd")
' Read the XML into the data set
dsProducts.ReadXml(strPath & "\Products.xml")
DataGrid1.DataSource = dsProducts
DataGrid1.DataBind()
Session.Item("Product1") = "Jam Doughnut"

End Sub

Private Sub btnJam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnJam.Click

Server.Transfer("order.aspx")

2nd form code

Dim product1 as string = session.item("Product1")

End Sub

As you can see I'm trying to create the session variables before the next form is loaded but can't seem to load these into the next form, for example if jam doughnut is selected then jam doughnut and 0.35 should appear in textboxes on the next form or if apple doughnut is selected then apple doughnut and 0.40 should appear in the texboxes on the next form instead

Any advice would be appreciated

ThanksI don't understand your problem. On your next page when you do...

<% Session.Item("Product") %>

does it list the item on the page?
So what is preventing you from using it?
If the dataset isn't too large, you might want to consider just loading the dataset into a session and then pulling the data out on each page.

Session("products") = dsProducts

then on each page you can get it back:

dim ds as DataSet = Ctype(Session("products"),DataSet)

then you have your stuff in ds...
Thanks, I'm stuck now on how to retrieve the info from the dataset

I've put session("products")= dsproducts after datagrid.databind in the form load event procedure and Dim ds As DataSet = CType(Session("products"), DataSet) in the next form

I will need to put server.transfer("order.apx")for the 5 button click event procedures depending on what button is clicked then load the required choice in the textboxes on the next form

Any advice would be appreciated

Thanks
There are buttons next to each product by clicking one of these should direct the user to another form showing the choice of product and price in textboxes

Don't use session variables then. Redirect the user to

Product.aspx?productid=2389472

Where 2389472 is the ID of the product. In Product.aspx, query the database based upon the querystring parameter and get the info you need.