Magento partial refund creditmemo programatically
Suppose you have a product which is out of stock or something and you want to refund that product line item from order programatically. The below code will create creditmemo/refund for the products with certain SKU if it finds it in the line items of the order.
Mage::app('admin'); //You can create creditmemo in admin area only | |
//You should have $orderID as order increment ID and $sku as product SKU you want to refund for. | |
$order = Mage::getModel('sales/order')->loadByIncrementId($orderID); | |
$orderItem = $order->getItemsCollection()->getItemByColumnValue('sku', $sku); | |
$service = Mage::getModel('sales/service_order', $order); | |
$data = array( | |
'qtys' => array( | |
$orderItem->getId() => 1 //qty to refund.. $orderItem->getQty() | |
) | |
); | |
$creditMemo = $service->prepareCreditmemo($data)->save(); |
2 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress
apart from the coding help, your child is too cute.
it’s work but not proper code, it show that product is refunded but still show in ship product, and if i refund all items then still i can ship the order, in proper way it is not possible.
and also not show refund offline in comment.
i also try some other code but it still not work properly. can you please suggest anything for do it because i try googling but no any developer can do this…