我有一个观察者:
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');
}
}
和我的配置.xml为我的观察者:
...
<controller_action_layout_generate_blocks_after>
<observers>
<...>
<type>singleton</type>
<class>...</class>
<method>removePrice</method>
</...>
</observers>
</controller_action_layout_generate_blocks_after>
....
在我的目录中.xml对于我的商店appdesignfrontenddefaultmyShoplayoutcatalog
定义了块:
<default>
<block type="catalog/product_price_template" name="catalog_product_price_template" />
</default>
正确调用观察器。问题是块catalog_product_price_template
仍然出现在前端。也许我在这里有错误的事件?
会对任何答案感到高兴:)!
您可以使用更简单的解决方案。将删除元素添加到 XML 中。
public function removePrice($observer) {
$layout = $observer->getLayout();
$layout->getUpdate()->addUpdate('<remove name="catalog_product_price_template"/>');
$layout->generateXml();
}
另一个问题可能是您的 XML 块的名称不正确。尝试删除块并查看块是否已删除。如果它不是正确的块,请先搜索该块。
并查看我们的list.phtml
模板。也许您的价格是手动添加的。