0

I am trying to add custom attribute "publisher name" below product name in PDF invoice. Publisher is a custom attribute created by me.

I have copied

app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

to

app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php

And have added some code in default.php but this is not working properly. It is showing attribute id like 250,251 in the pdf but I want it to show publisher name

I add following code in default.php

$Publisher = $this->getPublisherValue($item);

 $lines[1][] = array(
        'text'  => Mage::helper('core/string')->str_split($Publisher, 35),
        'feed'  => 35
    );


private function getPublisherValue($item)
    {
        $prod = Mage::getModel('catalog/product')->load($item->getProductId());

        if(($return_publisher = $prod->getPublisher()))
            return $return_publisher;
        else
            return 'N/A';
   }
  • what kind of attribute is publisher? is it an object or string or something else? without that I am not sure how much help we can be. – David Manners May 1 '15 at 18:51
  • 4
    I'm voting to close this question as off-topic because we need to know what type publisher is before we can help out. – David Manners May 1 '15 at 18:52
  • 250,251 looks like it's a varchar attribute with the table backend. Must be a multiselect due to the comma. – Agop May 1 '15 at 19:42
  • I appologize for a stupid question, but where I need to specify the attribute that I need to retrieve? Sorry, newbie on the subject... Thanks. I have an attribute imgur.com/a/Og1dP – Artur Rain Apr 5 '17 at 8:01
1

I guss that publisher is text type attribute

if($prod->getId()){
 /* if  check product is exit   */ 
 /* check getPublisher  value is null or not */
if(!is_null($prod->getPublisher()))
    return $return_publisher;
    else
    return $prod->getPublisher();



else{
return 'N/A';
}

If it dropdown attribute then use below code to get publisher label

$product->getResource()->getAttribute('publisher')->getFrontend()->getValue($product);
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.