Skip to content

[Magento 2] Get Salable Qty By SKU

publicfunction __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\CatalogInventory\Api\StockStateInterface $stockState,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
){
$this->storeManager = $storeManager;
$this->stockState = $stockState;
$this->stockRegistry = $stockRegistry;
}
public function getSalableQtyByPID($product)
$websiteId = $this->storeManager->getStore()->getWebsiteId();
$stockItem = $this->stockRegistry->getStockItem($product->getId());
$minStockQty = $stockItem->getMinQty();
$qty = $this->stockRegistry->getStockStatus($subject->getId(), $websiteId)->getQty();
$cekSalableQty = $qty – $minStockQty;
$cekSalableQty = ($cekSalableQty < 0) ? 0 : $cekSalableQty;
return (bool) $cekSalableQty;
}
Share

Comments are closed.