douhe4336 2011-05-02 16:01
浏览 20
已采纳

Magento,如何在主题文件中调用产品属性?

I have been searching for a an answer to this for a roughly 2 days and I am just not finding much on this, hopefully some one here may be able to assist.

Basically I am looking to call a product attribute in a theme file eg: 2columns-right.phtml

While I realize this is not possible by default as attributes are available in front end: product, category & search pages, I am hoping some one may have done this before and could point me in the right direction.

The goal is the following:

I have a that contains a banner image on the product detail, what I would like to do is use a small script that checks against the "attribute" manufacturer, and display a banner that is related to the manufacturer name, so brand-x gets banner x, brand-y gets banner-x.

If there is no, image or the manufacturer is not set then it will use a default banner.

Quite a simple concept, but proving to be troublesome since I am unable to call the function outside of view.phtml

I am currently trying to use: $_product->getAttributeName(); works great on view.pthml, not so great outside the page.

As a last resort I thought to create a simple hack where I would just have the above mentioned div empty while retaining its size selectors and then use and image with an absolute position that is called from view.phtml and lives in the desired location.

This would easily handle what I aiming to achieve but I would prefer if I could find the proper method to get the desired result and with out changing core Mage files.

Thank you in advance!

  • 写回答

1条回答 默认 最新

  • duangan6133 2011-05-02 16:26
    关注

    You can get the current product from Magento's registry:

     if (Mage::registry('product')) {
        $product = Mage::registry('product');
        $attribute = $product->getAttributeName();
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog