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

标签 magento inventory configurable-product

我们都知道 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/

相关文章:

php - Magento RESTful API 用于将产品添加到购物车

php - Magento,添加没有可配置产品的服装尺寸属性

Magento 添加产品尺寸和属性库存

C - 按零件编号升序显示零件

MySQL 获取连接表上的差异 - 股票交易/库存系统

java - 库存程序只读取一行?

api - 如何使用 magento api 创建可配置产品?

php - 如何在magento中的购物车页面上显示自定义图像

php - 观察者没有在 magento admin 中调用

php - 来自 cron 脚本的 Mage::getStoreconfig()