当我尝试编写checkout_type_onepage_save_order
事件的观察者时,如下面的
<events>
<checkout_type_onepage_save_order>
<observers>
<Appeal_Consignor_Model_Observer>
<type>singleton</type>
<class>consignor/observer</class>
<method>savedata</method>
</Appeal_Consignor_Model_Observer>
</observers>
</checkout_type_onepage_save_order>
</events>
我在frontend
以及global
尝试了以上代码。
即使我也尝试过跟随。
<events>
<checkout_type_onepage_save_order>
<observers>
<Appeal_Consignor_Model_Observer>
<type>singleton</type>
<class>Appeal_Consignor_Model_Observer</class>
<method>savedata</method>
</Appeal_Consignor_Model_Observer>
</observers>
</checkout_type_onepage_save_order>
</events>
完整的config.xml文件如下
<?xml version="1.0"?>
<config>
<modules>
<Appeal_Consignor>
<version>1.0.1</version>
</Appeal_Consignor>
</modules>
<global>
<models>
<consignor>
<class>Appeal_Consignor_Model</class>
</consignor>
</models>
<resources>
<consignor_setup>
<setup>
<module>Appeal_Consignor</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</consignor_setup>
<consignor_write>
<connection>
<use>core_write</use>
</connection>
</consignor_write>
<consignor_read>
<connection>
<use>core_read</use>
</connection>
</consignor_read>
</resources>
<helpers>
<consignor>
<class>Appeal_Consignor_Helper</class>
</consignor>
</helpers>
</global>
<frontend>
<routers>
<consignor>
<use>standard</use>
<args>
<module>Appeal_Consignor</module>
<frontName>consignor</frontName>
</args>
</consignor>
</routers>
<events>
<checkout_type_onepage_save_order>
<observers>
<Appeal_Consignor_Model_Observer>
<type>singleton</type>
<class>Appeal_Consignor_Model_Observer</class>
<method>savedata</method>
</Appeal_Consignor_Model_Observer>
</observers>
</checkout_type_onepage_save_order>
</events>
</frontend>
<adminhtml>
<layout>
<updates>
<consignor>
<file>consignor.xml</file>
</consignor>
</updates>
</layout>
</adminhtml>
</config>
但是会出现以下错误。我清除了1000次缓存,也手动删除了var cache文件夹。
2012-07-23T11:04:09+00:00 ERR (3): Warning: include(Appeal_Consignor_Model_Observer.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in E:\xampp\htdocs\magento\includes\src\Varien_Autoload.php on line 93
2012-07-23T11:04:09+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'Appeal_Consignor_Model_Observer.php' for inclusion (include_path='E:\xampp\htdocs\magento\includes\src;.;E:\xampp\php\PEAR') in E:\xampp\htdocs\magento\includes\src\Varien_Autoload.php on line 93
答案 0 :(得分:6)
根据包含警告判断,您似乎已启用编译器但无法找到(展平的)文件。
所以要么禁用编译器:
php shell/compiler.php disable
或者运行编译,以便它为您生成文件:
php shell/compiler.php compile
答案 1 :(得分:2)
这是我在将新产品添加到购物车时运行观察者的方法:
等\ config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Iln_Cartvalidation>
<version>0.1.0</version>
</Iln_Cartvalidation>
</modules>
<global>
<helpers>
<cartvalidation>
<class>Iln_Cartvalidation_Helper</class>
</cartvalidation>
</helpers>
</global>
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<Iln_Cartvalidation_Model_Observer>
<type>singleton</type>
<class>Iln_Cartvalidation_Model_Observer</class>
<method>Mytestmethod</method>
</Iln_Cartvalidation_Model_Observer>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
</config>
辅助\ Data.php
<?php
class Iln_Cartvalidation_Helper_Data extends Mage_Core_Helper_Abstract {
}
模型\ observer.php
<?php
class Iln_Cartvalidation_Model_Observer {
public function Mytestmethod($observer) {
$event = $observer->getEvent(); //Fetches the current event
$product = $event->getProduct();
$eventmsg = "Current Event Triggered : " . $event->getName() . "Currently Added Product : " . $product->getName();
//Adds Custom message to shopping cart
echo Mage::getSingleton('checkout/session')->addSuccess($eventmsg);
//Your Custom Logic Here
print_r($product);
}
}
答案 2 :(得分:0)
我认为这对你有帮助:
<events>
<checkout_type_onepage_save_order>
<observers>
<consignor>
<type>model</type>
<class>consignor/observer</class>
<method>savedata</method>
</consignor>
</observers>
</checkout_type_onepage_save_order>
</events>