magento sales_order_place_after observer

梦想的初衷 提交于 2019-12-03 05:33:45

Read my articles, they'll help you understand what's going on from a naming convention standpoint and get you grounded in some of Magento's conventions/assumptions.

Looking at the samples above, you have a few things not quite right.

First, your file in the etc folder is named wrong

magento/app/etc/modules/Feed.xml

This file needs to be named Packagename_Modulename, so you probably want

magento/app/etc/modules/Feed_Sales.xml

Look at System -> Configuration -> Advanced to see if your module shows up. If it does, you'll have named this file correctly. Without this, the module you created isn't being loaded into the system, and your code never has a chance to run.

Next, you're specifying the class incorrectly. You say

sales/order_observer

but that first part of the URI (sales) is incorrect. You defined your models section as

    <models>
        <feedsales> <!-- this is your model part -->
            <class>Feed_Sales_Model</class>
        </feedsales>
    </models>

which means you want

feedsales/order_observer

Checkout the Class/URI tab of Commerce Bug and try entering some URIs (like sales/order) to get a better idea of what's going on here.

Another quick tip, when you're trying to get your handler setup, do it for an event that fires on every page load. Then, once you have your method being called, you can switch it to the specific event you want and not have to go through the entire purchase process.

Finally, and I realize you were copying examples, consider putting your module in a folder named something other than Sales. I find mimicking the names of Magento core folders only add an extra layer of confusion, which is not what you need while you're learning the system.

The problem seems to be with your observer declaration. Give this a try:

    <events>
        <sales_order_place_after>
            <observers>
                <feed_sales_order_observer>
                    <type>singleton</type>
                    <class>feedsales/order_observer</class>
                    <method>export_new_order</method>
                </feed_sales_order_observer>
            </observers>
        </sales_order_place_after>
    </events>
jorelli

Holy crap. I was stupid. I tested it out with a command line script, like I do with a lot of things, but that particular file was only writeable by the command line interpreter, not the Apache interpreter. I should have left the office earlier last night.

Well for the record, this is how you trigger an action on order placement. I'll leave it up for posterity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!