我在:
中进行了一些发票模板修改/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
允许制造商等自定义属性在发票上。
此代码有效,但它会吐出制造商ID,我需要标签。
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('manufacturer'));
if ($product) {
$lines[0][] = array(
'text' => Mage::helper('core/string')->str_split($manufacturer, 15),
'feed' => 220
);
}
例如 - 当我需要'耐克'时,我得到4138
我已经尝试了这可以在前端工作但我得到一个错误:致命错误:在非对象上调用成员函数getResource()
$_product->getResource()->getAttribute('pos_short_colour')->getFrontend()->getValue($_product)
那么如何在发票模板中调用标签而不是ID。
P.S。我也试过玩getData / getLabel / getText
答案 0 :(得分:1)
您可以使用getAttributeText()
函数获取属性的标签。例如:
$text = $product->getAttributeText('manufacturer');
另外,我认为您使用第二段代码看到的错误是因为您正在使用$_product
,这是未定义/ null。请尝试使用$product
。