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 = \Magento\Framework\App\ObjectManager::getInstance();
$orderItemId = '3';
$orderItem = $objectManager->create('\Magento\Sales\Api\OrderItemRepositoryInterface')->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 ) {

But the weight not gets updated.

Full Code:

$orderId = $_GET['id'];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Api\Data\OrderInterface')->load($orderId);

// Edit the order items data
foreach ($order->getAllItems() as $key => $value) {
    $orderItemId = $value->getData('item_id');
    $orderItem = $objectManager->create('\Magento\Sales\Api\OrderItemRepositoryInterface')->get($orderItemId);
    $orderItems = $orderItem->getData();
    foreach ( $orderItems as $val ) {

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!!

2 Answers 2


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

protected $_orderItems;

public function __construct(
    \Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory $orderItems
    $this->_orderItems = $orderItems;

public function execute()
    $orderItem = $this->_orderItems->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();

For testing purpose use

use \Magento\Framework\App\Bootstrap;
$bootstrapp = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrapp->getObjectManager();
$appState = $objectManager->get('\Magento\Framework\App\State');

$orderItem = $objectManager->get('\Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory')->create()->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
  • Thanks Ranganathan. Will try this method and let you know.
    – Ramya
    Jul 19, 2019 at 5:04
  • Can I use the order item collection factory via object manager. $orderItem = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory')->addFieldToFilter( 'item_id', $orderItemId )->getFirstItem();
    – Ramya
    Jul 19, 2019 at 5:14
  • Where do you want to implement this code? Jul 19, 2019 at 5:15
  • For my testing purpose, I'm writing the code on magento root folder
    – Ramya
    Jul 19, 2019 at 5:16
  • Yes you can use objectmanager here only...... Jul 19, 2019 at 5:17

You can update or edit the existing order by following

$orderId = '21';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$quoteToOrder = $objectManager->create('Magento\Quote\Model\Quote\Item\ToOrderItem');
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
$quote = $objectManager->create('\Magento\Quote\Model\Quote')->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 

Update the order

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

    if ($origOrderItemNew) 
        if ($quoteItem->getParentItem()) 



  • But the question is how to update order items......Not how to update (order)/(quote items)... Jul 19, 2019 at 5:02
  • you can edit order item as well, look at "update quote item according your need"
    – Hiren
    Jul 19, 2019 at 5:05
  • I've just referred this link here. But I'm not having a clear idea about the orderquote.
    – Ramya
    Jul 19, 2019 at 5:05
  • But you didn't declared the $items variable..What the items variable has? Jul 19, 2019 at 5:07
  • You're right Ranganathan. That was my doubt while I'm referring that above link.
    – Ramya
    Jul 19, 2019 at 5:13

Your Answer

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

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