3

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.

8
  • Your code looks ok to me. Could you check if you don't have any other module rewriting the same model ? Also did you flush the cache ? Commented Jan 19, 2016 at 11:49
  • I have clear cache and how can check rewriting the same model ? and i work on linux machine.
    – rajeevG
    Commented Jan 19, 2016 at 11:52
  • Try disabling every other local and community module and see if your validate code is getting called. If it is that means you've got another module rewriting the same model. Commented Jan 19, 2016 at 11:54
  • Okey, but it is the first module to overwrite model
    – rajeevG
    Commented Jan 19, 2016 at 11:58
  • @rajeevG is your magento shop having third party extension installed and active? Commented Jan 19, 2016 at 11:59

4 Answers 4

1

/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

1
  • @rajeevG Please accept the answer that you find helpful
    – PЯINCƎ
    Commented Sep 16, 2017 at 2:01
0

Replace your Customer Model class with below code:

<?php
class Codefire_Customer_Model_Customer extends Mage_Customer_Model_Customer{

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

Its seems you missed closing "}" of your Codefire_Customer_Model_Customer

This might be the root cause of your issue.

3
  • by mistake remove "}" time of posting
    – rajeevG
    Commented Jan 19, 2016 at 12:38
  • Same code is working for me ... :) Commented Jan 19, 2016 at 12:39
  • I waiting yr response how this is working yr end please let me know in which OS. and give me some steps.
    – rajeevG
    Commented Jan 23, 2016 at 6:39
0

Can you please check if Mage_Customer_Model_Customer is already extended by another class?

If there is another class that is already extending the class that you are trying to overwrite then it may not work. If yes then instead of Mage_Customer_Model_Customer class you might need to extend another class and make changes in config file accordingly.

Other reason could be you are missing below code in your /app/etc/modules/Codefire_Customer.xml

        <depends>
            <Mage_Customer />
        </depends>
-1

Do you need to do this in a custom module? If not you could duplicate app/code/core/Mage/Customer/Model/Customer.php into app/code/local/Mage/Customer/Model/Customer.php and alter the validate function there.

1

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.