0

I want to override the default payment model class in a custom magento extension, as placing the file in local pool with same directory structure working fine but my hosting providers are telling that we have to proceed with overriding this in a custom module.

the class that I want to override is Mage_Payment_Model_Method_Cc and I want to override this in a custom module that I am developing but don't know how to write the config file for this and how to override the functionality. actually I want to overcome the error message "Please enter a valid credit card verification number." when I try to place the order using CC as a payment method and using the SOAP API. I want to comment this validation section to go ahead.

Can anyone help me with this?

thanks

2 Answers 2

1

Steps are creating module named Naveed Abbas where Naveed is your namespace and Abbas module name

app/etc/modules/Naveed_Abbas.xml

contents:

<?xml version="1.0"?>
<config>
    <modules>
        <Naveed_Abbas>
            <active>true</active>
            <codePool>local</codePool>
        </Naveed_Abbas>
    </modules>
</config>

/Library/WebServer/Documents/bineli/app/code/local/Naveed/Abbas/etc/config.xml

<?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>
                <resourceModel>naveed_abbas_resource</resourceModel>
            </naveed_abbas>
            <naveed_abbas_resource>
                <class>Naveed_Abbas_Model_Resource</class>
            </naveed_abbas_resource>
            <payment>
                <rewrite>
                    <method_cc>Naveed_Abbas_Model_Payment_Method_Cc</method_cc>
                </rewrite>
            </payment>
        </models>
        <blocks>
            <naveed_abbas>
                <class>Naveed_Abbas_Block</class>
            </naveed_abbas>
        </blocks>
        <helpers>
            <naveed_abbas>
                <class>Naveed_Abbas_Helper</class>
            </naveed_abbas>
        </helpers>
    </global>
</config>

create folders Block, Helper, Model, etc in directory app/code/local/Naveed and Resource folder in app/code/local/Naveed/Model

and then

file app/code/local/Naveed/Abbas/Model/Payment/Method/Cc.php

<?php

class Naveed_Abbas_Model_Payment_Method_Cc extends Mage_Payment_Model_Method_Cc {
 // overwrite your method here
 public function validate()
 {...}
}
0
1

In your module etc/config.xml:

<models>
    <your_module>
        <class>Your_Module_Model</class>
    </your_module>
    <payment>
        <rewrite>
            <method_cc>Your_Module_Model_Method_Cc</method_cc>
        </rewrite>
    </payment>
</models>
2
  • Thanks for your answer, but the answer given by Anonymous is more clear to me as he discussed in great details that's why accepted his answer. Commented Jan 23, 2017 at 11:25
  • @Shani No worries. I'm helping people, not hunting virtual internet points. Commented May 1, 2017 at 15:46

Your Answer

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

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