Magento 1.9 – How to Delete Product from Order

magento-1.9orderssales-order

Let as assume i got 1 order that order have 10 product's after that some reason i want to Delete or Cancel for particular product only i can keep 9 product . After Delete/cancel total also update based on product.

i want to UI wise if admin click delete button particular product only delete from that order

How i done this?

Best Answer

you can remove the product with sku. check this answer add this function into app\code\local\AR\Orderstatus\controllers\Adminhtml\IndexController.php

public function deleteproductAction()
{
    $order_id = $this->getRequest()->getParam('order_id');
    $product_id = $this->getRequest()->getParam('product_id');

     $_order = Mage::getModel('sales/order')->load($order_id);
        $items = $_order->getAllItems();
        foreach ($items as $item){
        $base_grand_total = $_order->getBaseGrandTotal();

        $base_subtotal = $_order->getBaseSubtotal();
        $base_tva = $_order->getBaseTaxAmount();

        $grand_total = $_order->getGrandTotal();

        $subtotal = $_order->getSubtotal();
        $tva = $_order->getTaxAmount();


        $base_subtotal_incl_tax = $_order->getBaseSubtotalInclTax();

        $subtotal_incl_tax = $_order->getSubtotalInclTax();

        $total_item_count = $_order->getTotalItemCount();



        if($item->getProductId()==$product_id){
            $item_price = $item->getPrice();
            $item_tva = $item->getTaxAmount();
            $item->delete();
            $_order->setBaseGrandTotal($base_grand_total-$item_price-$item_tva);

            $_order->setBaseSubtotal($base_subtotal-$item_price);

            $_order->setBaseTaxAmount($base_tva-$item_tva);

            $_order->setGrandTotal($grand_total-$item_price-$item_tva);

            $_order->setSubtotal($subtotal-$item_price);

            $_order->setTaxAmount($tva-$item_tva);


            $_order->setBaseSubtotalInclTax($base_subtotal_incl_tax-$item_price);

            $_order->setSubtotalInclTax($subtotal_incl_tax-$item_price);

            $_order->setTotalItemCount(count($items)-1);

            $_order->save(); 
        }

        }
Mage::getSingleton('adminhtml/session')
                           ->addSuccess('Order Updated Successfully');
        $this->_redirect('adminhtml/sales_order/view', array('order_id' => $_order->getId()));
    }
Related Topic