如何检查可配置产品是否缺货?

Bog*_*ogz 6 inventory magento configurable-product

我们都知道magento中的可配置产品与简单的产品相关联.

如果与可配置产品关联的简单产品变为Inventory = 0,则表示可配置产品缺货

所以问题是我如何检测可配置产品是否缺货?我想检测所以我可以在前端显示"缺货"文字.

这样的事情

if($configurable_product->isOutOfStock()) {
   echo "Out of Stock";
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在Magento做到这一点?

Ami*_*era 7

if (!$configurable->isSaleable() ||$configurable_product->getIsInStock()==0){
// out of stock
}
Run Code Online (Sandbox Code Playgroud)

用于检查儿童简单产品:

$allProducts = $configurable->getTypeInstance(true)
                ->getUsedProducts(null, $configurable);
            foreach ($allProducts as $product) {
                if (!$product->isSaleable()|| $product->getIsInStock()==0) {
                    //out of stock for check child simple product
                }
            }
Run Code Online (Sandbox Code Playgroud)