2
votes

I'm trying to extend the Customer module in Magento but I'm not having much luck.

I have: added a MyModule_Customer.xml to the etc/modules directory, set up with correct name and path. Created a MyModule/Customer/etc/config.xml Created a MyModule/Customer/Model/Customer.php (copied from Core/Customer). I added a Mage::log to my new class but it never logs anything.

There are to things I'm not sure about. Does my Customer.php class declaration extend the Mage_Customer_Model_Customer class or the Mage_Core_Model_Abstract class. What I've read online isn't consistent.

Is this the correct format for the rewrite section in the MyModule/etc/config.xml? MyModule_Customer_Model_Customer .... Or should there be another element inside the ? I tried adding around the path but that stopped Magento working altogether.

EDIT: The local/MyModule/Customer/etc/config.xml This is really a copy of the Mage/Customer config.xml with the module redefined and the rewrite section added

<pre>
global>  
models>  
customer>  
rewrite>                  
customer>
MyModule_Customer_Model_Customer
/customer>  
/rewrite>  
/customer>  
/models>  
/global>
</pre>

But this caused Magento to break and not display anything. My current best guess is as above but with the most inner customer elements removed.

EDIT 2: Here is all the code The app/etc/modules/MyModule_Customer.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyModule_Customer>
<active>true</active>
<codePool>local</codePool>
<depends>
 Mage_Customer
</depends>
</MyModule_Customer>
</modules>
</config>

A query about this format - most articles I saw didn't have a depends element here but enough did that I though I should try it, it makes sense. But is it right?

My local/MyModule/Customer/Model/Customer.php declaration:

class MyModule_Customer_Model_Customer extends Mage_Customer_Model_Customer

So, thats everything. The tutorials I read online suggest this should be trivial so what am I doing wrong? Any help would be much appreciated. Thank you.

2
please post your full codeMarius
I think you should override the core model in config.xml <global> <models> <customer> <rewrite> <customer>MyModule_Customer_Model_Customer</customer> </rewrite> </customer> </models> </global>Aleksandr
Thank you Alek, that was part of the answer but I found the actual line I was missing was to include the Core php file via: require_once('Mage/Customer/Model/Customer.php'. Then everything started working.Steve

2 Answers

1
votes

I finally found the solution. In the extended class use require_once to refer to the core class. E.g. require_once('Mage/Customer/Model/Customer.php');

0
votes

You shouldn't name your own module the same as an original, in this case 'Customer'. It can work, but it's very confusing. For Magento and other developers that might work on your code.

When overwriting the Customer model, you will need to extend Mage_Customer_Model_Customer. In that case you only have to place the method in your class that you want to rewrite. Copying the full parent class is unnecessary.

Please add your full config.xml :)