Help creating a purchase count code

I am currently trying to figure out if there is a way to create a code that will show on my website a purchase countdown. I would like to start with something like “100 small heart patches left” and then, as the patches are bought, for the number to automatically count down. I am using foxycart to make the transactions. Is it possible to come up with this coding?

Hey dsellers,

I’m not familiar with foxycart, so I’m not sure how far it goes for an ecommerce site (from their site, they say they handle only the cart and checkout). Most ecommerce platforms have an “Inventory” or “Stock tracking” module where you can key your remaining stock level. You can try searching foxycart’s documentation to see if they have something like that.

If not, probably the only way you are going to have this stock remaining displayed is to

(1) store this quantity in a database
(2) read from db when you are displaying the item
(3) verify that the stock is still available at various points in your checkout pages (not only adding to cart, but also before payment, etc - because the last one might be in 10 ppl’s carts at one time.)
(4) after a successful checkout and payment, do a callback function to update your inventory

I’m sure there are other, more complex models for “locking up” the stock when its added to a cart and releasing it after a timeout period (more robust, and more work too)