|
-
Mar 22nd, 2009, 05:34 AM
#1
Thread Starter
Member
[RESOLVED] Update cart quantity for same items
Hi,
Currently I have a situation where:
If someone adds and item to the cart with say a quantity of 2, then adds the same product again with a quantity of 2 (or whatever quantity), the cart shows the same item listed twice.
So I need to:
1) Check the table for whether that product exists
2) If it does, update the quantity with the old + new
3) Update the total for the orderitem
I'm assuming this will be using COUNT on the product page to determine if its there already?
I have some code on my product pages, when someone clicks "add to cart" it reloads the page and passes the productid. The following code checks if an order exists and creates one, or if one exists it adds the item to the order.
It was done a long time ago, so if its not efficient let me know as I'd be happy to change it 
Example code added.
Code to add item:
PHP Code:
// check to make sure there is a DB record $sql="SELECT count(*) thecount FROM table WHERE ID = " . $_SESSION['ID']; $result=@mysql_query($sql); $row=@mysql_fetch_row($result); if ($row[0]==0) { // if not create it $sqlcreate="INSERT INTO ..." $resultcreate=@mysql_query($sqlcreate); // get new OrderID and save in $_SESSION['ID'] $_SESSION['ID'] = mysql_insert_id(); }
} else { $sqlcreate2="INSERT INTO ..." $resultcreate2=@mysql_query($sqlcreate2); // get new ID and save in $_SESSION['ID'] $_SESSION['ID']=mysql_insert_id(); }
//get price and quantity variables via POST //calculate totalprice of item //insert orderid, quantity, price, product id and totalprice into orderitem table
Looking at it after all this time and seeing the else is the same as the if, its weird.
I also have some other questions:
- when do most people change the stock level, when an order is sent? then if not paid, admin cancels the order and it updates the stock level?
- do you put javascript or something in to check the quantity they add isn't greater then the amount in the db?
and
- I have some javascript to open a new popup window showing the enlarged image, if they click back on the main page the popup goes to the back. If they then enlarge another image, it loads in the old popup window but its still behind the main window. Anyway to force it to the front?
Thanks for you help!
Last edited by buffy; Mar 31st, 2009 at 01:05 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|