2D Array - Does not updating quantity as i want

ediguana

New Member
I got a shopping cart code that using a 2D Array to store user order in a Session!
We have some const here:\[code\]CONST CART_Product_ID = 0CONST CART_Product_NAME = 1CONST CART_Product_PRICE = 0CONST CART_Product_QUANTITY = 3\[/code\]
My first question is here!!
why these constants defined? and why got value 0-1-0-3 ?!in next step it get variables from a form like this:\[code\]Dim Product_ID, Product_Name, Product_Price, Product_QtyProduct_ID = trim(request("pro_id")) Product_Name = trim(request("pro_name")) Product_Price = trim(request("pro_price"))Product_Qty = trim(request("pro_qty"))\[/code\]
and in next step, it check out that there is a session and if not create one:\[code\]If not isArray(Session("Cart")) then dim localCart(4,50)ELSE localCart = Session("Cart") End If\[/code\]
in next step it check the array to Add or update quantity of item like this:\[code\]Dim FoundIt, iif Product_ID <> "" then FoundIt = False For i = 0 to ubound(localCart) If localCart(CART_Product_ID,i) = Product_ID then localCart(CART_Product_QUANTITY,i) = localCart(CART_Product_QUANTITY,i)+1 FoundIt = true EXIT For End If NEXT If NOT FoundIt then For i = 0 to ubound(localCart,2) If localCart(CART_Product_ID,i) = "" Then localCart(CART_Product_ID,i) = Product_ID localCart(CART_Product_NAME,i) = Product_Name localCart(CART_Product_PRICE,i) = Product_Price localCart(CART_Product_QUANTITY,i) = Product_Qty EXIT For End If NEXT End IfEnd IfSession("Cart") = localCart\[/code\]
And some problems is here!!
1- when i post a same product to this page ( product_ID=1), it add more and more instead of updating the Quantity, Why?!2-when i want to write content of array like this:
\[code\]Dim OrderTotalOrderTotal = 0for i = 0 to ubound(localCart,2) if localCart(CART_Product_ID, i) <> "" then orderTotal = orderTotal + (localCart(CART_Product_PRICE,i)) * localCart(CART_Product_QUANTITY,i) Response.Write("Product ID = "& localCart(CART_Product_ID,i) &"<br/>") Response.Write("Product Name = "& localCart(CART_Product_NAME,i) &"<br/>") Response.Write("Product Price = "& localCart(CART_Product_PRICE,i) &"<br/>") Response.Write("Product Qty= "& localCart(CART_Product_QUANTITY,i) &"<br/>") end ifnextResponse.Write ("Total = "& formatCurrency(orderTotal) &"")\[/code\]
It instead of price, show me the product id!!
oupput is like this:Product ID = 1
Product Name = Cheese
Product Price = 1 !!!!!!!
Product Qty = 1

Please guide me! :(
 
Back
Top