magento sales_order_place_after观察者 [英] magento sales_order_place_after observer

查看:115
本文介绍了magento sales_order_place_after观察者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个观察者,该观察者将在下订单时导出订单数据.我以前没有写任何模块.我的实现基于本文: http://www.magentocommerce. com/wiki/5 _-__ modules_and_development/0 _-__ module_development_in_magento/customizing_magento_using_event-observer_method

I'm trying to write an observer that will export order data when an order is placed. I haven't written any modules before. Basing my implementation on this article: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

到目前为止,我只是试图触发一些伪代码来写入文件.我的日志中没有任何显示,并且文件没有被修改. apache用户具有该目录的权限.我已在Magento设置中禁用了配置缓存.我对某些命名约定有些困惑;我只是尝试遵循该示例.有人知道我要去哪里了吗?

so far I'm just trying to trigger some dummy code to write to a file. I'm not getting anything showing in my log, and the file's not being modified. The apache user has permission for the directory. I've disabled configuration caching in the Magento settings. I'm a little confused on some of the naming conventions; I just tried to follow the example. Anyone know where I'm going wrong?

在magento/app/etc/modules/Feed.xml中:

in magento/app/etc/modules/Feed.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Feed_Sales>
            <codePool>local</codePool>
            <active>true</active>
        </Feed_Sales>
    </modules>
</config>

在magento/app/code/local/Feed/Sales/etc/config.xml中:

in magento/app/code/local/Feed/Sales/etc/config.xml:

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <feedsales>
                <class>Feed_Sales_Model</class>
            </feedsales>
        </models>
        <events>
            <sales_order_place_after>
                <observers>
                    <feed_sales_order_observer>
                        <type>singleton</type>
                        <class>sales/order_observer</class><!-- I've also tried Feed_Sales_Model_Order_Observer here -->
                        <method>export_new_order</method>
                    </feed_sales_order_observer>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
</config>

在magento/app/code/local/Feed/Sales/Model/Order/Observer.php中:

in magento/app/code/local/Feed/Sales/Model/Order/Observer.php:

<?php
class Feed_Sales_Model_Order_Observer
{
    public function __contruct()
    {

    }

    /**
     * Exports new orders to an xml file
     * @param Varien_Event_Observer $observer
     * @return Feed_Sales_Model_Order_Observer
     */
    public function export_new_order($observer)
    {
        Mage::log("reached export_new_order");
        try
        {
            $dumpFile = fopen('/home/jorelli/new_orders/testdump', 'w+');
            fwrite($dumpFile, 'this is a test!');
        }
        catch (Exception $e)
        {
            Mage::log("order export failed.\n");
        }
        return $this;
    }
}
?>  

在Debian Lenny和Apache2上使用Magento 1.4出于某种原因.

Magento 1.4 on Debian Lenny with Apache2 if it should matter for any reason.

推荐答案

神圣的废话.我真蠢啊.我使用命令行脚本对其进行了测试,就像我对很多事情所做的一样,但是该特定文件只能由命令行解释器写入,而不能由Apache解释器写入.我应该昨晚早些时候离开办公室的.

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.

这篇关于magento sales_order_place_after观察者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆