0

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!

6
  • Are you sure that's the only order criteria in your select? Commented Apr 21, 2020 at 13:45
  • The other criteria is correct , about the brand and name, As I have worked on Zend before I think there is still missing something in this line $this->_items->getSelect()->order('main_table.sku ASC'); Commented Apr 21, 2020 at 13:46
  • Are you trying to dump the sql query, let we see the result of this : $this->_items->getSelect()->__toString(); or log it in custom log file like this Mage::log($this->_items->getSelect()->__toString(),null,'logfile.log',true); Commented Apr 21, 2020 at 13:55
  • instead of that Line , I have written var_dump($this->_items->getSelect()->__toString()); Commented Apr 21, 2020 at 14:01
  • This is the output string 'SELECT main_table.*, catalog_product_index_eav.value, eav_attribute_option.*, eav_attribute.attribute_code, eav_attribute_option_value.value FROM sales_flat_quote_item AS main_table LEFT JOIN catalog_product_index_eav ON product_id=catalog_product_index_eav.entity_id LEFT JOIN eav_attribute_option ON catalog_product_index_eav.value=eav_attribute_option.option_id LEFT JOIN eav_attribute ON eav_attribute.attribute_id=catalog_product_index_eav.attribute_id LEFT JOIN `eav_attribute'... (length=761) Commented Apr 21, 2020 at 14:01

1 Answer 1

0

This is the solution to the problem :

$this->_items->getSelect()->order("LPAD(main_table.sku, 10, '0') ASC");
$this->_items->getSelect()->group('main_table.item_id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.