98
loading...
This website collects cookies to deliver better user experience
Magento\InventorySalesApi\Api\StockResolverInterface
and Magento\InventorySalesApi\Api\GetProductSalableQtyInterface
into the constructor of the class.public function __construct(
...
\Magento\InventorySalesApi\Api\StockResolverInterface $stockResolver,
\Magento\InventorySalesApi\Api\GetProductSalableQtyInterface
$getProductSaleableQty
...){
...
$this->stockResolver = $stockResolver;
$this->getProductSaleableQty = $getProductSaleableQty;
}
GetProductSalableQtyInterface
to get the saleable quantity of the product.StockResolverInterface
. These terminologies come from MSI feature of Magento.public function getProductSaleableQty($productSku, $websiteCode){
$stockId = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode)->getStockId();
try{
$qty = $this->getProductSalableQty->execute($productSku, $stockId);
} catch(Exception $exception){
$qty = 0;
}
return $qty;
}
SalesChannelInterface
is from Magento\InventorySalesApi\Api\Data\SalesChannelInterface
.GetSourcesAssignedToStockOrderedByPriorityInterface
StockRepositoryInterface
to get the details of the stock.IsProductAssignedToStockInterface
AreProductsSalableInterface
.AreProductsSalableForRequestedQtyInterface