I need to remove products from the order, after which, removed products can be added to the order
$backOrdersIds = array();
$this->getQuote()->getItemsCount();
foreach ($this->getQuote()->getAllItems() as $item) {
$oldQty = (int)$item->getProduct()->getStockItem()->getQty();
$qtyOrdered = (int)$item->getQty();
$differenceQty = $oldQty - $qtyOrdered;
//remove backorder items from Quote
Mage::log('first foreach' . $item->getProductId());
if($differenceQty < = 0 ){
$backOrdersIds[] = array(
'productId' => $item->getProductId(),
'qty' => $qtyOrdered
);
$this->getQuote()->removeItem($item->getId())->save();
}
}
//trying to add a remote item
foreach ($backOrdersIds as $ordersIds){
$product = Mage::getModel('catalog/product')->load($ordersIds['productId']);
Mage::log('order qty for product ' . $ordersIds['productId'] . 'qty=' .$ordersIds['qty']);
$this->getQuote()->addProduct($product, $ordersIds['qty'])->save();
Mage::log('product add to quote');
}
i have this error
The requested quantity for "product name" is not available.
How can I add the removed item to the order again?