I need a function which is order cancel based on the item. Current scenario is that Magento does cancel whole order.
What I want:
A customer placed 2 ordered items. And after placed order, customer wants to cancel 1 item,so in this situation which parameter I should consider and which approach I have to go ?
I found some below code in Magento core files,if someone check and give me some hint about cancel order item rather than whole order,it will be appreciated.
app\code\core\Mage\Sales\Model\Order.php
public function registerCancellation($comment = '', $graceful = true)
{
if ($this->canCancel() || $this->isPaymentReview()) {
$cancelState = self::STATE_CANCELED;
foreach ($this->getAllItems() as $item) {
if ($cancelState != self::STATE_PROCESSING && $item->getQtyToRefund()) {
if ($item->getQtyToShip() > $item->getQtyToCancel()) {
$cancelState = self::STATE_PROCESSING;
} else {
$cancelState = self::STATE_COMPLETE;
}
}
$item->cancel();
}
$this->setSubtotalCanceled($this->getSubtotal() - $this->getSubtotalInvoiced());
$this->setBaseSubtotalCanceled($this->getBaseSubtotal() - $this->getBaseSubtotalInvoiced());
$this->setTaxCanceled($this->getTaxAmount() - $this->getTaxInvoiced());
$this->setBaseTaxCanceled($this->getBaseTaxAmount() - $this->getBaseTaxInvoiced());
$this->setShippingCanceled($this->getShippingAmount() - $this->getShippingInvoiced());
$this->setBaseShippingCanceled($this->getBaseShippingAmount() - $this->getBaseShippingInvoiced());
$this->setDiscountCanceled(abs($this->getDiscountAmount()) - $this->getDiscountInvoiced());
$this->setBaseDiscountCanceled(abs($this->getBaseDiscountAmount()) - $this->getBaseDiscountInvoiced());
$this->setTotalCanceled($this->getGrandTotal() - $this->getTotalPaid());
$this->setBaseTotalCanceled($this->getBaseGrandTotal() - $this->getBaseTotalPaid());
$this->_setState($cancelState, true, $comment);
} elseif (!$graceful) {
Mage::throwException(Mage::helper('sales')->__('Order does not allow to be canceled.'));
}
return $this;
}