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();
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!
Julien
source share