Magento 无法获取产品可用性

Magento 无法获取产品可用性,magento,Magento,我试图在发送给客户的订单确认电子邮件中显示可用性。到目前为止,我尝试过的任何方法都不起作用: $_order = $this->getOrder(); foreach ($_order->getAllItems() as $_item): if ($_item->isSaleable()): echo $this->helper('catalog')->__('In stock'); else: echo $

我试图在发送给客户的订单确认电子邮件中显示可用性。到目前为止,我尝试过的任何方法都不起作用:

$_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;
我也试过了 $\项目->获取库存数量(); $\u项目->可用()

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

修改后的代码是

$_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;

你的代码是有道理的,但由于某种原因它不起作用。它应该在订单确认电子邮件中显示产品信息。但是代码中一定有错误,因为我使用你的代码时,电子邮件没有发送。但是我无法跟踪错误…我编辑的文件如下:app/design/frontend/base/default/template/email/order/items/order/default.phtml。这是我放置代码的地方OK,我在那里发现了一些语法错误,这就是导致错误的原因。无论如何谢谢你!