1

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?

3 Answers 3

2

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()));
    }
23
  • Check my updated question
    – Magento 2
    Dec 11, 2015 at 6:22
  • do you have any module because you have to add controller for that.. Dec 11, 2015 at 6:40
  • No module on that
    – Magento 2
    Dec 11, 2015 at 6:41
  • did you add the delete button on product? if you added kindly add the code Dec 11, 2015 at 6:42
  • No i didn't add i don't know where to add that so that
    – Magento 2
    Dec 11, 2015 at 6:44
0

Sales > Orders > Select the Order

Select "Credit Memo" at the top, and insert the "Qty to refund" and then press Update Qty.

Once complete press the "Issue refund offline"

That will remove the product from the order.

Or are you asking how to do this without the customer knowing?

1
  • In your case first generate invoice after create credit memo for the particular product qty
    – Abdul
    Dec 11, 2015 at 5:52
0

Try this

<?php
require_once('app/Mage.php');
Mage::app('default');

class AR
{
    public function index()    
    {
        $orderId = 100;
        $order =  Mage::getModel('sales/order')->load($orderId);
        $items = $order->getAllItems();
        $removeProductSku = 'test';
        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->getSku()==$removeProductSku){
                $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();
                break; 
            }
        }

}
$obj = new AR();
$obj->index();
?>

Note : first tried in demo server if working fine after use in live server

3
  • Actually i want to UI wise if admin click delete button particular product only delete from that order
    – Magento 2
    Dec 11, 2015 at 6:12
  • Pls update your qus
    – Abdul
    Dec 11, 2015 at 6:20
  • Check my updated question
    – Magento 2
    Dec 11, 2015 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.