Jump to content

Line items on invoice are alphabetical, we want them in the order that customer entered them


Recommended Posts

We are using PS v.1.6.1.5, and presently when the initial order confirmation is emailed to the customer, the products are listed in the same sequence that the customer added them to the order.

However, the PDF Invoice (Sales Order) prints them alphabetically by name.

For sake of ease for the customer, these items should be displayed in the same sequence they were added to the order.

 

This is also true for the PDF Delivery Slip and Packing Slip.

 

Is there a way to retain the original sequence of line items as entered by the customer?

Edited by lepusa (see edit history)
Link to comment
Share on other sites

  • 2 months later...

I checked the code and found it's sorting by name on line 147 in the OrderInvoice::getProductDetail() function:


		'.($this->id && $this->number ? ' AND od.`id_order_invoice` = '.(int)$this->id : '').' ORDER BY od.`product_name`');

You could try overriding this and removing the ORDER BY. For example, create override/classes/OrderInvoice.php with the following:

<?php

class OrderInvoice extends OrderInvoiceCore
{
    public function getProductsDetail()
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT *
		FROM `'._DB_PREFIX_.'order_detail` od
		LEFT JOIN `'._DB_PREFIX_.'product` p
		ON p.id_product = od.product_id
		LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
		WHERE od.`id_order` = '.(int)$this->id_order.'
		'.($this->id && $this->number ? ' AND od.`id_order_invoice` = '.(int)$this->id : ''));
    }   
}

Remember to go to Advanced Parameters > Performance and click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override.

  • Like 1
Link to comment
Share on other sites

 

I checked the code and found it's sorting by name on line 147 in the OrderInvoice::getProductDetail() function:

		'.($this->id && $this->number ? ' AND od.`id_order_invoice` = '.(int)$this->id : '').' ORDER BY od.`product_name`');

You could try overriding this and removing the ORDER BY. For example, create override/classes/OrderInvoice.php with the following:

<?php

class OrderInvoice extends OrderInvoiceCore
{
    public function getProductsDetail()
    {
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT *
		FROM `'._DB_PREFIX_.'order_detail` od
		LEFT JOIN `'._DB_PREFIX_.'product` p
		ON p.id_product = od.product_id
		LEFT JOIN `'._DB_PREFIX_.'product_shop` ps ON (ps.id_product = p.id_product AND ps.id_shop = od.id_shop)
		WHERE od.`id_order` = '.(int)$this->id_order.'
		'.($this->id && $this->number ? ' AND od.`id_order_invoice` = '.(int)$this->id : ''));
    }   
}

Remember to go to Advanced Parameters > Performance and click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override.

 

 That did the trick, thanks!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...