I am using below code to load product collection in custom module helper

$productCollection = Mage::getModel('catalog/product')->getCollection()

But addAttributeToSelect does not work, product collection does not include my custom_attribute_code attribute.

I also tried passing attributes in array().

It work if I pass attribute code twice as in below code


Anyone know why this strange issue is happening?

  • try with addAttributeToSelect('*') Commented Nov 25, 2017 at 11:44
  • You want to attribute value in getData() ? if you use foreach and try get attribute value using product object them you can get it $product->getCustomAttribute(); Commented Nov 25, 2017 at 11:46
  • I don't want load all attributes. anyways it does not make any difference
    – Piyush
    Commented Nov 25, 2017 at 11:46
  • I think addAttributeToSelect('*') will not display any attribute value in getData function attribute values can get by product object because it's EAV Commented Nov 25, 2017 at 11:46
  • @VaibhavAhalpara I know how to get attributes from product object, the issue here is I don't want loop product collection instead I want array of values of a particular attribute
    – Piyush
    Commented Nov 25, 2017 at 11:49

3 Answers 3


When you use addAttributeToSelect function it will call

Mage_Eav_Model_Entity_Collection_Abstract:addAttributeToSelect($attribute, $joinType = false)

here your second parameter will used as joinType

In addAttributeToSelect method there is a code to check if $joinType has value and attribute value is static

LINE 430 : if ($joinType !== false && !$this->getEntity()->getAttribute($attribute)->isStatic()) {
        $this->_addAttributeJoin($attribute, $joinType);

Then it will call $this->_addAttributeJoin($attribute, $joinType);

Mage_Eav_Model_Entity_Collection_Abstract::_addAttributeJoin($attributeCode, $joinType = 'inner')

In this function $joinType is used as table join method

Line 1312 : $joinMethod = ($joinType == 'left') ? 'joinLeft' : 'join';

you can see here if $joinType == 'left' then it will select joinLeft else select join method

after that magento will join attribut table using above method and fetch data.

so basically you do not need to pass variable 2 times if you leave it blank then also it will works


the second attribute here is used to select table join method which is either left (joinLeft) or simple join

  • Yes , it should work if I leave second parameter blank, but It is not working in my case it is not working. It work if I pass second parameter (even any random value)
    – Piyush
    Commented Nov 25, 2017 at 12:43
  • blank means ->addAttributeToSelect('custom_attribute',''); if you not use second parameter then it will use false Commented Nov 25, 2017 at 12:45
  • Can you tell me which magento version you have checked it
    – Piyush
    Commented Nov 25, 2017 at 12:46
  • version Commented Nov 25, 2017 at 12:46
  • still leaving second parameter blank does not giving me expected output, it works when I pass null (even passing false does not work) as second parameter
    – Piyush
    Commented Nov 25, 2017 at 12:49

do some temp filter using some non existing value, you will get that attribute into a result.

$productCollection = Mage::getModel('catalog/product')->getCollection()
  • it may work in static queries but I can not add random value filter for dynamic queries
    – Piyush
    Commented Nov 25, 2017 at 12:09
  • that add not allow null filter Commented Nov 25, 2017 at 12:11

You need to set store id for custom_attribute to be included in the select statement.

$_productCollection = Mage::getModel('catalog/product')
                        ->addAttributeToFilter('status',array('eq' =>1))
                        ->addAttributeToFilter('custom_attribute',array('notnull' => true))
                        ->addAttributeToSort('created_at', 'ASC')

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.