Save Customer Account Field When Address Object Saved

addresscustomerenterprise-1.14event-observer

The following observer calling properly.I'm getting address ,customer object also .

but customer setting data not working(3rd line).even i tried save function on that.but it is also not working.
even i changed event name customer_address_save_before.
here i created customer attribute company.

can you help any one?

<?xml version="1.0"?>
<config>
  <modules>
    <Gumbrands_Officename>
      <version>0.1.0</version>
    </Gumbrands_Officename>
  </modules>
    <global><models>
            <officename>
                <class>Gumbrands_Officename_Model</class>
            </officename>
        </models>
<events>
<customer_address_save_after>
            <observers>
                <Officename>
                    <type>singleton</type>
                    <class>officename/observer</class>
                    <method>updateCompany1</method>
                </Officename>
            </observers>
        </customer_address_save_after>
</events>
</global>
</config>

Observer.php

<?php
class Gumbrands_Officename_Model_Observer
{  
    public function updateCompany1($observer)
    { 

   $address = $observer->getCustomerAddress();
   $customer= $address->getCustomer();
   $customer->setData('company', $address->getData('company'));

    } 
}
?>

Best Answer

Please use update the attribute using Resource model because of when you have using save() function of customer model then customer will also call customer address model save function that make loop.If you use getResource()->saveAttribute() function that only update only specific field that means it does not call address model save function

$customer->setData('company', $address->getData('company'));
$customer->getResource()->saveAttribute($customer,'company');
Related Topic