cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the shipping address from using sales_order_payment_save_after event

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to get the shipping address from using sales_order_payment_save_after event

I need to save the shipping address while order is placed in my custom table how to i take the shipping address . I am using the event sales_order_payment_save_after and did the following codes

 

$shippingAddress = $order->getShippingAddress();
 $city = $shippingAddress->getCity();
 $state = $shippingAddress->getRegion();
$countryData = $this->countryInformation->getCountryInfo($shippingAddress->getCountryId());
$country = $countryData->getFullNameLocale();

 

It is not return any result . how to i get the shipping addess

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to get the shipping address from using sales_order_payment_save_after event

You need to keep below code in your observer file,

public function execute(Observer $observer)
    {
        /** @var OrderPaymentInterface $payment */
        $payment = $observer->getDataByKey('payment');

        $order = $payment->getOrder();

        $shippingAddress = $order->getShippingAddress();
        $city = $shippingAddress->getCity();
        $state = $shippingAddress->getRegion();
        $countryData = $this->countryInformation->getCountryInfo($shippingAddress->getCountryId());
        $country = $countryData->getFullNameLocale();
        return $this;
    }

First, you need to get a payment object and based on payment object you need to get Order Data.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

1 REPLY 1

Re: How to get the shipping address from using sales_order_payment_save_after event

You need to keep below code in your observer file,

public function execute(Observer $observer)
    {
        /** @var OrderPaymentInterface $payment */
        $payment = $observer->getDataByKey('payment');

        $order = $payment->getOrder();

        $shippingAddress = $order->getShippingAddress();
        $city = $shippingAddress->getCity();
        $state = $shippingAddress->getRegion();
        $countryData = $this->countryInformation->getCountryInfo($shippingAddress->getCountryId());
        $country = $countryData->getFullNameLocale();
        return $this;
    }

First, you need to get a payment object and based on payment object you need to get Order Data.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial