开发者

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

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜