Comments (8)
I've created a patch based on mathijsm@5dde194 . This way, the core files are used.
/patches/print-bold-order-comment-on-invoice-and-shipment-pdf.patch
--- module-sales/Model/Order/Pdf/AbstractPdf.php
+++ module-sales/Model/Order/Pdf/AbstractPdf.php
@@ -1124,4 +1124,78 @@
}
return $top;
}
+
+ // START add boldcommerce/magento2-ordercomments to PDF's
+ protected function insertComment(\Zend_Pdf_Page $page, $comment)
+ {
+ if (!$comment) {
+ return $page;
+ }
+
+ if ($this->y < 50) {
+ $page = $this->newPage();
+ }
+
+ $this->drawCommentHeader($page);
+ $comment = $this->formatComment($comment);
+ $page = $this->drawCommentBody($page, $comment);
+
+ return $page;
+ }
+
+ protected function drawCommentHeader(\Zend_Pdf_Page $page)
+ {
+ $this->_setFontRegular($page, 10);
+ $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
+ $page->setLineWidth(0.5);
+ $page->drawRectangle(25, $this->y, 570, $this->y - 15);
+ $page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));
+ $page->drawText(__('Order Comment'), 35, $this->y -10);
+ $this->y -= 30;
+ return $page;
+ }
+
+ protected function drawCommentBody(\Zend_Pdf_Page $page, $commentLines)
+ {
+ $this->prepareCommentBodyBlock($page, count($commentLines));
+
+ foreach($commentLines as $index => $line) {
+ $page->drawText($line, 35, $this->y);
+ $this->y -= 10;
+
+ if ($this->y <= 15) {
+ $page = $this->newPage();
+ $remainingLines = count($commentLines) - ($index + 1);
+ $this->drawCommentHeader($page);
+ $this->prepareCommentBodyBlock($page, $remainingLines);
+ }
+ }
+ return $page;
+ }
+
+ protected function prepareCommentBodyBlock(\Zend_Pdf_Page $page, $numLines)
+ {
+ $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1));
+ $page->drawRectangle(
+ 25,
+ $this->y + 15,
+ 570,
+ max($this->y - (10 * $numLines) + 10, 15)
+ );
+
+ $page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));
+ }
+
+ protected function formatComment($text)
+ {
+ $result = [];
+ foreach (explode("\n", $text) as $str) {
+ foreach ($this->string->split($str, 130, true, true) as $part) {
+ $result[] = $part;
+ }
+ $result[] = '';
+ }
+ return $result;
+ }
+ // END add boldcommerce/magento2-ordercomments to PDF's
}
--- module-sales/Model/Order/Pdf/Invoice.php
+++ module-sales/Model/Order/Pdf/Invoice.php
@@ -148,6 +148,14 @@
);
/* Add document text and number */
$this->insertDocumentNumber($page, __('Invoice # ') . $invoice->getIncrementId());
+
+ // START add boldcommerce/magento2-ordercomments to PDF's
+ $page = $this->insertComment(
+ $page,
+ $order->getBoldOrderComment()
+ );
+ // END add boldcommerce/magento2-ordercomments to PDF's
+
/* Add table */
$this->_drawHeader($page);
/* Add body */
--- module-sales/Model/Order/Pdf/Shipment.php
+++ module-sales/Model/Order/Pdf/Shipment.php
@@ -139,6 +139,14 @@
);
/* Add document text and number */
$this->insertDocumentNumber($page, __('Packing Slip # ') . $shipment->getIncrementId());
+
+ // START add boldcommerce/magento2-ordercomments to PDF's
+ $page = $this->insertComment(
+ $page,
+ $order->getBoldOrderComment()
+ );
+ // END add boldcommerce/magento2-ordercomments to PDF's
+
/* Add table */
$this->_drawHeader($page);
/* Add body */
To be used with https://github.com/cweagans/composer-patches
composer.json
"extra": {
"patches": {
"magento/module-sales": {
"boldordercomments": "./patches/print-bold-order-comment-on-invoice-and-shipment-pdf.patch"
}
}
}
from magento2-ordercomments.
@boldsidney, here is the business case: Many of my existing customers use this module to place "Shipping Comments" for their order, while this works great, we use the "Print Invoices" feature from the mass action drop down to give to our shipping department to process orders. Having the notes on the printed documented would prevent our team from having to review every order in the Admin panel. While the "Print Invoices" is our use case, I think many would make use of this in the "Print Packing Slips" PDF as well. As this feature will likely be specific per Magento installation, offering this as an admin configuration would be ideal.
from magento2-ordercomments.
No way @evs-xsarus just solved this 2 year open case just when I stumbled upon it. Legend and perfect timing!
from magento2-ordercomments.
hi @duffner ,
If you still want this functionality, I can look into this when i have some free time somewhere either this month or the next.
I didnt find the print order PDF button in Magento, but I did find the print packing slip. Was it just the packing slip that needed this addition?
from magento2-ordercomments.
Was there any update on this? I'm also interested in seeing the order comments in the pdf invoice printout. Common use case is that invoices will be printed in batch, and will be processed using the printouts
from magento2-ordercomments.
I don't use this module anymore, but it's better practice to override these files in your own module. Editing core files is a bad idea.
Create a custom module and include in /etc/admindhtml/di.xml lines like <preference for="Magento\Sales\Model\Order\Pdf\Shipment" type="VENDOR\MODULE\Model\Order\Pdf\Shipment" />
And put your new php files in the custom module.
from magento2-ordercomments.
@twoatechguy well, I agree partially. Doing it with a patch, gives me a warning should the core file change. This is a trigger for me to check if the functionality must be changed.
A preference on this PDF class also means overriding a long function. Should the function change a bit in the core, I'll never know.
Basically, when I can use a before or after plugin, I'll use a local module, otherwise, I'll patch.
from magento2-ordercomments.
@evs-xsarus agreed, but you will be called out by 3rd party auditors who don't understand the reasoning.
from magento2-ordercomments.
Related Issues (20)
- No output, not verbosing HOT 1
- Method Not Allowed HOT 4
- PHP Returns Problem on Magento 2.1.14
- Move comment field to first step HOT 2
- Adding comment in order POST call HOT 1
- composer.json is not compatible with php 7.3 (and so with Magento 2.3.3) HOT 5
- Compatability with Magento 2.3.3 HOT 2
- Cache Comments
- Change css of this extension
- Comment field not showing in checkout HOT 3
- Support Magento 2.4 HOT 1
- Can not add custom translation HOT 1
- Issue at production mode HOT 1
- Managing checkout comment REST API HOT 1
- Unable to save comment with Stripe Payment HOT 2
- Adobe issue with extension HOT 1
- Please add the greek translation
- Arabic Translation
- extension not working for billdesk payment method in magento 2.4.3 HOT 6
- Cannot install extension with PHP 8.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magento2-ordercomments.