2

I am using the sales_order_grid_collection_load_before event in order to append a filter to the collection.
However, in my case, I need to JOIN sales_flat_order table.
The problem is that the ordering is of the form ORDER BY created_at, and both sales_flat_order_grid and sales_flat_order have this column name..

How can I change/modify it to main_table.created_at, for instance?
I'm looking for a systematic method to prepend the table aliases to ORDER statements regardless of the specific column used, and, maybe to GROUP statements to.

How can I achieve this?

1

Are you looking for this solution?

$select = $collection->getSelect();
$select->reset(Zend_Db_Select::ORDER);
$select->order('main_table.created_at');
  • It Appends an additional order by. Additionally, what if the user orders by a different column? – user76568 Jan 27 '14 at 15:00
  • Than you need to check post data to know which filter customer selected. – oleksii.svarychevskyi Jan 27 '14 at 15:02
  • Yes correct. But how do I remove the original order by? Your solution adds another order by – user76568 Jan 27 '14 at 15:04
  • Answer updated. – oleksii.svarychevskyi Jan 27 '14 at 15:08
  • Nope, The reset does not remove the original order by. – user76568 Jan 27 '14 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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