user1559104
user1559104

Reputation: 105

PHP:update a stock with values in the cart

I am currently working on an eCommerce website, but i need some advice regarding the stock management.

I want the shopping cart to work as follow:

i came up with 2 solutions but neither is reliable from my point of view:

  1. add a field 'champ' to Table product that initially have value of product.quantity but change with cart movements.
  2. add table Cart and update it with cart movements.

as u can see both solution require lot of work.Is there a better way to implement my shopping cart.

Upvotes: 0

Views: 628

Answers (1)

nwalke
nwalke

Reputation: 3209

I think a better way might be to only update if the user checks out and check stock on the product listing pages.

The downside being the following scenario:

  • user A adds an item to their cart
  • user B adds the same item to their cart
  • user A checks out and the item is now out of stock
  • user B checks out, but item is out of stock

You'll need to check stock at every point in this process and inform your users what's going on.

Tying up inventory by having a user placing it in their cart is a bad idea. If user A adds all of the available stock of one item to their cart, no one else can buy it until they either log out, or you log them out with some sort of timeout.

Upvotes: 3

Related Questions