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
Override module view-files in the app/code folder. Make the necessary changes to the newly created theme file. If your own theme is missing from your Magento installation, create new theme.
To override a controller, you have to create a subclass to define existing functions. Now select a function from the controller for overriding from the addons. For better understanding, I have selected the following Carousel Recently viewed function for overriding.
What is a Model in Magento 2? A Model is a class that represents an entity or a record from a database. The model also provides access to entity data that is used across the Magento 2 application. The model term comes from a Model-View-Controller design pattern and is an important component to understand in Magento 2.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With