6

I am trying to override Payment/Model/Method/Cc.php file but it's not able rewrite. can you please any one check my script.

config.xml:

<?xml version="1.0"?>
<config>
   <modules>
      <Naveed_Abbas>
        <version>0.1.0</version>
      </Naveed_Abbas>
   </modules>
<global>
    <models>
       <payment>
            <rewrite>
                <method_cc>Naveed_Abbas_Model_Payment_Method_Cc</method_cc>                    
            </rewrite>
       </payment>
    </models>
  </global>
</config>

Naveed/Abbas/Model/Payment/Method/Cc.php :

<?php
  class Naveed_Abbas_Model_Payment_Method_Cc extends Mage_Payment_Model_Method_Cc {

    public function isAvailable($quote = null) {
         Mage::log("Canel Order",null,'isAvailable-test-1.log');
        return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
        && parent::isAvailable($quote);
    }
  }
  • Seems perfect. Are you sure its not already overridden by some other module or something else. Code looks pretty good to me. – Kingshuk Deb Apr 29 '17 at 10:10
  • @Kingshuk happy to reconnect, Actually i am trying in new instance(just now installed) – Ramesh Apr 29 '17 at 10:38
  • have create Naveed_Abbas.xml app/etc/modules – Amit Bera Apr 29 '17 at 12:28
  • @Amit, that module is visible in admin panel also with enable status. – Ramesh Apr 29 '17 at 12:40
  • What specific payment method are you trying to affect? Stored CC? – Ryan Hoerr Apr 29 '17 at 13:39
6
+25

Explanation is easy here.

There is a class Mage_Payment_Model_Method_Cc which has a lot of methods. The other class Mage_Payment_Model_Method_Ccsave is extended from it. It has few protected properties. All methods it takes from it's parent.

When magento is looking for some method from Mage_Payment_Model_Method_Ccsave and didn't find it there - it goes to it's parent method.

As result you see in xdebug that you are referring to Mage_Payment_Model_Method_Cc. But if you look which class is inside $this - you will see Mage_Payment_Model_Method_Ccsave.

5

I tried lot of ways finally i got the solution.

config.xml

<?xml version="1.0"?>
<config>
   <modules>
      <Naveed_Abbas>
          <version>0.1.0</version>
      </Naveed_Abbas>
   </modules>
   <global>
     <models>
        <payment>
          <rewrite>
            <method_ccsave>Naveed_Abbas_Model_Payment_Method_Cc</method_ccsave>
           </rewrite>
        </payment>
     </models>
   </global>
 </config>

Naveed/Abbas/Model/Payment/Method/Cc.php :

<?php

   class Naveed_Abbas_Model_Payment_Method_Cc extends Mage_Payment_Model_Method_Ccsave{

      public function isAvailable($quote = null) {
         echo "Test"; //sssssssexit;
         Mage::log("Canel Order",null,'isAvailable-test-1.log'); exit;
         return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
        && parent::isAvailable($quote);
     }    
  }
1

You can try with below way using <payment_method_cc> in config.xml file,

<?xml version="1.0"?>
<config>
   <modules>
      <Naveed_Abbas>
        <version>0.1.0</version>
      </Naveed_Abbas>
   </modules>
<global>
    <models>
       <naveed_abbas>
            <class>Naveed_Abbas_Model</class>
       </naveed_abbas>
       <payment>
            <rewrite>
                <payment_method_cc>Naveed_Abbas_Model_Payment_Method_Cc</payment_method_cc>                    
            </rewrite>
       </payment>
    </models>
  </global>
</config>
  • i updated my xml script with your script but still its going to core file. – Ramesh May 1 '17 at 10:43
  • shall i share my module – Ramesh May 1 '17 at 10:44
  • Sometimes module does not effect because of compiler enable. Have you checked compiler is enable or disabled? Also checked cache is disabled. – Sunil Patel May 3 '17 at 9:46

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.