Magento 1.9 – Get Customer Address Information from Observer

customercustomer-addressevent-observermagento-1.9

I have created an observer event on the customer_save_after event. At this point I am able to get the new name. I am trying to also retrieve their default billing address. If possible bring them in as separate items like Address 1, Address 2, City, State, Zip code.

<?php
class Mage_Customerupdate_Model_Observer
{
    public function logUpdate(Varien_Event_Observer $observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        $name = $customer->getName();
        $billingaddress = $customer->getDefaultBillingAddress();
        $customerId = $customer->getId();
        $customerObject=Mage::getModel('customer/customer')->load($customerId);

         Mage::log("{$name} ({$billingaddress}) ({$customerid}) updated", null, 'customerupdate.log', true);
    }
}
?>

In order to get an address change maybe I have to add another event to capture that. I don't really know

At this point all I get in my results are "NAME () (ID#) updated"

Best Answer

If you want to get billing adress details, you can try this:

class Mage_Customerupdate_Model_Observer
{
    public function logUpdate(Varien_Event_Observer $observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        $name = $customer->getName();
        $customerId = $customer->getId();
        $billingaddress = $customer->getDefaultBillingAddress();
        // just check if there is a billing adress
        if ($billingaddress) {
            $fon = $billingaddress->getTelephone(); // or $billingaddress->getData('telephone')
            $street = $billingaddress->getStreet(); // or $billingaddress->getData('street')
            ...
        }
    }
}

To check all available adress data ....

Mage::log($billingaddress->debug(), ZEND_LOG::DEBUG, 'customer-adress.log', true);
Related Topic