Tell me more ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

When displaying a product collection using a Mage_Catalog_Block_Product_List-type block, the custom attributes manufacturer and part_number are both blank/null/empty strings. Here's what's been checked so far:

  1. The attributes have been added to the default product attribute set
  2. The attributes have been added to the <reference name="product_list"> using the addAttribute method
  3. Both attributes are set to Display in product listing in their configurations
  4. The attributes are accessible via getManufacturer and getPartNumber after a product load

I have attempted some debugging (for example, I know the addAttribute method is being called), but if this is an issue anyone's run into, I would greatly appreciate some guidance.

As a side note, these two attributes do show up in some development environments, but not in what will be production. This leads me to believe that it's a configuration issue, though I don't want to influence answers down my (possibly) wrong line of thought.

Thanks

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

Adding attributes via layout XML is obselete as of CE 1.3/EE 1.8:

http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/add-attributes-to-product-grid#update_layout_xml

So, there are two ways to add to your collections:

Rewrite and Extend:

Rewrite Mage_Catalog_Block_Product_List and extend the protected method _getProductCollection to grab the parent, then add your attributes to it:

protected function _getProductCollection()
{
    $collection = parent::_getProductCollection();
    $collection->addAttributeToSelect('manufacturer')->addAttributeToSelect('part_number');

    return $collection;


}

Add to all default product collections:

Make your own module, and in the config.xml, add the following:

<?xml version="1.0"?>
<config>
    <frontend>
        <product>
            <collection>
                <attributes>
                    <manufacturer/>
                    <part_number/>
                </attributes>
            </collection>
        </product>
    </frontend>
</config>

That should add those two attributes as default members of all basis catalog collections.

Edit:

Another source of potential headaches here could be the exclusion of these attributes in various environments from the flat catalog. To include in the flat catalog, enable the following setting in Catalog > Attributes > Manage Attributes:

enter image description here

To ensure that the changes take place on the frontend, reindex the appropriate flat data.

share|improve this answer
Thanks for the tip about add attributes via config.xml, though it didn't fix our problem. Considering that the same code running on a different (though very similar) database does properly list the manufacturer and part_number attributes, it seems likely that there's just one more configuration option that we're missing. – mpw Jul 8 at 20:06
PHP version is the same? – philwinkle Jul 8 at 20:22
Can you screenshot the settings in Catalog > Attributes > Manage Attributes – philwinkle Jul 8 at 20:30
1  
We disabled the category flat tables, which "fixed" the issue. It seems that loading a category product collection used the flat tables, and even though the indexes appeared to be fully up-to-date, the flat tables weren't. Is there some place we should be setting the included columns for flat data? – mpw Jul 8 at 20:50
1  
We did make sure to set that configuration on each required attribute. Do you mean that if we set that to "Yes" and disable/re-enable the flat tables that they'll have the correct columns? – mpw Jul 9 at 14:43
show 3 more commentsadd comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.