Magento override Customer Resource model

17,494

Solution 1

You should be able to accomplish it with the code you had. If it is not being overwritten try some of the basics like making sure you've cleared your cache. If that still doesn't work, you might be fighting with another module that is already overriding it. In that case you'd need to figure out the next steps in figuring out which one wins: merge logic, rewrite/extend the other one, etc.

<models>
    <customer_resource>
        <rewrite>
            <customer>My_Company_Model_Resource_Customer</customer>
        </rewrite>
    </customer_resource>
</models>

Solution 2

I did it (in 1.7.0.2) with the following xml:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
    <Final_Dummy>
        <version>0.0.1</version>
    </Final_Dummy>
</modules>
<frontend>
    <routers>
        <dummy>
            <use>standard</use>
            <args>
                <module>Final_Dummy</module>
                <frontName>dummy</frontName>
            </args>
        </dummy>
    </routers>
</frontend>
<global>
    <helpers>
        <dummy>
            <class>Final_Dummy_Helper</class>
        </dummy>
    </helpers>
    <models>
        <dummy>
            <class>Final_Dummy_Model</class>
            <resourceModel>dummy_resource</resourceModel>
        </dummy>
        <dummy_rsource>
            <class>Final_Dummy_Model_Resource</class>
            <deprecatedNode>dummy_mysql4</deprecatedNode>
        </dummy_rsource>
        <customer_resource>
            <rewrite>
              <customer>Final_Dummy_Model_Resource_Customer</customer>
            </rewrite>
        </customer_resource>
    </models>
</global>
</config>

and in order to make sure that it really works I created the following class:

<?php
class Final_Dummy_Model_Resource_Customer extends Mage_Customer_Model_Resource_Customer{
    public function amIHere(){
        return 'Yes sir';
    }
}
?>

and called the resource in my module's controller like this

<?php
class Final_Dummy_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        $res=Mage::getResourceModel('customer/customer');
        die($res->amIHere());
    }
}
?>

and the result was:

Yes sir

I hope these code help you in some way. remember to clear the cache and I do recommend that in development phase, disable Magento compiler.

Share:
17,494
wutzebaer
Author by

wutzebaer

Updated on June 04, 2022

Comments

  • wutzebaer
    wutzebaer almost 2 years

    i try to overridde

    app\code\core\Mage\Customer\Model\Resource\Customer.php
    

    with this xml:

    <models> 
        <customer_resource>
            <rewrite>
                <customer>My_Company_Model_Resource_Customer</customer>
            </rewrite>
        </customer_resource>     
    </models>
    

    but i get

    Mage registry key "_resource_singleton/customer/customer" already exists
    

    and with

            <customer>
                <rewrite>
                    <customer_resource>My_Company_Model_Resource_Customer</customer_resource>
                </rewrite>
            </customer>
    

    or

        <models>
            <customer>
                <rewrite>
                    <resource_customer>My_Company_Model_Resource_Customer</resource_customer>
                </rewrite>
            </customer>
        </models>
    

    nothing happens