How can I remove a quote item from an observer from adminpanel in Magento 1?
-
29-12-2020 - |
Question
I want to remove some items if I am pressing the reorder button from adminpanel.
I'm using this event: controller_action_postdispatch_adminhtml_sales_order_create_reorder
and this is my method from my observer:
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
foreach($quote->getAllItems() as $item) {
if ($item->getSku() === 'with smth') {
$quote->removeItem($item->getId());
}
}
$quote->collectTotals()->save();
I don't get any errors, and the item is not removed :) What am I doing wrong here ? :)
Thank you!
Solution
I managed to fix it by using the delete()
method:
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
foreach($quote->getAllItems() as $item) {
if (my condition here) {
$item->delete();
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange