I am trying to extend default PayPal Express functionality. I have successfully rewritten app/code/core/Mage/Paypal/Model/Config.php like

 <global>
        <models>
            <paypalexpressconfirmation>
                <class>Namespace_PayPalExpressConfirmation_Model</class>
            </paypalexpressconfirmation>
            <paypal>
                <rewrite>
                    <config>Namespace_PayPalExpressConfirmation_Model_Config</config>
                </rewrite>
            </paypal>
        </models>
 </global>

But cannot find the way to overwrite

public function returnAction()
{
    try {
        $this->_initCheckout();
        $this->_checkout->returnFromPaypal($this->_initToken());
        $this->_redirect('*/*/placeOrder');
        return;
    }
    catch (Mage_Core_Exception $e) {
        Mage::getSingleton('checkout/session')->addError($e->getMessage());
    }
    catch (Exception $e) {
        Mage::getSingleton('checkout/session')->addError($this->__('Unable to process Express Checkout approval.'));
        Mage::logException($e);
    }
    $this->_redirect('checkout/cart');
}

in app/code/core/Mage/Paypal/Controller/Express/Abstract.php

I have tried using an observer in the event controller_action_predispatch_paypal_express_return and its triggered when customer come back from PayPal page but I don't see anything that allows me to intercept this method and rewrite it.

Thanks

up vote 3 down vote accepted

We cannot overwrite an Abstract class.

Instead we can achieve what we want by overwriting

Mage_Paypal_ExpressController` controller

There we can overwrite the method(s).

Hope this helps.

<config>
<.......>
    <frontend>
        <routers>
            <paypal>
                <args>
                    <modules>
                        <Namespace_Paypal before="Mage_Paypal">Namespace_Paypal</Namespace_Paypal>
                    </modules>
                </args>
            </paypal>
        </routers>
    </frontend>
<.......>
</config>

Now copy Abstract.php from core folder to app/code/local/Mage/Paypal/Controller/Express/Abstract.php

Edit this file in the following way.

require_once("Mage/Paypal/Controller/Express/Abstract.php");

abstract class Namespace_Paypal_Express_Abstract extends Mage_Paypal_Controller_Express_Abstract
{
     public function returnAction()
    {
        //your custom code
    }
}

I've not been able to test the code, so please let me know if it works.

Please refer to the following link to override a controller

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller

Thanks

  • Please can you put the relevant code as the answer. Then refer to the link. If the link becomes stale, the answer will be pointless in the future. – ProxiBlue Oct 28 '14 at 6:19
  • 1
    Thanks for your answer but there should be a more optimal way to handle this. Perhaps using controller dispatch events like @philwinkle recommend in magento.stackexchange.com/questions/9754/… – diazwatson Oct 30 '14 at 0:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.