I want to cancel order item before invoice or shipment is generated. I added item cancellation feature and it cancels item from order. But when I try to generate invoice for the order, it captures the full amount including the cancelled item.
I am setting below details on order while cancelling an item
$order->setSubtotalCanceled($order->getSubtotal() - $order->getSubtotalInvoiced());
$order->setBaseSubtotalCanceled($order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced());
$order->setTaxCanceled($order->getTaxAmount() - $order->getTaxInvoiced());
$order->setBaseTaxCanceled($order->getBaseTaxAmount() - $order->getBaseTaxInvoiced());
$order->setShippingCanceled($order->getShippingAmount() - $order->getShippingInvoiced());
$order->setBaseShippingCanceled($order->getBaseShippingAmount() - $order->getBaseShippingInvoiced());
$order->setDiscountCanceled(abs($order->getDiscountAmount()) - $order->getDiscountInvoiced());
$order->setBaseDiscountCanceled(abs($order->getBaseDiscountAmount()) - $order->getBaseDiscountInvoiced());
$order->setTotalCanceled($order->getGrandTotal() - $order->getTotalPaid());
$order->setBaseTotalCanceled($order->getBaseGrandTotal() - $order->getBaseTotalPaid());
This does set the amount correctly at order table, but when I generate the invoice, it captures total amount of the order. I want to exclude the cancelled item from invoice and only capture the amount of pending items.