Question

I'm building my very own checkout method in Magento atm. I've created a PHP script with the functionality to redirect the user after filling in the order details to my custom payment page. The script on itself is working but it is fired to early in the order process. When enabled, the user is imidiately redirected when he or she clicks on the "go to checkout button" without filling in the order details. So my PHP script is seen by Magento and the method is fired right away (I'm using the _contruct method).

So now it's the following procedure: User select product -> User goes to shopping basket -> User clicks on checkout -> user gets redirected.

I want it to be as follows: User select product -> User goes to shopping basket -> User clicks on checkout -> user fills in order details and selects my shipping method if prefered -> User clicks on "finish order and make payment" -> User gets redirected cuz now the script is executed.

I use the following syntax for my PHP script:

 public function __construct()
{ my PHP code here with the redirect };

How do I get the PHP script to be executed when the user is done with selecting shipping adres, billing adres and have selected my payment method..?

Was it helpful?

Solution

You can use event/observer method of magento to do something after order is placed.

you can use this event sales_order_place_after

Just create one module to listen magento observer/event.

In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:

<config>
        ...
        <frontend>
            ...
            <events>
                <sales_order_place_after>
                    <observers>
                        <unique_event_name>
                            <class>{{modulename}}/observer</class>
                            <method>your function name</method>
                        </unique_event_name>
                    </observers>
                </sales_order_place_after>
            </events>
            ...
        </frontend>
        ...
    </config>

And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php

    class <namespace>_<modulename>_Model_Observer
   {
      public function your function name(Varien_Event_Observer $obs)
      {
          whatever your logic put here
      }

   }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top