Magento: Attribute always returns default value in catalog view, works fine in product view

Posted by colinodell on Stack Overflow See other posts from Stack Overflow or by colinodell
Published on 2010-06-09T20:38:35Z Indexed on 2010/06/09 20:42 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I've created a new Yes/No attribute for products. I've extended the Product model to do some custom logic and the custom functions are working everywhere.

When I initially tried getting the custom attribute value, I ran into some issue. Magento wasn't loading it for me, so calls to $product->getMyAttributeName() did nothing. In the product views, I got it working with this additional function:

public function getAttrVal($attr_name)
{
    return $this->getResource()->getAttribute($attr_name)->getFrontend()->getValue($this);
}

So that worked great when viewing a product on the frontend. It would fetch the assigned value if set, or the default if not.

When I view any Category (grid of all products in that category), the same exact code is being executed. But my getAttrVal() function always returns the default value, even if I've explicitly set this value for my product.

I can't, for the life of me, figure out why the attribute loads correctly in the Product view but the Category view always grabs the default value, despite running the same exact code. Any thoughts?

© Stack Overflow or respective owner

Related posts about attributes

Related posts about magento