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