How can I make an SKU unavailable in the ecommerce if the stock is below a certain amount?

Dear community,
I’d like to make SKUs unavailable to buy if the stock is below a certain amount, so even if the integrations are slow to update the inventory, I know nothing will be sold if it’s not in stock. I saw this, and I think maybe it can be done with availableQuantityContainer ; but I’m not sure how to do it.
Can you please help me?
Thank you very much, have a very nice week :raised_hands:

3 Likes

I can’t think of anything native. Some of our marketplace connectors (e.g. Amazon, Mercado Libre) have a setting that is similar to the behavior you are looking for – we call it minimum stock control.

If I were to implement something custom, I would create an app to:

  • Create and update a table of SKUs with minimum stock settings and/or a global stock minimum on Master Data (probably with an admin interface)

  • Listen to the orders feed so it would be notified if every new order placed

  • For every new order, go through all SKUs to see if any have a minimum stock setting on the Master Data table we set up

  • For every SKU with a minimum stock setting, check the current inventory available using Logistics API and see whether it is less than or equal to the threshold set

  • For every SKU below the threshold, set the inventory level to zero using Logistics API and log that action somewhere (to allow for manual recovery of the original stock level if needed)

That’s the overall idea I would go for. There might be gotchas in the implementation to look out for, like:

  • Would I need to update inventory level in multiple warehouses or multiple sellers?

  • Would these operations be quick enough for peak demand situations, when that kind of behavior is most needed?

  • Would there be any conflict in my inventory updates made by my ERP?

But that’s what I think is possible. Maybe someone else has a better idea or knows about a hidden feature I’m not aware of, though :nerd_face:

3 Likes

Hi @Coca, welcome back to VTEX Community!

Maybe I would try to do it a bit different from @georgebrindeiro’s approach.

In place of using VTEX Orders Feed, my choice is the VTEX Order Hooks.

Using the VTEX Order Hook, you will configure an endpoint to get notified each new purchase for all orders from a desired order status like payment-approved or canceled.

Then, with your endpoint receiving the Order Id, you could get all data from order using the VTEX IO Clients if you create a VTEX IO Service. Or use VTEX Get Orders API to get the order data including the SKUs to check it over Logistic Inventory API, and then, if detect a minimum stock, you should sent a “ActivateIfPossible” as false to Update SKU API.

Other subject that you could investigate should be How the reservation works.

Reservation is a VTEX solution that prevents the same item from being sold more than once. After a purchase is completed, the purchased item is subtracted from the available inventory and its status is changed to Reserved.

2 Likes