0

When I run this code in a customer_save_after observer

$customer2 = Mage::getModel('customer/customer')->load(73);
try{        
  $customer2->setDomain("");
  $customer2->save();       
}
catch(exception $e){
  Mage::log($e);
}

Domain is a custom attribute.

I get the following error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 130968 bytes)

It says the error comes from Zend (Date.php)

Does anyone know where this comes from? The above works fine outside of this observer.

I have set the max_memory in php.ini to 1gb.

0

You need to check if the added domain is already there so you won't save the customer again, what you are doing now will make Magento trigger the same method again on the event of customer saving. which then you will end up with it looping forever. May be you can do something like :

$customer2 = Mage::getModel('customer/customer')->load(73);
try{
   if(isset($customer2->getDomain()) && !empty($customer2->getDomain())) {       
      $customer2->setDomain("");
      $customer2->save();
   }
}
catch(exception $e){
  Mage::log($e);
}
0

The problem was $customer2->save(); When you run (customermodel)->save(); it triggeres the customer_save_after observer thus creating a never ending loop. I solved it by using another observer.

  • :) Common trap. I think we have all done that at some point. – ProxiBlue Dec 8 '15 at 14:32

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.