5

How can I get a catalog/product collection with all attributes which are selected to be "used in product listing", i.e. are in the flat table?

2 Answers 2

6
$collection
    ->addAttributeToSelect(
          Mage::getSingleton('catalog/config')->getProductAttributes()
    );

This is for example used in Mage_Catalog_Model_Layer::prepareProductCollection.

3
  • Is this not equivalent with $collection->addAttributeToSelect('*');
    – philwinkle
    Commented Feb 12, 2013 at 15:49
  • 1
    no it is not. It get all the attributes which are marked as used_in_product_listing Commented Feb 13, 2013 at 0:27
  • Mark it as answer please. Commented Mar 14, 2013 at 21:15
1

Looks like

Mage::getSingleton('catalog/config')->getProductAttributes()

doesn't include all flat attributes. Still missing some attributes. Use the flat reindexer Model instead to get exactly attributes that are in Flat table:

Mage::getModel('catalog/resource_product_flat_indexer')->getAttributeCodes();
1
  • Which attributes were not included in your case?
    – Alex
    Commented Jan 3, 2017 at 13:10

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.