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;
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
add a comment |
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
add a comment |
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
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
magento2 magento2.3 order-items
edited Jul 19 at 4:52
Ramya
asked Jul 19 at 4:44
RamyaRamya
208 bronze badges
208 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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();
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
|
show 4 more comments
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();
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 theitems
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
|
show 4 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
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
|
show 4 more comments
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();
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
|
show 4 more comments
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();
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();
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
|
show 4 more comments
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
|
show 4 more comments
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();
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 theitems
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
|
show 4 more comments
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();
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 theitems
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
|
show 4 more comments
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();
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();
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 theitems
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
|
show 4 more comments
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 theitems
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
|
show 4 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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