Php 如何解决在Mage签出控制器中重写addaction()的问题
我正在做一个magento定制站点,我需要将某些产品详细信息添加到数据库中,因此我在Mage checkout controller中使用了函数addAction(),为了使其成为一个模块,我必须覆盖cartController的addAction() 我引用了stackoverflow的覆盖控制器问题,但没有用,它使用了Mage签出控制器中的编码 我使用了下面的代码Php 如何解决在Mage签出控制器中重写addaction()的问题,php,magento-1.7,Php,Magento 1.7,我正在做一个magento定制站点,我需要将某些产品详细信息添加到数据库中,因此我在Mage checkout controller中使用了函数addAction(),为了使其成为一个模块,我必须覆盖cartController的addAction() 我引用了stackoverflow的覆盖控制器问题,但没有用,它使用了Mage签出控制器中的编码 我使用了下面的代码 code\local\SmartGrowth\CompatibleWith\etc <?xml version="1.0
code\local\SmartGrowth\CompatibleWith\etc
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<SmartGrowth_CompatibleWith>
<version>0.1.0</version>
</SmartGrowth_CompatibleWith>
</modules>
<!-- Configure our module's behavior in the global scope -->
<global>
<blocks>
<catalog>
<rewrite>
<product_view>SmartGrowth_CompatibleWith_Block_CompatibleWith</product_view>
</rewrite>
</catalog>
</blocks>
</global>
<frontend>
<routers>
<checkout>
<use>standard</use>
<modules>
<SmartGrowth_CompatibleWith_Checkout before="Mage_Checkout">SmartGrowth_CompatibleWith_Checkout</SmartGrowth_CompatibleWith_Checkout>
</modules>
</checkout>
</routers>
</frontend>
</config>
您可以编写magento事件的观察者,而不是使用覆盖方法 代码\local\SmartGrowth\CompatibleWith\etc
<frontend>
<events>
<checkout_cart_add_product_complete>
<observers>
<SmartGrowth_CompatibleWith_Model_Observer>
<type>singleton</type>
<class>SmartGrowth_CompatibleWith_Model_Observer</class>
<method>cartproductcomplete</method>
</SmartGrowth_CompatibleWith_Model_Observer>
</observers>
</checkout_cart_add_product_complete>
</events>
</frontend>
使用事件比重写方法更好
<frontend>
<events>
<checkout_cart_add_product_complete>
<observers>
<SmartGrowth_CompatibleWith_Model_Observer>
<type>singleton</type>
<class>SmartGrowth_CompatibleWith_Model_Observer</class>
<method>cartproductcomplete</method>
</SmartGrowth_CompatibleWith_Model_Observer>
</observers>
</checkout_cart_add_product_complete>
</events>
</frontend>
class SmartGrowth_CompatibleWith_Model_Observer {
public function cartproductcomplete() {
//Database operation
}
}