Posted on

Magento 2 – Print pdf invoice; Sorted

The items in printout of the invoices, shipments and credit memos are sorted by sequences as to when they are added in the order. My question is how do I go about sorting them. For example how do I go about sorting them based on SKU column.

I am facing a challenging scenario, and cannot wrap my head around it. We have a long list of items. In which each item is compromised of 9 integers.

Case in point: 106110152, 106110163, 106110203, 106110172, etc.

I want to be able to sort based on the last digit of each items SKU number.


Product with last digit 2

Product with last digit also 2

Product with last digit 3

Product with last digit also 3

I have trying and playing with invoice.php and figured I have to do something with:

/* Add body */
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->getParentItem()) {
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);

Any comments, suggestions, etc would be a massive help.

Leave a Reply

Your email address will not be published. Required fields are marked *