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();
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)