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 ) {
$val->setWeight(1)->save();
}
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 ) {
$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!!