Jump to content

Shopping cart merge/update information for one product.


valourous

Recommended Posts

Hey guys,

 

Lovely forum. So I'm building a simple shopping cart from php and mysql. Whenever I update the quantity of the item that I want, I don't want it to duplicate all of the information but instead want it to merge the quantity together.

 

Below is an example of what happens. Note that Test Item has been added to the cart 3 separate times with different quantities (2, 1, and 1). How can I merge this information to show Test Item once with the total quantity? I know it's some kind of merge, but I'm a coding noob. Thanks!

 

tesem.jpg

 

 

Here is some (maybe) relevant information:

$insert = "INSERT INTO new_cart (sku, quantity, username) VALUES ('".$ssku."', '".$squantity."', '".$username."')";



mysql_query($insert);

}
echo "<table>";

$select = "SELECT * FROM new_cart JOIN products ON new_cart.sku = products.sku where '".$username."' = new_cart.username";

What needs to be changed or updated?

 

EDIT: If you need more information, feel free to let me know and I'll post it.  :D

 

 

 

Link to comment
Share on other sites

you could set up an if function to see if the sku number is already inside of your database...and if it is, grab the quantity value that is already in the database, add the new value onto it, and put your new quantity back into your database

Link to comment
Share on other sites

I know that it needs to be an if statement so that if the SKU already exists, it will simply update the quantity of the item. This is some kind of merge function, correct? If you could show me the code that makes this possible, it would be much appreciated. Let me know if you need more information/code.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.