00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Sales_Model_Order_Creditmemo_Total_Discount extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
00029 {
00030 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
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 }
00067 }