4

I have an order with processing status and its invoice is canceled.

When I use the order->canCancel() function, It returns me false. I checked the core and this is the part why I am getting false:

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

This is my custom code:

 foreach ($invoice->getAllItems() as $item) {
     echo '<pre>'; var_dump($item->getQty());
 }
 ...
 if ($orderObject->canCancel()){
 }

The result of the var_dump is 4 in my case. Then why the $item->getQtyToInvoice() returns me 0 or false ?

0

What do you mean by:

I have an order with processing status and its invoice is canceled.

Do you mean you have made a creditmemo? If not take this into consideration:

  • Orders can only be canceled when there has been no payment and thus an invoice (since you didn't got any payment you can just cancel an order without any obligations to the customer)
  • Orders with a payment and an invoice can only be "canceled" by a creditmemo (since you got a payment this should be refunded to the customer, and this is done by a creditmemo. Online or offline which doesn't matter)
| improve this answer | |

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.