问题描述
您好,在 Magento 中,一旦订单被设置为处理(通过网关确认或手动),我想触发一个事件,例如:如果普通客户(id 1)花费超过 100 美元并且付款已被确认,将他的组ID设置为4(银VIP,根据促销规则在全球获得2%的折扣)我会为此悬赏,但我希望在 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
- 模型/观察者.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>
现在,您的观察者方法 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 中收到的付款事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!