How to do Stock validation in Multi source inventory Magento 2?

Stock validation in Multi-source inventory is needed when you developing functionality with MSI of Magento 2.

Stock Validation in MSI using native interface class.
Magento\InventoryApi\Model\StockValidatorInterface

StockValidatorInterface has method called validate(StockInterface $stock);

If you want to validate the Stock of MSI, You just need to implement StockValidatorInterface in your class.

You can validate Stock related information for your requirements.

A simple example for a Stock name is valid or not using StockValidatorInterface.

Using the above code, You can validate your Stock with custom validation. In the validate method, You need to pass StockInterface Object as a parameter.

In the above code snippet, Validate the Stock is not empty and the Stock name does not equal to Default Stock.

When you Developing any functionality, You can set your custom validation for Stock data

Get Source Item info by Sku Using Multi-Source Inventory magento 2.

You can get source item details like Quantity, Status, Source item id, source code from the item Sku using Multi-source inventory (MSI) feature.

Useful Interface:
Magento\InventoryApi\Api\SourceItemRepositoryInterface Continue reading “Get Source Item info by Sku Using Multi-Source Inventory magento 2.”

Delete Stock by Stock Id Multi-source Inventory Magento 2.

You can Delete Stock by Stock Id in Multi-Source Inventory (MSI) Magento 2 programmatically by passing stock id only.

Delete the Stock data by Stock id. If the stock is not found do nothing. Continue reading “Delete Stock by Stock Id Multi-source Inventory Magento 2.”