1

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'));

    } 
}
?>
  • please try to remove cache and try i have same problem occur before – Keyur Shah Apr 30 '15 at 6:47
  • i removed cache.not working. – sivakumar Apr 30 '15 at 6:58
  • have you add new field company to customer? – Amit Bera Apr 30 '15 at 7:17
  • added.there is no problem with field name.that is sure – sivakumar Apr 30 '15 at 7:27
1

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');
  • Fatal error: Call to undefined method Mage_Customer_Model_Resource_Customer::setAttribute() – sivakumar Apr 30 '15 at 7:36
  • please check... i have update the answer – Amit Bera Apr 30 '15 at 7:40
  • upvote your answer – Amit Bera Apr 30 '15 at 7:50
2

Everything seems to be ok. The one thing that is missing is calling the save method

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

   $address = $observer->getCustomerAddress();
   $customer= $address->getCustomer();
    $customer->setData('company', $address->getData('company'));
    $customer->save();
    } 
}
  • i mentioned "even i tried save function on that.but it is also not working" in question.the browser continuously loading.after some time it is stopped. – sivakumar Apr 30 '15 at 7:16
  • 1
    ahhhh right, because it's calling the address save from the customer save. Ok let me see – Sander Mangel Apr 30 '15 at 7:18

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.