如何触发magento收到的付款事件? [英] How to trigger an event on payment received in magento?

查看:44
本文介绍了如何触发magento收到的付款事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,在Magento中,一旦订单设置为处理(通过网关确认或手动)后,我想触发一个事件,例如:如果一般客户(id 1)花费超过100 $并且付款已经确定后,将其组ID设置为4(银色VIP,根据促销规则,全球可获得2%的折扣) 我会为此提供赏金,但是我想在O_o

Greetings, in Magento I want to trigger an event, once an order has been set to processing (by gateway confirmation or manually) that, example: If a general customer (id 1) spends over 100$ and the payment has been confirmed, set his group id to 4 (silver VIP, which by promotion rule gets 2% discount globally) I would give a bounty to this, but I'd like the answer before 2 days O_o

编辑:到目前为止,我收到的答案只是部分答案,我也发现链接非常混乱,不清楚最小设置是什么,我必须配置什么创建等...此外,我也在尝试找出如何获取付费客户的ID/模型.

EDIT: the answer I received so far is only a partial answer, also I find the links very confusing, I'm not clear on what is the minimal setup, what do i have to configure create etc... Also I'm trying to find out how to get the paying customers id/model.

推荐答案

您应该首先在app/code/local中创建自己的模块. 例如,创建目录Moak/Vip.这将是您模块的根.

You should start by creating your own module in app/code/local. Create for example the directories Moak/Vip. It will be the root of your module.

为了使Magento知道它的存在,请在etc/modules中创建一个名为Moak_Vip.xml的文件,其内容如下:

In order for Magento to know it exists, create a file named Moak_Vip.xml in etc/modules, with the following content :

<?xml version="1.0"?>
<config>
    <modules>
        <Moak_Vip>
            <active>true</active>
            <codePool>local</codePool>
            <self_name>Moak VIP module</self_name>
        </Moak_Vip >
    </modules>
</config>

然后,在您的模块目录中,需要以下结构和文件:

Then, in your module directory, you need the following structure and files :

  • etc/config.xml
  • Model/Observer.php

config.xml定义了您的模块并声明了给定事件的事件侦听器(checkout_onepage_controller_success_action在一页结帐过程完成时发送,sales_order_payment_pay在付款确认后发送).

The config.xml defines your module and declares your event listener for a given event (checkout_onepage_controller_success_action is sent when onepage checkout process is complete, sales_order_payment_pay is sent when the payment has been confirmed).

由于不需要保存任何新实体,因此不需要任何数据库设置. 因此,您的配置文件应类似于以下内容:

You don't need any DB setup since you will not save any new entity. So your config file should look something like the following :

<?xml version="1.0"?>
<config>
    <modules>
        <Moak_Vip>
            <version>0.1.0</version>
        </Moak_Vip>
    </modules>
    <global>
        <models>
            <moak>
                <class>Moak_Vip_Model</class>
            </moak>
        </models>      
        <events>
            <sales_order_payment_pay>
                <observers>
                    <moak_observer>
                        <type>singleton</type>
                        <class>moak/observer</class>
                        <method>checkVipCustomer</method>
                    </moak_observer>
                </observers>
            </sales_order_payment_pay >     
        </events>
     </global>
</config>

现在,您的Observer方法checkVipCustomer应该会收到一个事件对象,您可以从中获取有关订单,客户...的所有信息,并执行所需的修改. 看看app/code/core/Mage/.../Model/...中的Magento模型类 了解如何在这些对象之间导航.

Now, your Observer method checkVipCustomer should receive an event object from which you can retrieve all information about the order, the customer... and perform the modifications you like. Have a look at Magento model classes in app/code/core/Mage/.../Model/... to see how to navigate through those objects.

示例:

<?php

class Moak_Vip_Model_Observer
{
    public function checkVipCustomer($event)
    {
        $order = $event->getInvoice()->getOrder(); // Mage_Sales_Model_Order
        /*
            - Check order amount
            - Get customer object
            - Set Group id
            - $customer->save();
        */
        return $this;
    }

}

请注意,我尚未测试我在此处编写的任何代码,因此请谨慎处理! 希望它能对您有所帮助,Magento的学习难度很大. 祝你好运!

Note I've not tested any of the code I wrote here, so handle with care ! Hope it helped, Magento has a hard learning curve... Good luck !

这篇关于如何触发magento收到的付款事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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