Magento Observer Event AFTER Payment Hold

I try to call the Supervisor after creating the order and AFTER payment. So far I have tried; checkout_submit_all_after, sales_order_payment_place_end, sales_order_place_after, sales_order_payment_pay, sales_order_payment_capture, sales_order_payment_transaction_save_after

Just to name the main ones. I also registered all the Event Dispatcher in dispatchEvent (), but did not find anything that stands out, and only got fired when I need it. the problem I am facing is that the status of the order is always a simple “Payment payment” or something that preceded it; this means that I do not know if the order will be unsuccessful or successful.

My goal is to run the function only on successful orders. thanks.

+4
source share
3 answers

after much more testing, I found that the following observer did the trick:

checkout_onepage_controller_success_action

This only returns the order ID, therefore:

$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);

and you see that the order status is “processing” and the payment is approved (or not).

+6
source

1) here is the user config.xml file for the observer file

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Modulename>
            <version>0.1.0</version>
        </Namespace_Modulename>
    </modules>
    <frontend>
        <events>            
            <checkout_submit_all_after>
                <observers>
                    <Namespace_Modulename_Customevent>
                        <type>singleton</type>
                        <class>Namespace_Modulename_Model_Observer</class>
                        <method>customFunction</method>
                    </Namespace_Modulename_Customevent>
                </observers>
            </checkout_submit_all_after>
        </events>
    </frontend>    
</config>

2) create an observer.php file inside your modules / models directory and paste this code

<?php
  class Namespace_Modulename_Model_Observer
{
    public function customFunction(Varien_Event_Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
         //here you can add your custom code

    }        

}

try this .. sure this will help you!

+3
source

, . Mage OnePageController . onestep.

\ ..\\Namespace_Module.xml

<Namespace_Checkout>
    <active>true</active>
    <codePool>local</codePool>
</Namespace_Checkout>

\\Local\Namespace\Checkout\ .. \config.xml

<?xml version="1.0"?>
<config>    
  <modules>
     <Namespace_Checkout>            
        <version>0.1.0</version>        
     </Namespace_Checkout>    
  </modules>        
    <frontend>        
        <routers>            
            <checkout>                
                <args>                    
                    <modules>                        
                        <Namespace_Checkout before="Mage_OneStepCheckout">Namespace_Checkout</Namespace_Checkout>                    
                    </modules>                
                </args>            
            </checkout>        
        </routers>    
    </frontend>     
</config>

\\Local\Namespace\Checkout\\OnepageController.php

<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';

class Namespace_Checkout_OnepageController extends Mage_Checkout_OnepageController{
    public function successAction(){
        $session = $this->getOnepage()->getCheckout();
        if (!$session->getLastSuccessQuoteId()) {
            $this->_redirect('checkout/cart');
            return;
        }

        $lastQuoteId = $session->getLastQuoteId();
        $lastOrderId = $session->getLastOrderId();
        $lastRecurringProfiles = $session->getLastRecurringProfileIds();
        if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
            $this->_redirect('checkout/cart');
            return;
        }

        $this->customFunction(); // Custom function to call

        $session->clear();
        $this->loadLayout();
        $this->_initLayoutMessages('checkout/session');
        Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
        $this->renderLayout();
    }

    function customFunction(){
        // This function is calling before clearing order session
        //Here you can put all your custom code 
    }
}
?>

In the controller above, I added customFunction()so you can put your own code.

Hope this helps you!

0
source

All Articles