如何在Magento 1.9中向产品添加堆栈标签

时间:2016-03-29 13:45:05

标签: magento magento-1.9

我正在寻找正确的解决方案,以标记缺货的产品,但直到现在找不到合适的解决方案。我正在使用INFORTIS的ULTIMO模板。我尝试了以下但没有成功:

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

$qty $stock->getQty();

if($qty <= 0)
{
    <span class="out-of-stock"><span>Sold Out</span></span>
}

知道我还能尝试什么吗?

感谢

2 个答案:

答案 0 :(得分:0)

$model = Mage::getModel('catalog/product'); 
$_product = $model->load($product_id); 
$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
                ->loadByProduct($_product)->getQty();
if($stocklevel <= 0)
{
    <span class="out-of-stock"><span>Sold Out</span></span>
}

答案 1 :(得分:0)

$product_model =  Mage::getModel('catalog/product');
$product_id = $product_model ->getIdBySku($productsku);
$productload = $product_model ->load($product_id);

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productload );

if($stock <= 0)
{

<span class="out-of-stock"><span>Sold Out</span></span></pre>

}