0

当我尝试为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>

上面的代码我试过frontendglobal

即使我也尝试过。

<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 缓存文件夹文件。

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
4

3 回答 3

6

从包含警告来看,您似乎启用了编译器,但它找不到(展平的)文件。

所以要么禁用编译器:

php shell/compiler.php disable

或者运行编译,以便为您生成文件:

php shell/compiler.php compile
于 2012-07-23T11:37:18.847 回答
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>

助手\数据.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);
    }

}
于 2012-07-23T12:52:48.040 回答
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>
于 2012-07-23T11:51:25.643 回答