3

We have a bit of code that looks like this:

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect('name');
$products->addAttributeToSelect('sellbydate');
$products->addAttributeToSort('sellbydate','ASC');

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?

3

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.

0

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, privacy policy and cookie policy

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