I have to update some sales order parameters

$order = $this->orderInterface->loadByIncrementId('000000009');

Here save() is @deprecated and also if try to save, it does not save.

I tried:

*  @var OrderStatusApiInterface

It changes all the other data also is completely false.

2 Answers 2


you can use OrderRepositoryInterface to load the order and ResourceModel to save order. I tested follow code and it's works fine at my local Magento.

public function __construct(
    \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
    \Magento\Sales\Model\ResourceModel\Order $orderResourceModel
) {
    $this->orderResourceModel = $orderResourceModel;
    $this->orderRepository = $orderRepository;

public function execute()
    $order = $this->orderRepository->get(1);
    $order->setCustomerEmail('[email protected]');
  • saved my time +1 Commented Jan 22, 2019 at 13:27
class Index extends \Magento\Backend\App\Action
  protected $resultJsonFactory;  
  protected $_orderRepository ;

   public function __construct(
     \Magento\Backend\App\Action\Context $context,
     \Magento\Sales\Model\Order $orderRepository,
     \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
   ) {
   $this->resultJsonFactory = $resultJsonFactory;
   $this->_orderRepository = $orderRepository;

  public function execute()
    $email = $this->getRequest()->getParam('email');
    $orderId = $this->getRequest()->getParam('OrderId');
    $_order = $this->_orderRepository->load($orderId); // it order is not order increment id
         echo "Saved";
        echo "Error:Not Saved";


  • Update customer order data through code in magento2.x
    – Lokesh Das
    Commented Jun 21, 2018 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.