[英]Magento get product ID in custom module block on product detail page
我有一个带有模块的自定义模块,该模块在产品详细信息页面内显示了一个表单。 我需要在此块中检索当前查看的产品的产品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>
试试这个代码:
$collection = Mage::getSingleton('Mage_Reports_Block_Product_Viewed')->getItemsCollection();
如果您的自定义块正在扩展此类
Mage_Catalog_Block_Product_View
您将可以轻松使用: $ this-> getProduct()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.