0

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"

1

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);
  • Ok I have this pulling now, customer name, phone, city, State. however it returs Street as "array" And I can't get zip to give me anything, would it be getZipcode? – John Burgess Feb 5 '18 at 21:38
  • Cmon, try it yourself :) Mage::log($billingaddress->debug(), ... should show, that there is no zipcode data, but postcode. ;) If streets is an array, i guess you have at least street_1 and street_2 ... I dont know what you want to do at the end, but foreach() and implode() could be usefull. – sv3n Feb 5 '18 at 21:50
  • Ok I see what you are saying about the customer-address.log. Now this was able to pull down the street address, but it combines the 2 lines, into 1 line, and my customerupdate.log is still coming through as an "array". Am I able to print the two lines as 2 lines? – John Burgess Feb 5 '18 at 21:55
  • Please check: magento.stackexchange.com/questions/9768/… – sv3n Feb 5 '18 at 22:01
0

I don't think you can get address with event object. Try loading the customer object using customer model with Id and get the address.

$customerId = $customer->getId();
$customerObject=Mage::getModel('customer/customer')->load($customerId);
  • I edited my code to match your answer and am not getting any different result. – John Burgess Feb 5 '18 at 17:22
  • Are you getting customer id at least ? – Kalyan Chakravarthi V Feb 5 '18 at 17:24
  • I did get it to populate the customer Id #, how can I go from there to getting the address? – John Burgess Feb 5 '18 at 17:26
  • $observer->getCustomer(); should return a Mage_Customer_Model_Customer object, so it should be possible to get adress details from there ... – sv3n Feb 5 '18 at 19:17

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.