Magento Forum

   
overriding Customer Entity Model not working [SOLVED]
 
vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Hi,

I’m working on overriding the class Mage_Customer_Model_Entity_Customer.
I tried it like overriding the customer model, but withouot success.
This doesn’t work:

<customer_entity>
    <
rewrite>
      <
customer_entity>My_CustomModule_Model_Entity_Customer</customer_entity>
    </
rewrite>
 </
customer_entity>

My question is, how do I override Mage_Customer_Model_Entity_Customer ?

Thanks,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

OK, simpler then I thought:

<models>
    <
customer_entity>
        <class>
My_CustomModule_Model_Entity</class>
    <
customer_entity>
<
models>

My_CustomModule_Model_Entity_Customer is now used as I want it to in place of Mage_Customer_Model_Entity_Customer, but…

Warning: include(My/CustomModule/Model/Entity/Group.php[function.include]failed to open streamNo such file or directory...

So, how can I only override Mage_Customer_Model_Entity_Customer, and leave the other Customer Model Entities untouched?
I have the suspicion that the answer lies in eav_attribute.attribute_model, eav_attribute.backend_model or eav_attribute.frontend_model

But I don’t understand how they work. Can someone please help?

Thanks,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Your new class that is overwriting the old class should extend the over-ridden class and not the class that the over-ridden class extends.

I love Magento just for letting me write that sentence <3

(this means you shouldn’t be using ‘include’)

example of what I mean:

if the original code is this:

Mage_Block_Example extends Mage_Core_Abstract {
//code
}

Yours new class that is over-riding Mage_Block_Example should be like this:

MyCompany_Block_Example extends Mage_Block_Example {
//notice im not extending the abstract but I am extending the class that I'm overriding. Don't use an "include" or "require" !
}

Your include probably would have worked instead of how I did it, but your file path needs to be relative to index.php (root magento folder), so it would be more like: (notice i use require_once instead of include)

require_once('app/code/local/My/CustomModule/Model/Entity/Group');

 
Magento Community Magento Community
Magento Community
Magento Community
 
vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Hi nikefido, thank you very much for your answer!
I am extending the original Magento classes I am overriding.

class My_CustomModule_Model_Entity_Customer extends Mage_Customer_Model_Entity_Customer

For entities resources the value of eav_entity_type.entity_model in the database extends the
value provided in the config.xml, so

<customer_entity>
    <class>
My_CustomModule_Model_Entity</class>
<
customer_entity>
and a entity_model value of customer/customer will be the class My_CustomModule_Model_Entity_Customer.
As far as I understand the first part of customer/customer is a pointer to the Model in the config.xml, and the seconod part gets appended to the value of the <class> tag.
Now, when some code loads a entity_model customer/group, it looks for
My_CustomModule_Model_Entity_Group instead of
Mage_Customer_Model_Entity_Group.
Now in my case I only want to override Mage_Customer_Model_Entity_Customer, not the other entities of the customer model.

But how can I do that?

Thanks,
Vinai

 
Magento Community Magento Community
Magento Community
Magento Community
 
vinai
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2008-04-04
Heidelberg, Germany
 

Here is the solution:

http://www.magentocommerce.com/boards/viewthread/14103/

(Thanks to vinko to point me to it!)

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top