سؤال

I've made some invoice template modifications in:

/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

to allow for custom attributes such as manufacturer to be on the invoice.

This code works, however it spits out the manufacturer id and I need the label.

 $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
              );
    }

Eg - I'm getting 4138 when I need 'Nike'

I've tried this which would work on the front end but I get an error: Fatal error: Call to a member function getResource() on a non-object

$_product->getResource()->getAttribute('pos_short_colour')->getFrontend()->getValue($_product)

So how can I call the label instead of the ID in an invoice template.

P.S. I've also tried playing around with getData / getLabel / getText

هل كانت مفيدة؟

المحلول

You can get the label of an attribute by using the getAttributeText() function. For example:

$text = $product->getAttributeText('manufacturer');

Also, the error you're seeing with your second bit of code I believe is because you're using $_product, which is undefined/null. Try $product instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top