less than a minute read • Updated 9 minutes ago
Set up advanced inventory tracking with inventory locks
How to combine inventory locks with Foxy's cart JavaScript events and webhooks to reserve stock and prevent overselling on limited or one-off products.
For stores that can’t afford to oversell — one-off items or products with strict limits like event tickets — combine inventory locks with Foxy’s cart JavaScript events and webhooks to reserve stock the moment a customer adds a product to their cart.
How to set it up
1Expand your own inventory system to track inventory locks — temporary holds on a specific quantity of a product tied to a customer’s cart. For example, if you’re tracking inventory in a database, add a table for locks with columns for the transaction ID, product ID or code, and how long the lock should last.
2On your add-to-cart page, calculate a product’s available stock by taking its normal inventory level and subtracting any active locks for that product. Use this adjusted value to determine whether the product is out of stock, and to set its quantity_max value.
3Set the expires attribute on the product to a time slightly before the corresponding lock is set to expire in your database. This avoids a gap where stock could become available again before the lock has actually cleared for the customer currently holding it.
4Use Foxy’s cart JavaScript events to create, update, and remove locks as customers interact with their cart. The relevant events are cart-submit.done, cart-item-quantity-update.done, and cart-item-remove.done. Add your custom callback for these events through the Configuration page in your store’s Foxy admin, in the “footer” textarea under Add custom header and footer code to your templates.
5Within your callback, check the params parameter of the event to see what changed, and use the FC.json cart object to access other cart details you need.
6In your pre-payment webhook endpoint, confirm that existing inventory locks still match the current contents of the cart. If the cart requires more stock than is locked, confirm there’s enough available before letting the checkout proceed.
7In your transaction webhook endpoint, clear out any inventory locks tied to that transaction once you’ve adjusted your actual inventory level.
Notes
This approach requires custom development on your end — Foxy provides the cart events and webhooks, but the lock tracking, matching, and clearing logic all live in your own system.
This is the most reliable way to prevent overselling, since stock is reserved as soon as a product is added to the cart rather than only checked at transaction time.