Magento 1.9.3 – Get Shipping Address from Observer Event sales_order_place_after

event-observermagento-1.9shipping-address

I have a custom function that is triggered with event sales_order_place_after, I need to retrieve the shipping address in this function.

I tried $observer->getCustomerAddress(), but it didn't work. How could I get the shipping address?

This is my function

        public function SalesOrderPlaceAfter($observer)
        {

            $orderIds = $observer->getEvent()->getOrder()->getId();   
                if (!empty($orderIds)) 
                {
//This get me the shipping method. it's working.
    $shipping_method = $observer->getEvent()->getOrder()->getShippingMethod(); 

// this is not working, How can I get the shipping address?
    $shipping_address = $observer->getEvent()->getOrder()->getShippingAddress(); 
                }
        }

Best Answer

You've loaded the Address object as per Rene's answer, here's how you'd get the fields;

$_shippingAddress = $observer->getEvent()->getOrder()->getShippingAddress();

echo $_shippingAddress->getFirstname();
echo $_shippingAddress->getLastname();
echo $_shippingAddress->getCompany();
echo $_shippingAddress->getStreetFull();
echo $_shippingAddress->getRegion();
echo $_shippingAddress->getCity();
echo $_shippingAddress->getPostcode();
echo $_shippingAddress->getTelephone();
echo $_shippingAddress->getCountryId();
Related Topic