- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Add short description to Magento 2 pdf invoice
Hey,
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
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Magento 2 Blogs/Tutorial
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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