我们都知道 magento 中的可配置产品与简单产品相关联。
如果与可配置产品关联的简单产品变为Inventory = 0,则表示可配置产品缺货
所以问题是我如何检测可配置产品是否缺货?我想检测以便我可以在前端显示“缺货”文本。
像这样的东西
if($configurable_product->isOutOfStock()) {
echo "Out of Stock";
}
我怎样才能在 Magento 中做到这一点?
最佳答案
if (!$configurable->isSaleable() ||$configurable_product->getIsInStock()==0){
// out of stock
}
用于检查 child 简单产品:
$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
}
}
关于magento - 如何检查可配置产品是否缺货?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25323090/