Creating a Shopping Cart with the Data Store Component

Also keep in mind that it’s easy for the visitor to edit the values in their local storage so you should never take those values as accurate. They could change the price, for example.

What I do is pass just the product ID and the quantity to my checkout script. I then do another query using those IDs to get the prices and do the calculation again with the quantities. So even if the local storage says a product is 99p, my checkout will look it up and use the real value of £99 (for example). It would also mean that if a product is no longer available, it won’t be in the query and so the checkout won’t proceed with it.

The other values in the local storage I generally ignore. They are just used to populate the cart every time it’s viewed.

Hope that helps.