浏览文章
文章信息
Magento2.3.x解决前端库存显示为零问题
14389
magento2.3.x加入了多源库存,但是目前还存在部分问题
1、店铺前端始终显示库存为零情况解决。
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface'); $SalableQuantity = $objectManager->get('Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku'); $salable = $SalableQuantity->execute($_product->getSku()); $qty = 0; foreach($salable as $able){ $qty += isset($able['qty'])?$able['qty']:0; } // TODO $qty是真正的可售产品数量