Public Member Functions | |
collect (Mage_Sales_Model_Order_Invoice $invoice) |
Definition at line 28 of file Discount.php.
collect | ( | Mage_Sales_Model_Order_Invoice $ | invoice | ) |
Resolve rounding problems
Reimplemented from Mage_Sales_Model_Order_Invoice_Total_Abstract.
Definition at line 30 of file Discount.php.
00031 { 00032 $invoice->setDiscountAmount(0); 00033 $invoice->setBaseDiscountAmount(0); 00034 00035 $totalDiscountAmount = 0; 00036 $baseTotalDiscountAmount = 0; 00037 foreach ($invoice->getAllItems() as $item) { 00038 if ($item->getOrderItem()->isDummy()) { 00039 continue; 00040 } 00041 $orderItem = $item->getOrderItem(); 00042 $orderItemDiscount = (float) $orderItem->getDiscountAmount(); 00043 $baseOrderItemDiscount = (float) $orderItem->getBaseDiscountAmount(); 00044 $orderItemQty = $orderItem->getQtyOrdered(); 00045 00046 if ($orderItemDiscount && $orderItemQty) { 00047 /** 00048 * Resolve rounding problems 00049 */ 00050 if ($item->isLast()) { 00051 $discount = $orderItemDiscount - $orderItem->getDiscountInvoiced(); 00052 $baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced(); 00053 } 00054 else { 00055 $discount = $orderItemDiscount*$item->getQty()/$orderItemQty; 00056 $baseDiscount = $baseOrderItemDiscount*$item->getQty()/$orderItemQty; 00057 00058 $discount = $invoice->getStore()->roundPrice($discount); 00059 $baseDiscount = $invoice->getStore()->roundPrice($baseDiscount); 00060 } 00061 00062 $item->setDiscountAmount($discount); 00063 $item->setBaseDiscountAmount($baseDiscount); 00064 00065 $totalDiscountAmount += $discount; 00066 $baseTotalDiscountAmount += $baseDiscount; 00067 } 00068 } 00069 00070 $invoice->setDiscountAmount($totalDiscountAmount); 00071 $invoice->setBaseDiscountAmount($baseTotalDiscountAmount); 00072 00073 $invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount); 00074 $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount); 00075 return $this; 00076 }