I am overriding Mage/Customer/Model/Customer.php in my local module:


protected function _beforeSave()
        echo get_class($this);   //Abc_Customer_Customer_Model_Customer_Customer is the above output


The above code is coming from Mage/Model/Resource/Customer.php

This is throwing an error :

Fatal error: Call to protected method Mage_Customer_Model_Resource_Customer::_beforeSave() from context 'Abc_Customer_Model_Customer_Customer ....

How to call this method Mage::getResourceModel('customer/customer')->_beforeSave($this);

  • As per as file location Abc/Customer/Model/Customer.php class name should be Abc_Customer_Model_Customer.plz put config.xml rewrite code – Amit Bera Sep 28 '15 at 15:57
  • Mage::getResourceModel('customer/customer')->_beforeSave($this); this is caling the method _beforeSave($customer) from app/code/Mage/Core/Customer/Model/Resource/Customer.php – mage-kat Sep 28 '15 at 16:00
  • i cannot understand your question .There are few confusion on this why you have using ``Mage::getResourceModel('customer/customer')->_beforeSave($this);` why you have rewrite Mage/Customer/Model/Customer.php – Amit Bera Sep 28 '15 at 16:11
  • i am calling _saveBefore() , here am trying to post data external server, before posting the data to external server , we need to check weather the email used for registration already exsist in magento database. – mage-kat Sep 29 '15 at 7:29
  • If you are just looking for posting data to external server in case of a new customer registration , registering an observer on 'customer_register_success' event would be my best advice. – Prateek Sep 29 '15 at 8:57

As the error already mentioned, you can't call a protected method outside of the class, but as the Magento system works, in this case, you don't have to. Every model save call internally calls save method of it's resource model which in turn call the beforeSave method, that's the way models work in Magento, so the call you are trying to create is redundant in this case.

Also, I'd suggest working with the save_before events instead of overriding beforeSave method, they are much safer.

  • you are correct. I tam trying with this solution , but looking for even best practise of magento $this->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($this->getData('email')); – mage-kat Sep 29 '15 at 7:30
  • Didn't get that code part, can you elaborate ? – Prateek Sep 29 '15 at 8:44
  • count($customerEmailCheck->getData()) from the registration form , we will get the post data, we are checking here weather the email id is already exsisting in the magento database. If email id is found , through error and redirect the user to signup/registration page, if the email id is not present push the data to ERP system as well as save the data in magento system, Note : in our scenario the data is getting pushed to ERP and saved but magento will throw error email id already exsist. – mage-kat Sep 29 '15 at 9:46
  • Is your registration form within the scope of Magento application ? – Prateek Sep 29 '15 at 10:20
  • yes its in scope – mage-kat Sep 29 '15 at 17:12

The answer is 'customer_register_success' as mentioned above by Prateek.

In _beforeSave() , customer model file i have used this one

$emailCheck= $this->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($this->getData('email'));
        if($emailCheck->getData('entity_id')!= ''){
//error message email id exsist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.