Hi i have this code:

                //shop the look product code
                $products = Mage::getResourceModel('catalog/product_collection');
                // Select which fields to load into the product
                // * will load all fields but it is possible to pass an array of
                // select fields to load
                $products->addAttributeToFilter('type_id', array('eq' => 'configurable'));
                // Ensure the product is visible
                $products->addAttributeToFilter('visibility', array('neq' => 1));
                // Ensure the product is enabled
                $products->addAttributeToFilter('status', 1);
                $products->addAttributeToFilter('featured_products', 'si');
                // Load the collection

it will take all products from the passed catedory id with a filter on featured_products. it works fine but only with simple products, it don’t load configurable products from the category!!

it’s a magento bug i think, there is a solution to retrive configurable products too?

  • 2
    Stupid question but does the configurable products have this featured_products as well? On a side note: please don't use addAttributeToSelect('*'), it's a performance killer – Sander Mangel Feb 20 '14 at 18:42
  • yes all products have the attribute and the value is set – Emanuele Parisio Feb 21 '14 at 9:00

Take a look at catalog_product_entity. Essentially you are interested in the type_id column. Now because it is located in the base table for the entity you should use addFieldToFilter instead of addAttributeToFilter http://www.creare.co.uk/magento-product-collection-bible

  • works like a charm thanks!! replaced addAttributeToFilter with addFieldToFilter and now it takes simple and configurable products! – Emanuele Parisio Feb 21 '14 at 10:47
  • Glad to hear that! – Evgeni Ivanov Feb 21 '14 at 10:49

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.