cancel
Showing results for 
Search instead for 
Did you mean: 

Order by SKU on Order Checkout Page

Order by SKU on Order Checkout Page

Hello

I am trying to order products by SKU but I got it wrong The order is on the Order page (Checkout) This is a snippet of my code

$this->_items->getSelect()->order('main_table.sku ASC');$this->_items->getSelect()->group('main_table.item_id');

I am trying to order products having SKU : 4422; 00003001 and 00004335 but I am gotten them in this order :

4422

00003001

00004335

How can I solve this problem, don't hesitate if you need more details?

Thanks in advance!

4 REPLIES 4

Re: Order by SKU on Order Checkout Page

Try this:

$this->_items->getSelect()->order('CAST(main_table.sku AS DECIMAL(10,2)) 

Re: Order by SKU on Order Checkout Page

Hi @ahmed_chouihi 

You can't get the SKU as ascending format as you mentioned, because SKU always a string type, not the integer type.

Screenshot from 2020-04-22 08-06-53.png

It will always treated as a string when you will try to sort by ascending.

I hope you got me concern.  

Re: Order by SKU on Order Checkout Page

It is incorrect I have written it like this and It is incorrect also :

$this->_items->getSelect()->order('CAST(main_table.sku AS DECIMAL(10,2)');

How can I solve it ?

Thanks in advance 

Re: Order by SKU on Order Checkout Page

Is there any other table having some order with Sku at least, because I must do that

Thanks