Multi Source Inventory (MSI) in Magento 2.3 – reservation logic

Magento 2.3 CE is coming with new inventory feature MSI or Multi Source Inventory. In this post we will explain how it works and where are modifications in code and database. If you take a look on vendor/magento folder you will see more then 30 new modules with prefix module-inventory. These all modules are in charge for new inventory logic.

So far Magento catalog-inventory didn’t have major changes in logic, but from now in Magento 2.3 inventory management has new term and workflow. This term is reservation. In shortly on every order place reservation will be created. Reservation are stored in database table: inventory_reservation. In screen shot below you can see structure of inventory_reservation table.

In this table first record is reservation, quantity value is -1 and second row is compensation of reservation for the same product. Second row is inserted after shipment is created. Second record has quantity value 1 and our reservation is compensated (-1+1=0).

The core logic how new inventory work is in module: module-inventory-sales. There are two important plugins. First is Magento\InventorySales\Plugin\CatalogInventory\ StockManagement\ProcessRegisterProductsSalePlugin and method aroundRegisterProductsSale. In method aroundRegisterProductSales there is logic for checking is specific product salable for requested qty.

Chunk of logic from method aroundRegisterProductsSale.

Method aroundRegisterProductsSale overrides old method registerProductsSale in class Magento\CatalogInventory\Model\StockManagement  and always return  empty array.

With empty array, plugin prevent reindex process in observer class Magento\CatalogInventory\Observer\SubtractQuoteInventoryObserver:

Second plugin is in charge for creating reservation is: Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin and method afterPlace.

This method is called after method place in class Magento\Sales\Model\Service\OrderService. Below you can see method place:

Mehod afterPlace from class Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin  is in charge for inserting reservation in db table inventory_reservation. 

From my experience there is possible problem, because reservation is created after order place (after mysql commit). With this inventory logic on web site with big traffic there is possibility that order will be placed, but qty (stock items) are already reserved, or product is not salable for specific qty. It means that although you placed order, maybe there is no enough items on stock (items are already reserved) and merchant will have to refund order.

And last step is decreasing qty from physical stock

If merchant ship order with non virtual products then qty from stock will be decreased when shipment is created, but if order contains only virtual products then qty will be decrease after invoice is created.

My conclusion is that this workflow will be problem for most of merchant, because from my experience merchant don’t like to ship from magento.  It means that we will have to modify this process.

All logic for decreasing stock is in module “module-inventory-shipping”. This module has two observers:

  • Magento\InventoryShipping\Observer\SourceDeductionProcessor event “sales_order_shipment_save_after”
  • Magento\InventoryShipping\Observer\VirtualSourceDeductionProcessor event “sales_order_invoice_save_after”


Last thing which we have to mention is two classes from module module-inventory-sales which is in charge for regulation is product salable and is product salable for requested qty condition.

First class Magento\InventorySales\Model\IsProductSalableCondition\IsSalableWithReservationsCondition checks current stock qty and current number of reservation from db table inventory_reservation and if curent qtyWithreservation is grether then $stockItemConfiguration->getMinQty() then product is salable. Logic you can see below:

Second class checks is product salable for requested qty condition Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\IsSalableWithReservationsCondition this class has method execute and take a look below on methods code.

This method checks for requested qty is product available. Method calculated total available qty with reservation, check variable $qtyWithReservation.

This is short explanation how new MSI inventory works and my conclusion is that we will have big problem if you upgrade Magento 2.2 to Magento 2.3. Merchants will have to change own process. They have to ship order, but if you don’t need to use multi source inventory then my suggestion is that disable it.

In next post we will explain how to configure Multi Source Inventory in Magento 2.3, what is stock and what is source, until then if you have any questions feel free to send comment 🙂

 

 

You may also like...

3 Responses

  1. Vito says:

    Hi there! Such a nice short article, thank you!

  2. Aiden says:

    Your website has outstanding content. I bookmarked the site

  3. Malinda says:

    Hi there! Such a great short article, thank you!

Leave a Reply