My requirement
I Have created custom shipping method for allowing customers to choose Stores to pickup the orders. When the customers choose the stores pickup option, I need to update the selected store address as shipping address for the relevant order.
Checkout section and save the store id part is successfully implemented.
I tried to update the shipping address using observer checkout_onepage_controller_success_action
like below.
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
try{
$quote = $this->quoteRepository->get($order->getQuoteId());
$order->setPickupStoreName($quote->getPickupStoreName());
//set shipping address here
$shippingAddress = array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => "Mujahidh",
'middlename' => '',
'lastname' => "Haseem",
'suffix' => '',
'company' => '',
'street' => array(
'0' => 'Address 1',
'1' => 'Address 2'
),
'city' => 'Culver City',
'country_id' => 'US',
'region' => 'California',
'region_id' => '12',
'postcode' => '90232',
'telephone' => '888-888-8888',
'fax' => ''
);
//-------
$quote->getShippingAddress()->addData($shippingAddress);
$quote->save();
$order->save();
return $this;
} catch(\Exception $e){
$this->logger->info('Error in execute method in sales order place observer :'.$e->getMessage());
}
}
Using this way i am unable to save it. How can i update the shipping address in this scenario?