I know one can call $order->cancel() to easily cancel an order, but it calls registerCancellation() which in turns calls the internal _setState() itself.

The internal _setState() function will add a state change history all on its own, provided with no way to customize it.

If I want that status changing history contains my own comments, or even notify customers, how can I do that?


This should do the trick:

if ($order->canCancel()) {
    try {

        // remove status history set in _setState

        // do some more stuff here
        // ...

    } catch (Exception $e) {
  • $order->getHistoryStatusCollection()->getLastItem()->delete()->save(); is exactly how I did this. Added that rewriting the whole order model would be the perfect solution, but I just don't bother. – Vicary Jan 20 '15 at 12:10
  • Does it also reset the coupon code applied to it. If not then how to do it any idea – insoftservice Mar 6 at 22:33

Can you try this ?

$order->setData('state', "cancel");
    $history = $order->addStatusHistoryComment('Order marked as cancelled.', false);
  • AFAIK an order must call registerCancellation() to properly set prices, problem is that it contains a non-customizable _setState() call inside. – Vicary Jan 20 '15 at 6:53

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.