我有一个自定义模块,其中显示了产品详细信息页面中的表单。我需要检索该块内当前查看产品的产品ID。其他一切正在工作。Magento在产品详细信息页面的自定义模块块中获取产品ID
其他答案建议尝试:
$this->getProduct()->getId(); // or
Mage::registry('current_product')->getId();
前者返回一个错误。在产品详细信息模板中使用这一个工作正常。我明白这是因为getProduct()不是该块的方法。
后者总是返回null。
如果有人能帮助我,那会很棒。
在此先感谢。
编辑:自定义块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>
它已经扩展Mage_Core_Block_Template,当我交换与你所建议我得到的“致命错误:调用/ null /成员函数getMetaTitle()在/app/code/core/Mage/Catalog/Block/Product/View.php “ – s148
我不能猜到现在有什么问题,我已经更新了班级名称,可以请您尝试 – tawfekov
以上的新班级名称现在我没有收到错误,但$ this-> getProduct()返回null 。我已经用block layout.xml中的一些信息更新了我的问题,不知道它的相关性,但它会给你一个想法它放置的位置。 – s148