如何使用扩展重写 Magento 块?
How to rewrite a Magento Block with an extension?
我想重写 Mage_Catalog_Block_Product_View 块。
我创建了这个文件:config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<JB_CustomPrice>
<version>0.1.0</version>
</JB_CustomPrice>
</modules>
<global>
<blocks>
<customprice>
<class>JB_CustomPrice_Block</class>
</customprice>
<catalog>
<rewrite>
<product_view>JB_CustomPrice_Block_Catalog_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
</config>
然后我在
/app/code/local/JB/CustomPrice/Block/Catalog/Product/View.php
<?php
class JB_CustomPrice_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
public function getJsonConfig()
{
return 'test';
}
}
?>
尽管如此,产品视图并没有改变,即使在我调用 getProduct() 方法时也是如此。怎么了?
全局错误是一个打字错误,已通过使用 Mage::log(get_class($this))
解决并修复了它。问题是另一个插件已经扩展了 Mage_Catalog_Block_Product_View。这是一个旧的 Yoast_MetaRobots 插件,已弃用。我禁用了它,一切都已修复。谢谢解答!
我想重写 Mage_Catalog_Block_Product_View 块。
我创建了这个文件:config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<JB_CustomPrice>
<version>0.1.0</version>
</JB_CustomPrice>
</modules>
<global>
<blocks>
<customprice>
<class>JB_CustomPrice_Block</class>
</customprice>
<catalog>
<rewrite>
<product_view>JB_CustomPrice_Block_Catalog_Product_View</product_view>
</rewrite>
</catalog>
</blocks>
</config>
然后我在 /app/code/local/JB/CustomPrice/Block/Catalog/Product/View.php
<?php
class JB_CustomPrice_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{
public function getJsonConfig()
{
return 'test';
}
}
?>
尽管如此,产品视图并没有改变,即使在我调用 getProduct() 方法时也是如此。怎么了?
全局错误是一个打字错误,已通过使用 Mage::log(get_class($this))
解决并修复了它。问题是另一个插件已经扩展了 Mage_Catalog_Block_Product_View。这是一个旧的 Yoast_MetaRobots 插件,已弃用。我禁用了它,一切都已修复。谢谢解答!