[英]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.