Imagine that the buyer added three modems to the cart, and started browsing the site further. And after a while, when he decided to place an order, the “In Stock” modems became 2 pcs (one modem was bought by someone else). And in his basket 3 modems are hanging, now he will be able to place an order for 3 modems. And then in the “Available” field the number will change to “-1 ″.
So that a person could not place an order for a larger quantity of goods than are in stock, you should always after the user clicks the “Checkout” button do a check for consistency: The number of goods indicated in the basket should not exceed the number specified in the field “In stock” regarding one product. If it exceeds, then issue a message: “Such (to indicate here what kind of goods) goods in stock: n pieces. Please change the number of goods in the field of the same name and click “recalculate”.
Basically, I understood how to do it, after pressing the button, we have to place an order, call the database to compare the count. goods in stock and the quantity in the basket, if they> =, then the goods are cleared, if <=, then it displays a message that "litter blah blah blah", that's just in the code I can not write.