I am working on script and want to know about how magento credit memo created. My requirement is same as magento after update quantities of product in order, hit update order button. Then enter custom shipping , custom Adjustment Refund , custom Adjustment Fee. How this work programatically.
2 Answers
Try this :
<?php require_once('app/Mage.php'); Mage::app('default'); class creditmemo { public function index() { $creditmemoData = array( 'qtys' => array('order_item_id' => 3, 'qty' => '1'), 'shipping_amount' => null, 'adjustment_positive' => '0', 'adjustment_negative' => null ); $comment= 'comment for credit memo'; $notifyCustomer = true; $includeComment = false; $refundToStoreCreditAmount= '1'; $order = Mage::getModel('sales/order')->load(101); //OR $order = Mage::getModel('sales/order')->loadByIncrementId('100001'); // Case : 1 partial credit memo /*$orderItem = $order->getItemsCollection()->getItemByColumnValue('sku', 'test-1'); $creditmemoData = array( 'qtys' => array( $orderItem->getId() => 1) );*/ // Case : 2 full credit memo // $creditmemoData = array(); /** @var $service Mage_Sales_Model_Service_Order */ $service = Mage::getModel('sales/service_order', $order); /** @var $creditmemo Mage_Sales_Model_Order_Creditmemo */ $creditmemo = $service->prepareCreditmemo($creditmemoData); $creditmemo->setPaymentRefundDisallowed(true)->register(); // add comment to creditmemo if (!empty($comment)) { $creditmemo->addComment($comment, $notifyCustomer); } try { Mage::getModel('core/resource_transaction') ->addObject($creditmemo) ->addObject($order) ->save(); // send email notification $creditmemo->sendEmail($notifyCustomer, ($includeComment ? $comment : '')); } catch (Mage_Core_Exception $e) { $e->getMessage(); } return $creditmemo->getIncrementId(); } } $obj = new creditmemo(); $obj->index(); ?> - Where is values for other required values. Updated quantity , shipping , Adjustment Refund and Adjustment Fee.Mathew– Mathew2015-12-10 06:31:16 +00:00Commented Dec 10, 2015 at 6:31
- You used "creditmemoData" but it is not present in example.Mathew– Mathew2015-12-10 06:32:14 +00:00Commented Dec 10, 2015 at 6:32
-
- It is not display in order section with Shipped functionality and also Adjustment Refund and Adjustment Fee not applied only shipping is done.Mathew– Mathew2015-12-10 07:09:27 +00:00Commented Dec 10, 2015 at 7:09
If you do not need to play with online refund try this
$order = Mage::getModel('sales/order')->load($entity_id); $orderCreditApi = Mage::getModel('sales/order_creditmemo_api'); $result = $orderCreditApi->create($order->getData('increment_id'));