I am currently working on a shopping cart project rn for a certain subject. This is how I implement my shoppong cart
Products are read from an xml file (I don't have much of an idea on how to use sql yet so...) w/ the following details: prodID, prodName, prodDesc, prodPrice, and prodStock
Every time the user adds items to their cart, the items' respective stocks are updated on the xml file.
Other things: I'm using a session variable, $_SESSION['items'], which is the cart of the user. This session variable is an array of objects, Product, which contains the following: prodID, prodName, prodPrice, prodQTY(the number the user wants). I don't implement the login system here since it might be annoying for the users, IMO.
When the user buys the products he added into the cart, there is no problem. However, whenever the user abandons the cart (via browser close or whatnot), the stocks of said items do not go back to their original states. Is there any way for me to keep track the case of a cart abandoment? Or is there something about my implementation I need to change?
My advice would be to not change stock levels until the user has been through the checkout process.
Until they have confirmed the purchase neither the merchant nor the customer has entered into a contract and there for stock levels should not change.