I know this has been asked before but can't find an answer yet.

Our payment provider supports partial refund so that is not an issue.

We created bundled products to sell sets of items. In this is also the option to add extra.

-Require 5 items (choose option for each 5)
-Add extra items at same price (optional)
-Backend: Dynamic pricing / ship seperate

-Client orders 5 items + 3 extra's
-Client wants to return one of the extra ordered items (too many)
-Creating a credit memo tries to refund the whole bundled set

Is there a way to set this up different/better so that I can refund child items?

Not working: Grouped product
-Can't make items mandatory / QTY or set adjusted price

Not working: Adjustment fee
-Doesn't recalculate the tax amount
-Still credits the whole bundle, so another extra bought too much can't be credited or replaced afterwards

1 Answer 1


This might help you:

  /* Credit Memo and Partial refund item wise   -- START    @Ahsan Horani */
        $item_id        = $_POST['itemid'];
        $orderId        = $_POST['orderid'];
        $itemsku        = $_POST['itemsku'];
        $refundQty  = $_POST['refund_qty'];     //Get item's Qty to be refunded @Ahsan Horani

        $order = Mage::getModel('sales/order')->load($orderId, 'increment_id');

        //Initialize arrays
        $data = array();        
        $qtys     = array();

        //Set qty of items to be refunded
        foreach($order->getAllVisibleItems() as $rItem)
            if($rItem->getId() == $item_id)
                $qtys[$rItem->getId()]      = array("qty"=> $refundQty);    //Set item's qty to be refunded @Ahsan Horani
                // $qtysArray[$rItem->getId()] = $rItem->getQtyOrdered();
                $qtysArray[$rItem->getId()] = $refundQty;
            {   //Set qty=0 for items not to be refunded
                $qtys[$rItem->getId()]      = array("qty"=> '0');
                $qtysArray[$rItem->getId()] = '0';

        //Prepare array for Credit Memo
        $data = array
                        'items' => $qtys,
                        'do_offline' => '1',
                        'comment_text' => '',
                        'shipping_amount' => '0',
                        'adjustment_positive' => '0',
                        'adjustment_negative' => '0',

        $data['qtys']   =   $qtysArray;

        $service = Mage::getModel('sales/service_order', $order);

        $creditmemo = $service->prepareCreditmemo($data);       //Create Credit Memo
         echo "Credit memo created<br>";
        $creditmemo->setRefundRequested(true);                      //Enable Refund 
         echo "Refund requested<br>";
        $creditmemo->setOfflineRequested(true);                     //Enable Offline Refund
         echo "Offline requested<br>";
        $creditmemo->register();                                                    //Register Credit Memo
         echo "Registered<br>";

        //Save transaction for Credit Memo
        $transactionSave = Mage::getModel('core/resource_transaction')
         echo "Transaction Saved<br>";

        // Send email notification
        // $creditmemo->sendEmail(true, ($includeComment ? $comment : ''));

        /* Credit Memo and Partial refund item wise -- END  @Ahsan Horani */
  • This is tested code for creating partial Credit Memo programmatically. Feb 9, 2016 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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