Magento – how to override a Core Customer Model in a local module in magento 1.9.2

ce-1.9.2.0magento-1.9model

I am try to override Function public function validate() in app/code/core/Mage/Customer/Model/Customer.php

To Restrict user registration by email domain i can do this by change directly in Function public function validate() in app/code/core/Mage/Customer/Model/Customer.php but I need to override it in codepool.

With Creating module in codepool :

/app/code/local/Codefire/Customer/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Codefire_Customer>
            <version>0.1</version>
        </Codefire_Customer>
    </modules>
    <global>
       <models>
          <customer>
              <rewrite>
                  <customer>Codefire_Customer_Model_Customer</customer>
              </rewrite>
          </customer>
       </models>
    </global>
</config>

/app/etc/modules/Codefire_Customer.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Codefire_Customer>
            <active>true</active>
            <codepool>local</codepool>
        </Codefire_Customer>
    </modules>
</config>

/app/code/local/Codefire/Customer/Model/Customer.php

<?php
/**
 * Overrite Customer model
 */

class Codefire_Customer_Model_Customer extends Mage_Customer_Model_Customer{

    /**
     * Validate customer attribute values.
     *
     * @return bool
     */
    public function validate() {
     echo 'I am here'; die;
   }

I need call this function when do new registration.

Best Answer

/app/etc/modules/Codefire_Customer.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Codefire_Customer>
            <active>true</active>
            <codePool>local</codePool> //codePool and not codepool
            <depends><Mage_Customer/></depends> //you have forgot the depends
        </Codefire_Customer>
    </modules>
</config>

With this config, Magento load first Mage_Customer then Codefire_Customer

Related Topic