1

Solved this myself, but was a pain so thought I'd share the knowledge,

In vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

in public function draw()

under lines[];

add :

$id = $item->getProductid();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($id);
$brand = $product->getAttributeText('manufacturer');

Change manufacturer to whatever custom attribute code you want.

Quick and dirty - yes I know its a mod of core code and will translate to my own module now it's working, but hope this makes others life easier.

2

The above solution failed to show some attribute and this is what worked for me:

Add the following code In

vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

in public function draw()

    $id = $item->getProductid();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $product = $objectManager->get('Magento\Catalog\Model\Product')->load($id);
    $locationCode = $product->getData('location');

Then draw the Attribute:

        $lines[0][] = [
        'text' => $locationCode,
        'feed' => 290,
        'align' => 'right',
    ];
1
  • But this code is not working in magento 2.4.0, any update ? Aug 20 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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