We have a bit of code that looks like this:

$products = Mage::getModel('catalog/product')->getCollection();

This has been working fine, but after enabling flat product data the items are no longer sorted. I have reindexed but there is no change.

Should I be using a different function?


2 Answers 2


The function is correct and checks to see if the catalog is in flat mode. So do not worry about that. Make sure that your attribute is set correctly so that there is a column for it on the flat table.

I think setting used_in_product_listing to yes via a set-up script or via the admin, then preform a reindex should solve this problem.


Because you are using flat tables you should use setOrder()/addOrder() instead of addAttributeToSort().
Take a look here : http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento


Your Answer

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

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