How to edit or update the ordered item data in magento 2Magento 2 change order item priceUnit Test for overwrite collection class in magento2Convert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2Uncaught Error: Call to a member function setItem() on boolean on product grid: Magento 2Unable to create order from admin in magento 2How to get the ordered size of a product In Magento 2Magento 2 get custom attribute of a single product inside a pluginMagento 2 plugin change price of products that have a custom attribute withget invoice item using order_item_id in magento 2Magento 2.3 EE Bulk Asynchronous API Operations using RabbitMQMagento 2 Uncaught TypeError: Argument 1 […] DataSetup::__construct() […] must be an instance […]

Should I bike or drive to work? (6.8 mi)

What container to use to store developer concentrate?

Why do they sell Cat 5 Ethernet splitters if you can’t split the signal?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

Nested keyval proper parsing

Is there a way to know the composition of a Team GO Rocket before going into the fight?

Is it possible to attain stream-entry if one is only following "the 5 precepts"?

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

Is it safe if the neutral lead is exposed and disconnected?

Polyhedra, Polyhedron, Polytopes and Polygon

Is there a wealth gap in Boston where the median net worth of white households is $247,500 while the median net worth for black families was $8?

Composing fill in the blanks

Why does the Eurostar not show youth pricing?

Finding out if upgrading to a newer macOS version will cause issues?

Is there an antonym for "spicy" or "hot" regarding food?

Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?

Applying a Taylor series WITH RESPECT TO ... and AROUND...

Sci-fi change: Too much or Not enough

8086 stack segment and avoiding overflow in interrupts

ECDSA: Why is SigningKey shorter than VerifyingKey

What is this 4 sharp symbol and what does it mean?

What happens when a flying sword is killed?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

Summoning A Technology Based Demon



How to edit or update the ordered item data in magento 2


Magento 2 change order item priceUnit Test for overwrite collection class in magento2Convert MagentoQuoteModelQuote to MagentoSalesModelOrder: Magento 2Uncaught Error: Call to a member function setItem() on boolean on product grid: Magento 2Unable to create order from admin in magento 2How to get the ordered size of a product In Magento 2Magento 2 get custom attribute of a single product inside a pluginMagento 2 plugin change price of products that have a custom attribute withget invoice item using order_item_id in magento 2Magento 2.3 EE Bulk Asynchronous API Operations using RabbitMQMagento 2 Uncaught TypeError: Argument 1 […] DataSetup::__construct() […] must be an instance […]






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to edit some data's of ordered items like weight, price and some more.



For that, I got the ordered item collection for the specific order.



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orderItemId = '3';
$orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
$orderItems = $orderItem->getData()


So $orderItems has the ordered item collection.



And then I have tried to edit the ordered items like below.



foreach ( $orderItems->getData() as $val ) 
$val->setWeight(1)->save();



But the weight not gets updated.



Full Code:



$orderId = $_GET['id'];
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderId);

// Edit the order items data
foreach ($order->getAllItems() as $key => $value)
$orderItemId = $value->getData('item_id');
$orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
$orderItems = $orderItem->getData();
foreach ( $orderItems as $val )
$val->setWeight(1)->save();


$orderResourceModel->save($order);


I've just referred this link here. But I'm not having a clear idea about the orderquote.



I'm using magento 2.3 version.



Please help me. I am a novice in magento and I am stuck at this point. Thank you in advance!!










share|improve this question
































    2















    I want to edit some data's of ordered items like weight, price and some more.



    For that, I got the ordered item collection for the specific order.



    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $orderItemId = '3';
    $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
    $orderItems = $orderItem->getData()


    So $orderItems has the ordered item collection.



    And then I have tried to edit the ordered items like below.



    foreach ( $orderItems->getData() as $val ) 
    $val->setWeight(1)->save();



    But the weight not gets updated.



    Full Code:



    $orderId = $_GET['id'];
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderId);

    // Edit the order items data
    foreach ($order->getAllItems() as $key => $value)
    $orderItemId = $value->getData('item_id');
    $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
    $orderItems = $orderItem->getData();
    foreach ( $orderItems as $val )
    $val->setWeight(1)->save();


    $orderResourceModel->save($order);


    I've just referred this link here. But I'm not having a clear idea about the orderquote.



    I'm using magento 2.3 version.



    Please help me. I am a novice in magento and I am stuck at this point. Thank you in advance!!










    share|improve this question




























      2












      2








      2


      2






      I want to edit some data's of ordered items like weight, price and some more.



      For that, I got the ordered item collection for the specific order.



      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $orderItemId = '3';
      $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
      $orderItems = $orderItem->getData()


      So $orderItems has the ordered item collection.



      And then I have tried to edit the ordered items like below.



      foreach ( $orderItems->getData() as $val ) 
      $val->setWeight(1)->save();



      But the weight not gets updated.



      Full Code:



      $orderId = $_GET['id'];
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderId);

      // Edit the order items data
      foreach ($order->getAllItems() as $key => $value)
      $orderItemId = $value->getData('item_id');
      $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
      $orderItems = $orderItem->getData();
      foreach ( $orderItems as $val )
      $val->setWeight(1)->save();


      $orderResourceModel->save($order);


      I've just referred this link here. But I'm not having a clear idea about the orderquote.



      I'm using magento 2.3 version.



      Please help me. I am a novice in magento and I am stuck at this point. Thank you in advance!!










      share|improve this question
















      I want to edit some data's of ordered items like weight, price and some more.



      For that, I got the ordered item collection for the specific order.



      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $orderItemId = '3';
      $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
      $orderItems = $orderItem->getData()


      So $orderItems has the ordered item collection.



      And then I have tried to edit the ordered items like below.



      foreach ( $orderItems->getData() as $val ) 
      $val->setWeight(1)->save();



      But the weight not gets updated.



      Full Code:



      $orderId = $_GET['id'];
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $order = $objectManager->create('MagentoSalesApiDataOrderInterface')->load($orderId);

      // Edit the order items data
      foreach ($order->getAllItems() as $key => $value)
      $orderItemId = $value->getData('item_id');
      $orderItem = $objectManager->create('MagentoSalesApiOrderItemRepositoryInterface')->get($orderItemId);
      $orderItems = $orderItem->getData();
      foreach ( $orderItems as $val )
      $val->setWeight(1)->save();


      $orderResourceModel->save($order);


      I've just referred this link here. But I'm not having a clear idea about the orderquote.



      I'm using magento 2.3 version.



      Please help me. I am a novice in magento and I am stuck at this point. Thank you in advance!!







      magento2 magento2.3 order-items






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 19 at 4:52







      Ramya

















      asked Jul 19 at 4:44









      RamyaRamya

      208 bronze badges




      208 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          2














          Use below method to update order item data, Note: using objectManager directly is not recommended.



          protected $_orderItems;

          public function __construct(
          MagentoSalesModelResourceModelOrderItemCollectionFactory $orderItems
          )

          $this->_orderItems = $orderItems;


          public function execute()

          $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight(1);
          $orderItem->save();



          For testing purpose use



          use MagentoFrameworkAppBootstrap;
          include('app/bootstrap.php');
          $bootstrapp = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrapp->getObjectManager();
          $appState = $objectManager->get('MagentoFrameworkAppState');
          $appState->setAreaCode('frontend');

          $orderItem = $objectManager->get('MagentoSalesModelResourceModelOrderItemCollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight('2')->save();





          share|improve this answer



























          • Thanks Ranganathan. Will try this method and let you know.

            – Ramya
            Jul 19 at 5:04











          • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

            – Ramya
            Jul 19 at 5:14











          • Where do you want to implement this code?

            – Ranganathan
            Jul 19 at 5:15











          • For my testing purpose, I'm writing the code on magento root folder

            – Ramya
            Jul 19 at 5:16











          • Yes you can use objectmanager here only......

            – Ranganathan
            Jul 19 at 5:17


















          0














          You can update or edit the existing order by following



          $orderId = '21';
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $quoteToOrder = $objectManager->create('MagentoQuoteModelQuoteItemToOrderItem');
          $order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);
          $quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());


          Update the order quote.



          $items = $quote->getQuote()->getAllVisibleItems();

          foreach ($items as $quoteItem)

          $origOrderItem = $order->getItemByQuoteItemId($quoteItem->getId());
          $orderItemId = $origOrderItem->getItemId();

          //update quote item according your need
          $quoteItem->setWeight();
          $quoteItem->setQty();
          ....

          $quote->collectTotals();
          $quote->save();


          Update the order



          foreach ($items as $quoteItem) 

          $orderItem = $quoteToOrder->convert($quoteItem);
          $origOrderItemNew = $order->getItemByQuoteItemId($quoteItem->getId());

          if ($origOrderItemNew)

          $origOrderItemNew->addData($orderItem->getData());

          else

          if ($quoteItem->getParentItem())

          $orderItem->setParentItem($order->getItemByQuoteItemId($orderItem->getParentItem()->getId()));


          $order->addItem($orderItem);



          $order->setSubtotal($quote->getSubtotal())
          ->setBaseSubtotal($quote->getBaseSubtotal())
          ->setGrandTotal($quote->getGrandTotal())
          ->setBaseGrandTotal($quote->getBaseGrandTotal());

          $quote->save();
          $order->save();





          share|improve this answer



























          • But the question is how to update order items......Not how to update (order)/(quote items)...

            – Ranganathan
            Jul 19 at 5:02












          • you can edit order item as well, look at "update quote item according your need"

            – user4536
            Jul 19 at 5:05












          • I've just referred this link here. But I'm not having a clear idea about the orderquote.

            – Ramya
            Jul 19 at 5:05












          • But you didn't declared the $items variable..What the items variable has?

            – Ranganathan
            Jul 19 at 5:07












          • You're right Ranganathan. That was my doubt while I'm referring that above link.

            – Ramya
            Jul 19 at 5:13













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282590%2fhow-to-edit-or-update-the-ordered-item-data-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Use below method to update order item data, Note: using objectManager directly is not recommended.



          protected $_orderItems;

          public function __construct(
          MagentoSalesModelResourceModelOrderItemCollectionFactory $orderItems
          )

          $this->_orderItems = $orderItems;


          public function execute()

          $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight(1);
          $orderItem->save();



          For testing purpose use



          use MagentoFrameworkAppBootstrap;
          include('app/bootstrap.php');
          $bootstrapp = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrapp->getObjectManager();
          $appState = $objectManager->get('MagentoFrameworkAppState');
          $appState->setAreaCode('frontend');

          $orderItem = $objectManager->get('MagentoSalesModelResourceModelOrderItemCollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight('2')->save();





          share|improve this answer



























          • Thanks Ranganathan. Will try this method and let you know.

            – Ramya
            Jul 19 at 5:04











          • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

            – Ramya
            Jul 19 at 5:14











          • Where do you want to implement this code?

            – Ranganathan
            Jul 19 at 5:15











          • For my testing purpose, I'm writing the code on magento root folder

            – Ramya
            Jul 19 at 5:16











          • Yes you can use objectmanager here only......

            – Ranganathan
            Jul 19 at 5:17















          2














          Use below method to update order item data, Note: using objectManager directly is not recommended.



          protected $_orderItems;

          public function __construct(
          MagentoSalesModelResourceModelOrderItemCollectionFactory $orderItems
          )

          $this->_orderItems = $orderItems;


          public function execute()

          $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight(1);
          $orderItem->save();



          For testing purpose use



          use MagentoFrameworkAppBootstrap;
          include('app/bootstrap.php');
          $bootstrapp = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrapp->getObjectManager();
          $appState = $objectManager->get('MagentoFrameworkAppState');
          $appState->setAreaCode('frontend');

          $orderItem = $objectManager->get('MagentoSalesModelResourceModelOrderItemCollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight('2')->save();





          share|improve this answer



























          • Thanks Ranganathan. Will try this method and let you know.

            – Ramya
            Jul 19 at 5:04











          • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

            – Ramya
            Jul 19 at 5:14











          • Where do you want to implement this code?

            – Ranganathan
            Jul 19 at 5:15











          • For my testing purpose, I'm writing the code on magento root folder

            – Ramya
            Jul 19 at 5:16











          • Yes you can use objectmanager here only......

            – Ranganathan
            Jul 19 at 5:17













          2












          2








          2







          Use below method to update order item data, Note: using objectManager directly is not recommended.



          protected $_orderItems;

          public function __construct(
          MagentoSalesModelResourceModelOrderItemCollectionFactory $orderItems
          )

          $this->_orderItems = $orderItems;


          public function execute()

          $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight(1);
          $orderItem->save();



          For testing purpose use



          use MagentoFrameworkAppBootstrap;
          include('app/bootstrap.php');
          $bootstrapp = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrapp->getObjectManager();
          $appState = $objectManager->get('MagentoFrameworkAppState');
          $appState->setAreaCode('frontend');

          $orderItem = $objectManager->get('MagentoSalesModelResourceModelOrderItemCollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight('2')->save();





          share|improve this answer















          Use below method to update order item data, Note: using objectManager directly is not recommended.



          protected $_orderItems;

          public function __construct(
          MagentoSalesModelResourceModelOrderItemCollectionFactory $orderItems
          )

          $this->_orderItems = $orderItems;


          public function execute()

          $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight(1);
          $orderItem->save();



          For testing purpose use



          use MagentoFrameworkAppBootstrap;
          include('app/bootstrap.php');
          $bootstrapp = Bootstrap::create(BP, $_SERVER);
          $objectManager = $bootstrapp->getObjectManager();
          $appState = $objectManager->get('MagentoFrameworkAppState');
          $appState->setAreaCode('frontend');

          $orderItem = $objectManager->get('MagentoSalesModelResourceModelOrderItemCollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
          $orderItem->setWeight('2')->save();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 19 at 6:04

























          answered Jul 19 at 4:59









          RanganathanRanganathan

          1,2496 silver badges21 bronze badges




          1,2496 silver badges21 bronze badges















          • Thanks Ranganathan. Will try this method and let you know.

            – Ramya
            Jul 19 at 5:04











          • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

            – Ramya
            Jul 19 at 5:14











          • Where do you want to implement this code?

            – Ranganathan
            Jul 19 at 5:15











          • For my testing purpose, I'm writing the code on magento root folder

            – Ramya
            Jul 19 at 5:16











          • Yes you can use objectmanager here only......

            – Ranganathan
            Jul 19 at 5:17

















          • Thanks Ranganathan. Will try this method and let you know.

            – Ramya
            Jul 19 at 5:04











          • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

            – Ramya
            Jul 19 at 5:14











          • Where do you want to implement this code?

            – Ranganathan
            Jul 19 at 5:15











          • For my testing purpose, I'm writing the code on magento root folder

            – Ramya
            Jul 19 at 5:16











          • Yes you can use objectmanager here only......

            – Ranganathan
            Jul 19 at 5:17
















          Thanks Ranganathan. Will try this method and let you know.

          – Ramya
          Jul 19 at 5:04





          Thanks Ranganathan. Will try this method and let you know.

          – Ramya
          Jul 19 at 5:04













          Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

          – Ramya
          Jul 19 at 5:14





          Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('MagentoSalesModelResourceModelOrderItemCollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

          – Ramya
          Jul 19 at 5:14













          Where do you want to implement this code?

          – Ranganathan
          Jul 19 at 5:15





          Where do you want to implement this code?

          – Ranganathan
          Jul 19 at 5:15













          For my testing purpose, I'm writing the code on magento root folder

          – Ramya
          Jul 19 at 5:16





          For my testing purpose, I'm writing the code on magento root folder

          – Ramya
          Jul 19 at 5:16













          Yes you can use objectmanager here only......

          – Ranganathan
          Jul 19 at 5:17





          Yes you can use objectmanager here only......

          – Ranganathan
          Jul 19 at 5:17













          0














          You can update or edit the existing order by following



          $orderId = '21';
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $quoteToOrder = $objectManager->create('MagentoQuoteModelQuoteItemToOrderItem');
          $order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);
          $quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());


          Update the order quote.



          $items = $quote->getQuote()->getAllVisibleItems();

          foreach ($items as $quoteItem)

          $origOrderItem = $order->getItemByQuoteItemId($quoteItem->getId());
          $orderItemId = $origOrderItem->getItemId();

          //update quote item according your need
          $quoteItem->setWeight();
          $quoteItem->setQty();
          ....

          $quote->collectTotals();
          $quote->save();


          Update the order



          foreach ($items as $quoteItem) 

          $orderItem = $quoteToOrder->convert($quoteItem);
          $origOrderItemNew = $order->getItemByQuoteItemId($quoteItem->getId());

          if ($origOrderItemNew)

          $origOrderItemNew->addData($orderItem->getData());

          else

          if ($quoteItem->getParentItem())

          $orderItem->setParentItem($order->getItemByQuoteItemId($orderItem->getParentItem()->getId()));


          $order->addItem($orderItem);



          $order->setSubtotal($quote->getSubtotal())
          ->setBaseSubtotal($quote->getBaseSubtotal())
          ->setGrandTotal($quote->getGrandTotal())
          ->setBaseGrandTotal($quote->getBaseGrandTotal());

          $quote->save();
          $order->save();





          share|improve this answer



























          • But the question is how to update order items......Not how to update (order)/(quote items)...

            – Ranganathan
            Jul 19 at 5:02












          • you can edit order item as well, look at "update quote item according your need"

            – user4536
            Jul 19 at 5:05












          • I've just referred this link here. But I'm not having a clear idea about the orderquote.

            – Ramya
            Jul 19 at 5:05












          • But you didn't declared the $items variable..What the items variable has?

            – Ranganathan
            Jul 19 at 5:07












          • You're right Ranganathan. That was my doubt while I'm referring that above link.

            – Ramya
            Jul 19 at 5:13















          0














          You can update or edit the existing order by following



          $orderId = '21';
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $quoteToOrder = $objectManager->create('MagentoQuoteModelQuoteItemToOrderItem');
          $order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);
          $quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());


          Update the order quote.



          $items = $quote->getQuote()->getAllVisibleItems();

          foreach ($items as $quoteItem)

          $origOrderItem = $order->getItemByQuoteItemId($quoteItem->getId());
          $orderItemId = $origOrderItem->getItemId();

          //update quote item according your need
          $quoteItem->setWeight();
          $quoteItem->setQty();
          ....

          $quote->collectTotals();
          $quote->save();


          Update the order



          foreach ($items as $quoteItem) 

          $orderItem = $quoteToOrder->convert($quoteItem);
          $origOrderItemNew = $order->getItemByQuoteItemId($quoteItem->getId());

          if ($origOrderItemNew)

          $origOrderItemNew->addData($orderItem->getData());

          else

          if ($quoteItem->getParentItem())

          $orderItem->setParentItem($order->getItemByQuoteItemId($orderItem->getParentItem()->getId()));


          $order->addItem($orderItem);



          $order->setSubtotal($quote->getSubtotal())
          ->setBaseSubtotal($quote->getBaseSubtotal())
          ->setGrandTotal($quote->getGrandTotal())
          ->setBaseGrandTotal($quote->getBaseGrandTotal());

          $quote->save();
          $order->save();





          share|improve this answer



























          • But the question is how to update order items......Not how to update (order)/(quote items)...

            – Ranganathan
            Jul 19 at 5:02












          • you can edit order item as well, look at "update quote item according your need"

            – user4536
            Jul 19 at 5:05












          • I've just referred this link here. But I'm not having a clear idea about the orderquote.

            – Ramya
            Jul 19 at 5:05












          • But you didn't declared the $items variable..What the items variable has?

            – Ranganathan
            Jul 19 at 5:07












          • You're right Ranganathan. That was my doubt while I'm referring that above link.

            – Ramya
            Jul 19 at 5:13













          0












          0








          0







          You can update or edit the existing order by following



          $orderId = '21';
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $quoteToOrder = $objectManager->create('MagentoQuoteModelQuoteItemToOrderItem');
          $order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);
          $quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());


          Update the order quote.



          $items = $quote->getQuote()->getAllVisibleItems();

          foreach ($items as $quoteItem)

          $origOrderItem = $order->getItemByQuoteItemId($quoteItem->getId());
          $orderItemId = $origOrderItem->getItemId();

          //update quote item according your need
          $quoteItem->setWeight();
          $quoteItem->setQty();
          ....

          $quote->collectTotals();
          $quote->save();


          Update the order



          foreach ($items as $quoteItem) 

          $orderItem = $quoteToOrder->convert($quoteItem);
          $origOrderItemNew = $order->getItemByQuoteItemId($quoteItem->getId());

          if ($origOrderItemNew)

          $origOrderItemNew->addData($orderItem->getData());

          else

          if ($quoteItem->getParentItem())

          $orderItem->setParentItem($order->getItemByQuoteItemId($orderItem->getParentItem()->getId()));


          $order->addItem($orderItem);



          $order->setSubtotal($quote->getSubtotal())
          ->setBaseSubtotal($quote->getBaseSubtotal())
          ->setGrandTotal($quote->getGrandTotal())
          ->setBaseGrandTotal($quote->getBaseGrandTotal());

          $quote->save();
          $order->save();





          share|improve this answer















          You can update or edit the existing order by following



          $orderId = '21';
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();

          $quoteToOrder = $objectManager->create('MagentoQuoteModelQuoteItemToOrderItem');
          $order = $objectManager->create('MagentoSalesModelOrder')->load($orderId);
          $quote = $objectManager->create('MagentoQuoteModelQuote')->load($order->getQuoteId());


          Update the order quote.



          $items = $quote->getQuote()->getAllVisibleItems();

          foreach ($items as $quoteItem)

          $origOrderItem = $order->getItemByQuoteItemId($quoteItem->getId());
          $orderItemId = $origOrderItem->getItemId();

          //update quote item according your need
          $quoteItem->setWeight();
          $quoteItem->setQty();
          ....

          $quote->collectTotals();
          $quote->save();


          Update the order



          foreach ($items as $quoteItem) 

          $orderItem = $quoteToOrder->convert($quoteItem);
          $origOrderItemNew = $order->getItemByQuoteItemId($quoteItem->getId());

          if ($origOrderItemNew)

          $origOrderItemNew->addData($orderItem->getData());

          else

          if ($quoteItem->getParentItem())

          $orderItem->setParentItem($order->getItemByQuoteItemId($orderItem->getParentItem()->getId()));


          $order->addItem($orderItem);



          $order->setSubtotal($quote->getSubtotal())
          ->setBaseSubtotal($quote->getBaseSubtotal())
          ->setGrandTotal($quote->getGrandTotal())
          ->setBaseGrandTotal($quote->getBaseGrandTotal());

          $quote->save();
          $order->save();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jul 19 at 5:28

























          answered Jul 19 at 5:00









          user4536user4536

          3631 silver badge15 bronze badges




          3631 silver badge15 bronze badges















          • But the question is how to update order items......Not how to update (order)/(quote items)...

            – Ranganathan
            Jul 19 at 5:02












          • you can edit order item as well, look at "update quote item according your need"

            – user4536
            Jul 19 at 5:05












          • I've just referred this link here. But I'm not having a clear idea about the orderquote.

            – Ramya
            Jul 19 at 5:05












          • But you didn't declared the $items variable..What the items variable has?

            – Ranganathan
            Jul 19 at 5:07












          • You're right Ranganathan. That was my doubt while I'm referring that above link.

            – Ramya
            Jul 19 at 5:13

















          • But the question is how to update order items......Not how to update (order)/(quote items)...

            – Ranganathan
            Jul 19 at 5:02












          • you can edit order item as well, look at "update quote item according your need"

            – user4536
            Jul 19 at 5:05












          • I've just referred this link here. But I'm not having a clear idea about the orderquote.

            – Ramya
            Jul 19 at 5:05












          • But you didn't declared the $items variable..What the items variable has?

            – Ranganathan
            Jul 19 at 5:07












          • You're right Ranganathan. That was my doubt while I'm referring that above link.

            – Ramya
            Jul 19 at 5:13
















          But the question is how to update order items......Not how to update (order)/(quote items)...

          – Ranganathan
          Jul 19 at 5:02






          But the question is how to update order items......Not how to update (order)/(quote items)...

          – Ranganathan
          Jul 19 at 5:02














          you can edit order item as well, look at "update quote item according your need"

          – user4536
          Jul 19 at 5:05






          you can edit order item as well, look at "update quote item according your need"

          – user4536
          Jul 19 at 5:05














          I've just referred this link here. But I'm not having a clear idea about the orderquote.

          – Ramya
          Jul 19 at 5:05






          I've just referred this link here. But I'm not having a clear idea about the orderquote.

          – Ramya
          Jul 19 at 5:05














          But you didn't declared the $items variable..What the items variable has?

          – Ranganathan
          Jul 19 at 5:07






          But you didn't declared the $items variable..What the items variable has?

          – Ranganathan
          Jul 19 at 5:07














          You're right Ranganathan. That was my doubt while I'm referring that above link.

          – Ramya
          Jul 19 at 5:13





          You're right Ranganathan. That was my doubt while I'm referring that above link.

          – Ramya
          Jul 19 at 5:13

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282590%2fhow-to-edit-or-update-the-ordered-item-data-in-magento-2%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?