0

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?

  • I've implemented the code standing above. I uploaded the new DefaultInvoice.php file to the FTP, refreshed the cache but it still doens't works. On the invoice isn't coming a 'locatiecode' field, also no title in de titlebar (i mean the bar where the names 'Products, SKU, price, QTY' are). I hope someone can help me out. This is (a part of) my code: public function draw() { $order = $this->getOrder(); $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); $lines = []; // draw Product name $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed – D. Verheij Oct 13 '18 at 10:50
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – liyakat Nov 7 '18 at 9:48
1

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!

|improve this answer|||||
  • What code did you use to show the attribute? Really need this but I can't get it to work. Thanks – Stifboy Sep 27 '18 at 15:05
  • @Stifboy I've update my answer. – Juliano Vargas Sep 28 '18 at 9:42
  • In which file did you overrid headers and add the new column? – zekia Nov 6 '18 at 8:18
  • @zekia All the file I mentioned above you will need to overwrite it's simple there are 2 methods to overwrite draw() and _drawHeader() just look out for them in those files! – Juliano Vargas Nov 7 '18 at 9:46

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.