2

Currently I am using the code below to refund a full order and create the creditmemo..

        $order = Mage::getModel('sales/order')->loadByIncrementId('100091904');
        $invoices = array();
        foreach ($order->getInvoiceCollection() as $invoice) {
            if ($invoice->canRefund()) {
                $invoices[] = $invoice;
            }
        }

        $service = Mage::getModel('sales/service_order', $order);
        foreach ($invoices as $invoice) {
            $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
            $creditmemo->refund();
        }

But the problem is that the customer paid online with SagePay, this current method ONLY refunds this offline and as you can see this could be a very big problem, anyone got any ways to get around this? Would be much appreciated. Using Magento Enterprise ver. 1.12.0.2

I've not found anything on this before this purely REFUNDING online.

  • 1
    If the extension provider didn't implement it, it is either not possible or it is not yet done. Ask the extention provider. – Fabian Blechschmidt Dec 9 '13 at 15:03
  • It works doing it manually in Magento, but if I refund the full order it goes offline, I have to go to refund individually each invoice, thus why I thought this would work. – Aimson Dec 9 '13 at 15:50
  • Ah ok, yes then you make something wrong... Don'T ask me what :D – Fabian Blechschmidt Dec 9 '13 at 15:54
  • Yup ha, just wondering where.. Any Idea? damn.. ha – Aimson Dec 9 '13 at 15:55
  • Will create it offline because its converting the order into a credit memo, which creates offline order even on Magento.. Don't see why they would want to do that... I found this but link the link to the API is dud. – Aimson Dec 9 '13 at 16:01
0

I can't follow your last comment.

The question I referenced had this answer, there is more:

$order = Mage::getModel('sales/order')->loadByIncrementId('1117575');
$orderItem = $order->getItemsCollection()->getItemByColumnValue('sku', '100-0055-BRO-S');
$service = Mage::getModel('sales/service_order', $order);
$data = array(
    'qtys' => array(
        $orderItem->getId() => 1
    )
);
$creditMemo = $service->prepareCreditmemo($data)->save();
|improve this answer|||||
  • This will just create an offline refund on the Order, I believe it needs to be done on the Invoice. – Aimson Dec 9 '13 at 16:24
  • Try $service->prepareInvoiceCreditmemo() – Fabian Blechschmidt Dec 9 '13 at 16:54
  • Thats what I'm using currently, unsure why it wouldn't work. Surely more people have this problem. – Aimson Dec 9 '13 at 17:01

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