dongpu3792 2016-07-01 15:56
浏览 27
已采纳

Magento在产品详细信息页面的自定义模块块中获取产品ID

I have a custom module with a block which shows a form inside the product detail page. I need to retrieve the product ID for the currently viewed product inside this block. Everything else is working.

Other answers suggested trying:

$this->getProduct()->getId(); // or
Mage::registry('current_product')->getId();

The former returned an error. Using this one inside the product detail template is working fine. I understand that's because getProduct() is not a method for the block.

The latter is always returning null.

If anyone could help me, that would be great.

Thanks in advance.

EDIT: The custom block layout.xml

<layout version="0.1.0">
    <catalog_product_view>
        <reference name="content">
            <reference name="product.info">
                <block
                    type="s148_interestnotification/form"
                    name="interest_notification"
                    before="-"
                    template="s148_interestnotification/index.phtml"
                ></block>
            </reference>
        </reference>
    </catalog_product_view>
</layout>
  • 写回答

2条回答 默认 最新

  • dongyi9783 2016-07-03 13:15
    关注

    if your custom block is extending this class

    Mage_Catalog_Block_Product_View

    you would be easily able to use : $this->getProduct()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题