Order Repository save not working
-
06-02-2021 - |
Question
I am trying to associate orders and customer using the following code.
$order = $this->orderRepo->get($oid);
$order->setCustomerId($newCustomer->getId());
$order->setCustomerIsGuest(0);
$this->orderRepo->save($order);
Where orderRepo is Magento\Sales\Api\OrderRepositoryInterface
But save is not working as expected and I can’t see association in order details page/customer order section.
I have checked in the create
method in \Magento\Sales\Model\Order\CustomerManagement
and Magento is doing the same.
Solution
I found the problem it was because some other module was loading the order object using Magento\Sales\Model\OrderFactory
and setting some data and then calling save
method of it.
I have solved my problem by calling my method after this module's processing.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange