cancel
Showing results for 
Search instead for 
Did you mean: 

Add short description to Magento 2 pdf invoice

SOLVED

Add short description to Magento 2 pdf invoice

Hello,

 

I would like to add the product short description on the pdf invoices.

 

I figured out that the name is drawn on line :

$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

around line 69 of vendor/magento/module-sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php

 

But I can't manage to get short description there; I would like  something like :

product name<br />product short description

 

I tried $this->string->split($item->getShortDescription(), but I must be missing to call the right controller or item attributes.

 

Any idea on how to get this done please ?

 

Best regards,

David

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Add short description to Magento 2 pdf invoice

You cant get product short_description from item object.

 

If you want product long description only,
You can get using $item->getDescription() but item object not store short description.

 

 

You have to do manually add short description by adding below code in your file.
You have to override your defaultInvoice.php file,

Keep below line of code in your file,

$objManager = \Magento\Framework\App\ObjectManager::getInstance();
$itemId = $item->getProductId();
$productObject = $objManager->create('Magento\Catalog\Model\Product')->load($itemId);
/* use for strip tag from short description */ $short_description =$this->filterManager->stripTags($productObject->getShortDescription());

Please let me know if you have any query.

If issue solved, click kudos/accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

3 REPLIES 3

Re: Add short description to Magento 2 pdf invoice

Hey,

@ShapesGS

 

Magento does not store description info into order info, so you need to load product then you will get product description or short description.

 

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
		$description = $objectManager->create('Magento\Catalog\Model\Product')->load($item->getProductId())->getShortDescription();

You need to work with PDF position to add long description into PDF.

 

If work for you then mark as solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Add short description to Magento 2 pdf invoice

You cant get product short_description from item object.

 

If you want product long description only,
You can get using $item->getDescription() but item object not store short description.

 

 

You have to do manually add short description by adding below code in your file.
You have to override your defaultInvoice.php file,

Keep below line of code in your file,

$objManager = \Magento\Framework\App\ObjectManager::getInstance();
$itemId = $item->getProductId();
$productObject = $objManager->create('Magento\Catalog\Model\Product')->load($itemId);
/* use for strip tag from short description */ $short_description =$this->filterManager->stripTags($productObject->getShortDescription());

Please let me know if you have any query.

If issue solved, click kudos/accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Add short description to Magento 2 pdf invoice

Thank you, both solutions work fine, second one is a bit better stripping the tags.

 

Best regards,

David