Magento 1.9 – How to Override Core Payment Model

magento-1.9overridespayment-gateway

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

Best Answer

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()
 {...}
}
Related Topic