3

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

2 Answers 2

13

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 like so:

cd {magento_root}/shell
php indexer.php --reindex catalog_product_flat
php indexer.php --reindex catalog_category_flat

Note, you may need to reindex others. See: https://www.atwix.com/magento/process-magento-indexes-from-command-line/

9
  • 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, 2013 at 20:06
  • PHP version is the same?
    – philwinkle
    Jul 8, 2013 at 20:22
  • Can you screenshot the settings in Catalog > Attributes > Manage Attributes
    – philwinkle
    Jul 8, 2013 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, 2013 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, 2013 at 14:43
0

I don't believe adding product attributes via layout xml is obsolete.

<action method="addAttribute"><code>image</code></action>

Works in 1.9.1

I think the issue is probably related to having the "Used in product listing" flag set to yes.

The way Magento works, it will use the flat product table to serve category product listing data (if you have that option enabled). The attributes that go into that table are attributes with the "Used in product listing" flag set to TRUE

When you load a product individually, it uses the EAV structure, which is apathetic to that attribute setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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