How to trigger a payment event received in purple?

Hi, in Magento I want to trigger an event as soon as the order has been configured to process (using confirmation of the gateway or manually), for example: If the general customer (id 1) spends more than $ 100 and the payment has been confirmed, set his group ID to 4 (silver VIP, which according to the rules of promotion receives a 2% discount all over the world) I would give generosity to this, but I would like to answer up to 2 days O_o

EDIT : The answer I received so far is only a partial answer, also I find the links very confusing, I donโ€™t understand what the minimal setup is, what I need to configure to create, etc. I am also trying to figure out how to get the ID / model of payment customers.

+6
php triggers observer-pattern magento
source share
2 answers

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

To let Magento know that it exists, create a file called Moak_Vip.xml in etc / modules with the following contents:

<?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 modules directory you will need the following structure and files:

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

. config.xml defines your module and announces your event listener for this event ( checkout_onepage_controller_success_action sent when the process of checking one page is completed, sales_order_payment_pay sent when the payment is confirmed).

You do not need to configure the database, since you will not save the new entity. Therefore, your configuration file should look something like this:

 <?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> 

Now your Observer method checkVipCustomer should get an event object from which you can get all the information about the order, client ... and make the modifications you need. Take a look at the Magento model classes in / code / core / Mage /.../ Model / ... to see how to navigate these objects.

Example:

 <?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; } } 

Note. I have not tested the code that I wrote here, so be careful! Hope this helps, Magento has a complicated learning curve ... Good luck!

+31
source share

You can create an observer for the event "sales_order_payment_pay". The following is a cheatsheet of events in magento 1.3.

And an explanation of how to create observer methods . Links are courtesy of the excellent sites activecodeline and indoo.

+1
source share

All Articles