1

I have the following observer method thats been called successfully, but the order status is not changing.

public function customCancel(Varien_Event_Observer $observer) {

        $order = $observer->getEvent()->getPayment()->getOrder();
        $order = Mage::getModel('sales/order')->load($order->getId());
        $payment_code = $observer->getEvent()->getPayment()->getMethodInstance()->getCode();
        if ($payment_code == 'cashondelivery') {
            $order->setStatus("cod_cancel");
            $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Cancel Transaction.');
            Mage::log($payment_code, null, 'paymentMethod.log');
            $order->save();
        }
    }

I have implemented the following event.

sales_order_payment_cancel

  • Please add the magento-1 tag here – stephen May 23 '17 at 7:41
1

There's a lot more going on canceling an order than just simply set its state to canceled. Please try following code sections inside your if-block instead and see if at least one of them gets you there:

$order->registerCancellation('Cancel Transaction.', false);

false will throw an exception if the order is not subject to cancelation.

If this doesn't work for you, try

$order->cancel();

This one might cause trouble since it cancels the payment, too, to which your observer is listening so you might create an infinite loop. Maybe there's an event better suited for your situation.

| improve this answer | |
  • Not working either of these options – Magento Learner Nov 21 '16 at 6:59

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.