views:

69

answers:

1

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?

+1  A: 

Because Magento uses an EAV model for its extensible catalog attributes, not every attribute may be carried over onto every page. Try fiddling with the "displayed in catalog" and other related variables on the attribute, and it may fix your problem. If not, say so and we can try other things.

Hope that helps!

Thanks, Joe

Joseph Mastey
Yep, that did it. I thought it would actually show the value too, not just load it into the model. Thanks!!
Colin O'Dell