1

I'm trying to override the core Magento class Mage_Payment_Model_Info in order to solve an error.

To be clear, the override I am talking about has been entirely written by me, and is extending a core Magento model class. The override is not showing up in the stack trace generated by the error, the core version is. A list of solutions I have tried so far is as follows. None have been fully successful.

  • Successfully able to override a block that is also part of this process and that override appears in the stack trace.
  • Checked for any conflicts. I found some but when I changed my override extends so it extends from the potential conflict class it has no effect.
  • Made the code in my override very similar to the original so I know it is not a result of the code I have changed.
  • Added log statements to both my override and the original so I can confirm which version is being run. The code for the override is as follows:

    class Work_Rewrites_Model_Payment_Info extends Mage_Payment_Model_Info {
        public function getMethodInstance()
        {
            Mage::log("In rewrite payment info model");
            if (!$this->hasMethodInstance()) {
                if ($this->getMethod()) {
                    $instance = Mage::helper('payment')->getMethodInstance($this->getMethod());
                    if ($instance) {
                        $instance->setInfoInstance($this);
                        $this->setMethodInstance($instance);
                        return $instance;
                    }
                }
                //return false;
                Mage::throwException(Mage::helper('payment')->__('The requested Payment Method is not available.'));
            }
    
            return $this->_getData('method_instance');
        }
    }
    

Revlevant code from the config file is as follows:

    <config>
        <global>
            <models>
                <rewrites>
                    <class>Work_Rewrites_Model</class>
                </rewrites>
                <payment>
                    <rewrite>
                        <info>Work_Rewrites_Model_Payment_Info</info>
                    </rewrite>
                </payment>
            <models>
        <global>
    <config>

Thanks for your help

0

Try below code

 <config>
        <global>
            <models>
                <payment>
                    <rewrite>                       
                   <payment_info>Work_Rewrites_Model_Payment_Info</payment_info>
                    </rewrite>
                </payment>
            <models>
        <global>
    <config>
  • Just tried it. It did not work – Ben Parker Nov 27 '17 at 20:04
  • try to log your text in this format. Mage::log('text here', null, 'system.log', true); – Abhishek Panchal Nov 27 '17 at 20:09
  • Which file should I put that code in? – Ben Parker Nov 27 '17 at 20:10
  • the one you override ` Work_Rewrites_Model_Payment_Info` and mention log there – Abhishek Panchal Nov 27 '17 at 20:10
  • Once I add and try to run that what should that reveal? – Ben Parker Nov 27 '17 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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