无法获得产品供应

时间:2014-07-03 07:39:14

标签: magento

我正在尝试在订单确认电子邮件中显示可用性,该电子邮件已发送到客户端。到目前为止我尝试过的任何东西都不起作用:

$_order = $this->getOrder();
foreach ($_order->getAllItems() as $_item):

    if ($_item->isSaleable()):
          echo $this->helper('catalog')->__('In stock');
    else:
          echo $this->helper('catalog')->__('Out of stock');
    endif;

endforeach;

我也试过了 $ _item-> getStockQty(); $ _item-> isAvailable();

为什么这不起作用?你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

修改后的代码是

$_order = $this->getOrder();
foreach ($_order->getAllItems() as $_item):

    if(($_item->getProduct()->getSku()==$_item->getSku()){

    if ($_item->getProduct()->isSaleable()):
              echo $this->helper('catalog')->__('In stock');
        else:
              echo $this->helper('catalog')->__('Out of stock');
        endif;
    }else{

    $product=Mage::getModel('catalog/product');
    $product->loadByAttribute('sku',$_item->getSku())

    if (($_item->getProduct()->isSaleable()) && ($product->isSaleable()):
              echo $this->helper('catalog')->__('In stock');
        else:
              echo $this->helper('catalog')->__('Out of stock');
        endif;



    }
foreach;