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';
   }
4
  • 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. Commented May 1, 2015 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. Commented May 1, 2015 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
    Commented May 1, 2015 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
    Commented Apr 5, 2017 at 8:01

1 Answer 1

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

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