Sylius leverages a very simple approach to inventory management. The current stock of an item is stored on the ProductVariant entity as the
InventoryUnit has a relation to a Stockable on it, in case of Sylius Core it will be a relation to the ProductVariant that implements the StockableInterface on the OrderItemUnit that implements the InventoryUnitInterface.
It represents a physical unit of the product variant that is in the magazine.
Inventory On Hold¶
Putting inventory items
onHold is a way of reserving them before the customer pays for the order. Items are put on hold when the checkout is completed.
onHold does not remove them from
onHand yet. If a customer buys 2 tracked items out of 5 being
in the inventory (
5 onHand), after the checkout there will be
5 onHand and
There is a service that will help you checking the availability of items in the inventory - AvailabilityChecker.
It has two methods
isStockAvailable (is there at least one item available) and
isStockSufficient (is there a given amount of items available).
There are two respective twig functions for checking inventory:
Inventory Operator is the service responsible for managing the stock amounts of every ProductVariant on an Order with the following methods:
hold- is called when the order’s checkout is completed, it puts the inventory units onHold, while still not removing them from onHand,
sell- is called when the order’s payment are assigned with the state
paid. The inventory items are then removed from onHold and onHand,
release- is a way of making onHold items of an order back to only onHand,
giveBack- is a way of returning sold items back to the inventory onHand,
cancel- this method works both when the order is paid and unpaid. It uses both
How does Inventory work on examples?¶
You can see all use cases we have designed in Sylius in our Behat scenarios for inventory.