5

I have created a custom payment gateway module. Everything works fine, except canceling the order from the backend.

The error: The order(s) cannot be canceled

Any ideas?

1
  • Have you checked the logs for exceptions and errors. It would seem it is throwing an exception (and not showing you the error back to you) Commented May 8, 2014 at 17:11

1 Answer 1

4

If you look into the function canCancel under Mage_Sales_Model_Order then you can see what in what situations an order can or cannot be cancelled.

The following need to be true before an order can be cancelled.

  1. If the payment can be voided,
  2. If you cannot unhold the order,
  3. If all items have have not been invoiced,
  4. If the order is not cancelled, complete or closed,
  5. Or if the order has not already been flagged to be cancelled,

The full code is as follows.

/**
 * Retrieve order cancel availability
 *
 * @return bool
 */
public function canCancel()
{
    if (!$this->_canVoidOrder()) {
        return false;
    }
    if ($this->canUnhold()) {  // $this->isPaymentReview()
        return false;
    }

    $allInvoiced = true;
    foreach ($this->getAllItems() as $item) {
        if ($item->getQtyToInvoice()) {
            $allInvoiced = false;
            break;
        }
    }
    if ($allInvoiced) {
        return false;
    }

    $state = $this->getState();
    if ($this->isCanceled() || $state === self::STATE_COMPLETE || $state === self::STATE_CLOSED) {
        return false;
    }

    if ($this->getActionFlag(self::ACTION_FLAG_CANCEL) === false) {
        return false;
    }
    /**
     * Use only state for availability detect
     */
    /*foreach ($this->getAllItems() as $item) {
        if ($item->getQtyToCancel()>0) {
            return true;
        }
    }
    return false;*/
    return true;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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