use Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku;
class ClassName
{
private $getSalableQuantityDataBySku;
public function __construct(
GetSalableQuantityDataBySku $getSalableQuantityDataBySku
) {
$this->getSalableQuantityDataBySku = $getSalableQuantityDataBySku;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$sku = "testsimpleproduct1";
$salable = $this->getSalableQuantityDataBySku->execute($sku);
echo json_encode($salable);
}
}
This will give output as:
1
|
[
{
"stock_name"
:
"Default Stock"
,
"qty"
:
4
,
"manage_stock"
:
true
}
]
|
来源:oschina
链接:https://my.oschina.net/ganfanghua/blog/4307881