Question

In admin orders how to include custom attribute on pdf print all action?

enter image description here

It spits out PDF with Products SKU Price Qty Tax Subtotal I need to add another which is warehouse_location I know to add label is ../../../vendor/magento/module-sales/Model/Order/Pdf/Invoice.php

How to add the values?

Was it helpful?

Solution

I've manage to add custom attribute warehouse_location to Print on PDF an bellow are the class to overwrite :

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

update draw() Method in my case:

// draw Warehouse Location
    $lines[0][] = [
        'text' => $this->getWarehouseLocation($item),
        'feed' => 240,
        'align' => 'right',
    ];

 

/vendor/magento/module-sales/Model/Order/Pdf/Items/Shipment/DefaultShipment.php

update draw() Method in my case:

// draw Warehouse Location
    $lines[0][] = [
        'text' => $this->getWarehouseLocation($item),//This you will have to build 
         to get custom attribute mime case: 
         $this->loadMyProduct($item->getSku())->getCustomAttribute('warehouse_location')->getValue()
        'feed' => 240,
        'align' => 'right',
    ];

 

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

All of the above class are to overwrite method to PDF draw()

And the Bellow are to overwrite method to PDF _drawHeader()  

update _drawHeader() Method both files:

$lines[0][] = ['text' => __('Warehouse Location'), 'feed' => 260]

/vendor/magento/module-sales/Model/Order/Pdf/Shipment.php

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

Hope it helps anyone!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top