1

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

  • Order is placed in my custom table means? – Keyur Shah Dec 19 '18 at 8:14
  • @KeyurShah I have a custom table. i need to save order details in my table while order is placed . so i use the event "sales_order_payment_save_after" . when the event is called i am not able to get the orders shipping address – Sammu Sundar Dec 19 '18 at 8:15
0

You can try something like this:

use Magento\Checkout\Model\Session as CheckoutSession;

public function __construct(
    CheckoutSession $session,
){
    $this->session = $session;
}
public function execute(Observer $observer)
{
    $quote = $this->session->getQuote();
    $shipping = $quote->getShippingAddress();
    $shipping->getCountryId();
    $shipping->getCity();
    $shipping->getRegion();
 }

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.