0

I added a custom attribute is_featured to my Magento 1.7 store. Its a yes/no dropdown. I am setting it to yes on storeview level and to no on the standard level.

Now I try to load a collection with all the products that have is_featured set to yes. This is my code:

$products = $this->_addProductAttributesAndPrices($products)->addAttributeToFilter(array(array('attribute' => 'featured', 'eq' => '1')));

This only loads those products that have is_featured set to yes on both storeview and standard scope, the ones that have it set to yes on storeview only are NOT included. Why is this the case, did I miss something?

1

You need to use addAttributeToSelect() for add custom attribute in product collection :

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('your_custom_attribute_code')->addAttributeToFilter(array(array('attribute' => 'is_featured', 'eq' => '1')));
  • It returns the right amount of products as it seems, but they do not have a name, SKU, image and so on. This is my code: $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('featured')->addAttributeToFilter(array(array('attribute' => 'featured', 'eq' => '1'))); – Arnie Dec 4 '18 at 10:54
  • I also edited the code I am using in my OP. – Arnie Dec 4 '18 at 10:56
  • You can set like addAttributeToSelect(array('*')) for all attribute display or addAttributeToSelect(array('name','sku')) – Emipro Technologies Pvt. Ltd. Dec 4 '18 at 10:58
  • This is what works: $products = $this->_addProductAttributesAndPrices($products)->addAttributeToSelect('is_featured')->addAttributeToFilter(array(array('attribute' => 'is_featured', 'eq' => '1'))); – Arnie Dec 4 '18 at 10:58

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.