4

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

2 Answers 2

3

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.

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

2
  • 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, 2014 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, 2014 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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