Portal Home > Knowledgebase > Articles Database > PHP - cart update solution


PHP - cart update solution




Posted by horizon, 01-02-2010, 11:18 PM
Hi, I'm trying to code something up with an e-commerce script by handling products. Although, I cannot seem to find the solution on how to set the right value when changing the value of quantity of products. Now, let's say the stock level is 200 products in total for a specific product. Then, I'd first, add 50 products in my cart. I have already assured that the posted quantity value does not exceed its stock level (200 max in this case). What would be the right math formula (equation) to update the quantity of products and result the right value ? It would be right to assume that three variables are needed for this but I only need the equation on how this could be done. Any help ?

Posted by htbsales, 01-02-2010, 11:55 PM
I guess it would be something like..... x=stock level y=current order z=product quantity x-y=z The product quantity in most systems like for whmcs is a auto decreasing value based on the orders but it doesn't have a mechanism to increase by any action other than it being manually set. So the 'X' value seems to be just be a placeholder. Would you have a flag that you indicate if the system should check for quantity before allowing the order? This would probably look so much more intelligent as a select and/or update statement.

Posted by horizon, 01-03-2010, 10:14 AM
The stock level has already been programmed that only if a valid order has been checked out, the quantity level will, then, decrease from the stock. However, what I only need is the right equation to return the right values in the shopping cart before the SQL update query executes ... x-y=z ... this would not suffice since it would only distinguish that the total of quantity minus the current quantity would result the updated quantity. Although, by doing so, if I have 200 and decide to add one more (which should not be possible but seem to be anyway) - the value returns 201 for some reason ... Which is why, the right equation is needed ... any ideas ?

Posted by TomNet, 01-03-2010, 11:46 AM
I am not sure what you mean. If your stock has a max of 200 you control that in the admin interface when staff are adding stock to the system. An example is someone tries to add 1 when there is already 200 you return an error saying "full" and don't run the mysql update, a simple if statement. As far as I can understand there should be no other point in your script where someone can increase the stock amount. On checkout to show the current stock level you simply do a SQL query to see how much stock there is. As until its paid for its still in the stock. Finally when they order and pay for the items you run a SQL to x-y=z updating the stock level as required.

Posted by horizon, 01-03-2010, 12:45 PM
Looks like I needed a temp SQL table to reduce the products quantity as well as the other values (level balancing as we call it). If one is not being balanced and the other values are being so - it will not work. All three values needs to be balanced in this case. Glad I finally got it resolved.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Heart Internet (Views: 29018)
Sites not loading?! :( (Views: 820)


Language:

LoadingRetrieving latest tweet...

Back to Top Copyright © 2018 DC International LLC. - All Rights Reserved.