Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Overload Model Entity
 
scallion
Jr. Member
 
Total Posts:  3
Joined:  2008-08-05
 

Hi,

I want to extend the customer model of Magento. I succeeded in overloading the model class Mage_Customer_Model_Customer but I can’t overload the Entity class. Here is my config.xml file :

<?xml version="1.0"?>
<config>
    <
modules>
        <
Clrz_Customer>
            <
version>0.1.0</version>
        </
Clrz_Customer>
    </
modules>
    <global>
        <
models>
            <
customer>
                <
rewrite>
                      <
customer>Clrz_Customer_Model_Customer</customer>
                </
rewrite>
            </
customer>
        </
models>
    </global>
</
config>

And here is my new entity class file :

class Clrz_Customer_Model_Entity_Customer extends Mage_Customer_Model_Entity_Customer
{
    
protected function _beforeSave(Varien_Object $customer)
    
{
         parent
::_beforeSave($customer);
    
            
$collection Mage::getResourceModel('customer/customer_collection')
                ->
addAttributeToFilter'pseudo', array('='=>$customer->getPseudo() ) )->load();
        if (
$collection->getItems()) {
            Mage
::throwException(Mage::helper('customer')->__('customer Pseudo already exists')); 
        
}
        
      
return $this
    
}
}

Tha naming convention is ok, I must be missing something in the config.xml file.

Thanks a lot !

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unluckypixie
Jr. Member
 
Total Posts:  4
Joined:  2008-08-06
 

Based on how I’ve got entity overloads working I think you want something like:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Clrz_Customer>
            <
version>0.1.0</version>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Clrz_Customer>
    </
modules>
    <
models>
        <
customer_entity>
            <
rewrite>
                  <
customer>Clrz_Customer_Model_Entity_Customer</customer>
            </
rewrite>
        </
customer_entity>
    </
models>
</
config>

The use of “customer_entity” instead of “customer” didn’t seem very intuitive to me and threw me for ages too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scallion
Jr. Member
 
Total Posts:  3
Joined:  2008-08-05
 

Thanks a lot, that’s it !

 
Magento Community Magento Community
Magento Community
Magento Community
 
platinumtackle
Member
 
Total Posts:  40
Joined:  2008-09-30
 

Did you add more fields to setup.php?  I am trying to add some more attributes to customer by extending setup.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
miked2004
Sr. Member
 
Avatar
Total Posts:  214
Joined:  2007-12-13
Atlanta, Georgia
 

I am trying to add a section to magento customers called showroom. I was trying to mock the way customer address are setup/used. I was able to get it working by adding and editing in the magento core files,but now I want to migrate the code to the local code folder to allow clean updating. I was able to override the model/customer, model/entity/customer and other files that are in the core files; but I had added customer/model/showroom.php, customer/model/showroom/abstract.php, customer/model/showroom/config.php, and have not been able to get them to work in my local code folder.

I am not sure how to set up the /etc/congig.xml “models” node to use the new files. I am not sure if I should use rewrite or not.

when the code was all in core/mage/customer folders I just added

<showroom_entity>
      <
table>customer_showroom_entity</table>        
</
showroom_entity>

inside of

<models>
            <
customer>
                <class>
Mage_Customer_Model</class>
                <
resourceModel>customer_entity</resourceModel>
            </
customer>
            <
customer_entity>
                <class>
Mage_Customer_Model_Entity</class>
                <
entities>
                       <
showroom_entity>
                    <
table>customer_showroom_entity</table>        
                    </
showroom_entity>
                 </
entities>
             <
customer_entity>
</
models>

If any one could point me in the right direction I would be greatly appreciative.

P.S. Just to reiderate I have no problem rewriteing core files, my problem is adding the “NEW” customer_showroom model information to the customer code.

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