[英]Magento unsetting block by observer
我有一個觀察員:
public function removePrice($observer) {
// $observer contains data passed from when the event was triggered.
// You can use this data to manipulate the order data before it's saved.
// Uncomment the line below to log what is contained here:
$layout = $observer->getEvent()->getLayout();
if ($block = $layout->getBlock('catalog_product_price_template')) {
$layout->unsetBlock('catalog_product_price_template');
}
}
和我的觀察者我的config.xml:
...
<controller_action_layout_generate_blocks_after>
<observers>
<...>
<type>singleton</type>
<class>...</class>
<method>removePrice</method>
</...>
</observers>
</controller_action_layout_generate_blocks_after>
....
在我的商店app\\design\\frontend\\default\\myShop\\layout\\catalog
的catalog.xml中,定義了該塊:
<default>
<block type="catalog/product_price_template" name="catalog_product_price_template" />
</default>
觀察者被正確調用。 問題在於,塊catalog_product_price_template
仍出現在前端。 也許我在這里發生了錯誤的事件?
會對任何答案感到高興!:)。
您可以使用更簡單的解決方案。 將remove元素添加到XML。
public function removePrice($observer) {
$layout = $observer->getLayout();
$layout->getUpdate()->addUpdate('<remove name="catalog_product_price_template"/>');
$layout->generateXml();
}
另一個問題可能是您的XML塊名稱不正確。 嘗試刪除該塊並查看是否已刪除該塊。 如果不是正確的塊,請先搜索該塊。
並檢查我們的list.phtml
模板。 也許有您手動添加的價格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.