1

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->addCategoryFilter(Mage::getModel('catalog/category')->load($this->getCatId()));
                $products->addAttributeToSelect('*');
                $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');
                $products->getSelect()->limit(1);
                // Load the collection
                $products->load();

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
  • 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 Commented Feb 20, 2014 at 18:42
  • yes all products have the attribute and the value is set
    – Dekron
    Commented Feb 21, 2014 at 9:00

1 Answer 1

2

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

2
  • works like a charm thanks!! replaced addAttributeToFilter with addFieldToFilter and now it takes simple and configurable products!
    – Dekron
    Commented Feb 21, 2014 at 10:47
  • Glad to hear that! Commented Feb 21, 2014 at 10:49

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.