public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     if (Mage::getStoreConfig('tax/calculation/price_includes_tax') != 1) {
         $tax = $address->getTaxAmount();
     }
     if ($paymentMethod) {
         $amount1 = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
         $amount = Mage::helper('directory')->currencyConvert($amount1, Mage::app()->getWebsite()->getConfig('currency/options/default'), Mage::app()->getStore()->getCurrentCurrencyCode());
         //			if(Mage::getStoreConfig('payment/paypal_payment_solutions/charge_type')!="percentage"){
         $address->setPaymentCharge($amount);
         $address->setBasePaymentCharge($amount1);
         /*			} else {
         					$address->setPaymentCharge($amount);
         				   
         					$subTotal = $address->getBaseSubtotal();	
         					$amount12 = ($subTotal+ $tax) * floatval(Mage::getStoreConfig('payment/paypal_payment_solutions/charge_value')) / 100;
         					$address->setBasePaymentCharge($amount12);
         			}*/
     }
     $address->setGrandTotal($address->getGrandTotal() + $tax + $address->getPaymentCharge());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $_helper = Mage::helper('webpos');
     $active = $_helper->enableGiftWrap();
     if (!$active) {
         return;
     }
     $session = Mage::getSingleton('checkout/session');
     $giftwrap = $session->getData('webpos_giftwrap');
     if (!$giftwrap) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $giftwrapType = $_helper->getGiftwrapType();
     $giftwrapAmount = $_helper->getGiftwrapAmount();
     $wrapTotal = 0;
     if ($giftwrapType == 1) {
         foreach ($items as $item) {
             if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                 continue;
             }
             $wrapTotal += $giftwrapAmount * $item->getQty();
         }
     } else {
         $wrapTotal = $giftwrapAmount;
     }
     $session->setData('webpos_giftwrap_amount', $wrapTotal);
     $address->setWebposGiftwrapAmount($wrapTotal);
     $address->setGrandTotal($address->getGrandTotal() + $address->getWebposGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getWebposGiftwrapAmount());
     return $this;
 }
Esempio n. 3
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $totalWeeeTax = 0;
     $baseTotalWeeeTax = 0;
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     foreach ($items as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         $this->_resetItemData($item);
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $this->_resetItemData($child);
                 $this->_processItem($address, $child, true);
                 $totalWeeeTax += $child->getWeeeTaxAppliedRowAmount();
                 $baseTotalWeeeTax += $child->getBaseWeeeTaxAppliedRowAmount();
             }
         } else {
             $this->_processItem($address, $item);
             $totalWeeeTax += $item->getWeeeTaxAppliedRowAmount();
             $baseTotalWeeeTax += $item->getBaseWeeeTaxAppliedRowAmount();
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $totalWeeeTax);
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $baseTotalWeeeTax);
     return $this;
 }
 /**
  * Determine if the addres is a valid ship group.
  *
  * @return bool
  */
 protected function _validateAddressIsShipGroup()
 {
     // This assume that the address is in a valid state to be
     // included and does not check for individual data constraints
     // to be met.
     return (bool) count($this->_address->getAllItems());
 }
Esempio n. 5
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $active = Mage::helper('giftwrap')->enableGiftwrap();
     if (!$active) {
         return;
     }
     if (Mage::app()->getStore()->isAdmin()) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address_id = $address->getId();
     /*
      * 	update of version 0.2.2
      */
     $giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount(null, $address_id);
     $address->setGiftwrapAmount($giftwrapAmount);
     $address->setBaseGiftwrapAmount(0);
     //var_dump($address->getData());die();
     // if($giftwrapAmount>0){
     // $taxAmount = 10;
     // $address->setTaxAmount($address->getTaxAmount() + $taxAmount);
     // $address->setBaseTaxAmount($address->getBaseTaxAmount() + $taxAmount);
     // }
     Mage::getModel('core/session')->setData('giftwrap_amount', $giftwrapAmount);
     $address->setGrandTotal($address->getGrandTotal() + $address->getGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getGiftwrapAmount());
     //var_dump($address->getData());die();
     return $this;
 }
Esempio n. 6
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     foreach ($address->getAllItems() as $item) {
         Mage::getSingleton('rewards/redeem')->refactorRedemptions($item, false);
     }
     return parent::collect($address);
 }
 /**
  * Collect address subtotal
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Sales_Model_Quote_Address_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     /**
      * Reset subtotal information
      */
     $address->setSubtotal(0);
     $address->setBaseSubtotal(0);
     $address->setTotalQty(0);
     $address->setBaseTotalPriceIncTax(0);
     /**
      * Process address items
      */
     $items = $address->getAllItems();
     foreach ($items as $item) {
         if (!$this->_initItem($address, $item) || $item->getQty() <= 0) {
             $this->_removeItem($address, $item);
         }
     }
     /**
      * Initialize grand totals
      */
     $address->setGrandTotal($address->getSubtotal());
     $address->setBaseGrandTotal($address->getBaseSubtotal());
     AO::helper('sales')->checkQuoteAmount($address->getQuote(), $address->getSubtotal());
     AO::helper('sales')->checkQuoteAmount($address->getQuote(), $address->getBaseSubtotal());
     return $this;
 }
 /**
  * Get the address item the item payload represents.
  *
  * @param ITaxedOrderItem
  * @return Mage_Sales_Model_Quote_Address_Item|null
  */
 protected function _getItemForItemPayload(ITaxedOrderItem $itemPayload)
 {
     foreach ($this->_address->getAllItems() as $item) {
         if ($item->getId() === $itemPayload->getLineNumber()) {
             return $item;
         }
     }
     return null;
 }
Esempio n. 9
0
 /**
  * Collect the Buckaroo fee for the given address.
  *
  * @param Mage_Sales_Model_Quote_Address $address
  *
  * @return $this
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     /**
      * We can only add the fee to the shipping address.
      */
     if ($address->getAddressType() != 'shipping') {
         return $this;
     }
     $quote = $address->getQuote();
     $store = $quote->getStore();
     if (!$quote->getId()) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     /**
      * First, reset the fee amounts to 0 for this address and the quote.
      */
     $address->setBuckarooFee(0)->setBaseBuckarooFee(0);
     $quote->setBuckarooFee(0)->setBaseBuckarooFee(0);
     /**
      * Check if the order was placed using Buckaroo
      */
     $paymentMethod = $quote->getPayment()->getMethod();
     if (strpos($paymentMethod, 'buckaroo') === false) {
         return $this;
     }
     /**
      * Get the fee amount.
      */
     $baseFee = $this->_getPaymentFee($quote, $paymentMethod);
     if ($baseFee <= 0) {
         return $this;
     }
     /**
      * Convert the fee to the base fee amount.
      */
     $fee = $store->convertPrice($baseFee);
     /**
      * Set the fee for the address and quote.
      */
     $address->setBuckarooFee($fee)->setBaseBuckarooFee($baseFee);
     $quote->setBuckarooFee($fee)->setBaseBuckarooFee($baseFee);
     /**
      * Update the address' grand total amounts.
      */
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $baseFee);
     $address->setGrandTotal($address->getGrandTotal() + $fee);
     return $this;
 }
Esempio n. 10
0
 /**
  * Calculate address total tax based on address subtotal
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _totalBaseCalculation(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $items = $address->getAllItems();
     $store = $address->getQuote()->getStore();
     $taxGroups = array();
     $inclTax = false;
     foreach ($items as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId());
                 $rate = $this->_calculator->getRate($taxRateRequest);
                 $taxGroups[(string) $rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest);
                 $this->_aggregateTaxPerRate($child, $rate, $taxGroups);
                 $this->_getAddress()->addTotalAmount('hidden_tax', $child->getHiddenTaxAmount());
                 $this->_getAddress()->addBaseTotalAmount('hidden_tax', $child->getBaseHiddenTaxAmount());
                 $inclTax = $child->getIsPriceInclTax();
             }
             $this->_recalculateParent($item);
         } else {
             $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId());
             $rate = $this->_calculator->getRate($taxRateRequest);
             $taxGroups[(string) $rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest);
             $this->_aggregateTaxPerRate($item, $rate, $taxGroups);
             $this->_getAddress()->addTotalAmount('hidden_tax', $item->getHiddenTaxAmount());
             $this->_getAddress()->addBaseTotalAmount('hidden_tax', $item->getBaseHiddenTaxAmount());
             $inclTax = $item->getIsPriceInclTax();
         }
     }
     foreach ($taxGroups as $rateKey => $data) {
         $rate = (double) $rateKey;
         $totalTax = $this->_calculator->calcTaxAmount(array_sum($data['totals']), $rate, $inclTax);
         $baseTotalTax = $this->_calculator->calcTaxAmount(array_sum($data['base_totals']), $rate, $inclTax);
         $totalRewardPointDiscount = $baseTotalRewardPointDiscount = Mage::getSingleton('checkout/session')->getCredit();
         $totalRewardPointDiscount = $this->_calculator->calcTaxAmount($totalRewardPointDiscount, $rate, $inclTax);
         $baseTotalRewardPointDiscount = $this->_calculator->calcTaxAmount($baseTotalRewardPointDiscount, $rate, $inclTax);
         if ($totalRewardPointDiscount > $totalTax) {
             $totalRewardPointDiscount = $totalTax;
         }
         if ($baseTotalRewardPointDiscount > $baseTotalTax) {
             $baseTotalRewardPointDiscount = $baseTotalTax;
         }
         $this->_addAmount($totalTax - $totalRewardPointDiscount);
         $this->_addBaseAmount($baseTotalTax - $baseTotalRewardPointDiscount);
         $this->_saveAppliedTaxes($address, $data['applied_rates'], $totalTax, $baseTotalTax, $rate);
     }
     return $this;
 }
Esempio n. 11
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $storeId = Mage::app()->getStore()->getId();
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     $quote = $address->getQuote();
     if ($paymentMethod && substr($paymentMethod, 0, 11) == 'pay_payment') {
         $baseAmount = Mage::helper('pay_payment')->getPaymentCharge($paymentMethod, $address->getQuote());
         $amount = Mage::helper('directory')->currencyConvert($baseAmount, Mage::app()->getWebsite()->getConfig('currency/options/default'), Mage::app()->getStore()->getCurrentCurrencyCode());
         $address->setPaymentCharge($amount);
         $address->setBasePaymentCharge($baseAmount);
         $taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
         $taxCalculationModel = Mage::getSingleton('tax/calculation');
         $request = $taxCalculationModel->getRateRequest($quote->getShippingAddress(), $quote->getBillingAddress(), null, $storeId);
         $request->setStore(Mage::app()->getStore());
         $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
         //$rate = 21;
         if ($rate > 0) {
             //                $includesTax = Mage::getStoreConfig('tax/calculation/price_includes_tax');
             $baseChargeTax = round($address->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
             $chargeTax = round($address->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
         } else {
             $baseChargeTax = 0;
             $chargeTax = 0;
         }
         $rates = array();
         $applied = false;
         foreach ($address->getAppliedTaxes() as $arrRate) {
             // maximaal 1 keer de btw voor de extra kosten toevoegen
             if ($arrRate['percent'] == $rate && !$applied) {
                 $applied = true;
                 $arrRate['amount'] = $arrRate['amount'] + $chargeTax;
                 $arrRate['base_amount'] = $arrRate['base_amount'] + $baseChargeTax;
             }
             $rates[] = $arrRate;
         }
         $address->setAppliedTaxes($rates);
         $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseChargeTax);
         $address->setTaxAmount($address->getTaxAmount() + $chargeTax);
         $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     }
     return $this;
 }
Esempio n. 12
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $_helper = Mage::helper('onestepcheckout');
     $active = $_helper->enableGiftWrap();
     if (!$active) {
         return;
     }
     $session = Mage::getSingleton('checkout/session');
     $giftwrap = $session->getData('onestepcheckout_giftwrap');
     if (!$giftwrap) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $giftwrapType = $_helper->getGiftwrapType();
     $giftwrapAmount = $_helper->getGiftwrapAmount();
     $wrapTotal = 0;
     if ($giftwrapType == 1) {
         foreach ($items as $item) {
             if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
                 continue;
             }
             // if ($item->getHasChildren() && $item->isShipSeparately()) {
             // foreach ($item->getChildren() as $child) {
             // if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
             // $freeBoxes += $item->getQty() * $child->getQty();
             // }
             // elseif ($item->getFreeShipping()) {
             // $freeBoxes += $item->getQty();
             // }
             // }
             // }
             $wrapTotal += $giftwrapAmount * $item->getQty();
         }
     } else {
         $wrapTotal = $giftwrapAmount;
     }
     //        var_dump($wrapTotal);
     //		$giftwrapAmount = Mage::helper('giftwrap')->giftwrapAmount(null,$address_id);
     $session->setData('onestepcheckout_giftwrap_amount', $wrapTotal);
     $address->setOnestepcheckoutGiftwrapAmount($wrapTotal);
     $address->setGrandTotal($address->getGrandTotal() + $address->getOnestepcheckoutGiftwrapAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getOnestepcheckoutGiftwrapAmount());
     return $this;
 }
Esempio n. 13
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
     $paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
     if ($paymentMethod != 'cashondelivery' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if ($paymentMethod->getCode() != 'cashondelivery') {
         return $this;
     }
     $store = $address->getQuote()->getStore();
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
     $taxCalculationModel = Mage::getSingleton('tax/calculation');
     /* @var $taxCalculationModel Mage_Tax_Model_Calculation */
     $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
     $codTaxClass = Mage::helper('cashondelivery')->getCodTaxClass($store);
     $codTax = 0;
     $codBaseTax = 0;
     if ($codTaxClass) {
         if ($rate = $taxCalculationModel->getRate($request->setProductClassId($codTaxClass))) {
             if (!Mage::helper('cashondelivery')->codPriceIncludesTax()) {
                 $codTax = $address->getCodFee() * $rate / 100;
                 $codBaseTax = $address->getBaseCodFee() * $rate / 100;
             } else {
                 $codTax = $address->getCodTaxAmount();
                 $codBaseTax = $address->getBaseCodTaxAmount();
             }
             $codTax = $store->roundPrice($codTax);
             $codBaseTax = $store->roundPrice($codBaseTax);
             $address->setTaxAmount($address->getTaxAmount() + $codTax);
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $codBaseTax);
             $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $codTax, $codBaseTax, $rate);
         }
     }
     if (!Mage::helper('cashondelivery')->codPriceIncludesTax()) {
         $address->setCodTaxAmount($codTax);
         $address->setBaseCodTaxAmount($codBaseTax);
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getCodTaxAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseCodTaxAmount());
     return $this;
 }
Esempio n. 14
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     //parent::collect($address);
     $collection = $address->getQuote()->getPaymentsCollection();
     if ($collection->count() <= 0 || $address->getQuote()->getPayment()->getMethod() == null) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if ($paymentMethod->getCode() != 'billmateinvoice') {
         return $this;
     }
     $store = $address->getQuote()->getStore();
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
     $taxCalculationModel = Mage::getSingleton('tax/calculation');
     /* @var $taxCalculationModel Mage_Tax_Model_Calculation */
     $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
     $InvoiceTaxClass = Mage::helper('billmateinvoice')->getInvoiceTaxClass($store);
     $InvoiceTax = 0;
     $InvoiceBaseTax = 0;
     if ($InvoiceTaxClass) {
         if ($rate = $taxCalculationModel->getRate($request->setProductClassId($InvoiceTaxClass))) {
             if (!Mage::helper('billmateinvoice')->InvoicePriceIncludesTax()) {
                 $InvoiceTax = $address->getFeeAmount() * $rate / 100;
                 $InvoiceBaseTax = $address->getBaseFeeAmount() * $rate / 100;
             } else {
                 $InvoiceTax = $address->getPaymentTaxAmount();
                 $InvoiceBaseTax = $address->getBasePaymentTaxAmount();
             }
             $InvoiceTax = $store->roundPrice($InvoiceTax);
             $InvoiceBaseTax = $store->roundPrice($InvoiceBaseTax);
             $address->setTaxAmount($address->getTaxAmount() + $InvoiceTax);
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $InvoiceBaseTax);
             $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $InvoiceTax, $InvoiceBaseTax, $rate);
         }
     }
     if (!Mage::helper('billmateinvoice')->InvoicePriceIncludesTax()) {
         $address->setInvoiceTaxAmount($InvoiceTax);
         $address->setBaseInvoiceTaxAmount($InvoiceBaseTax);
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentTaxAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentTaxAmount());
     return $this;
 }
Esempio n. 15
0
 /**
  * Collect address subtotal
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Sales_Model_Quote_Address_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setSubtotal(0);
     $address->setBaseSubtotal(0);
     $address->setTotalQty(0);
     $items = $address->getAllItems();
     if (count($items)) {
         foreach ($items as $item) {
             if (!$this->_initItem($address, $item) || $item->getQty() <= 0) {
                 $this->_removeItem($address, $item);
             }
         }
     }
     $address->setGrandTotal($address->getSubtotal());
     $address->setBaseGrandTotal($address->getBaseSubtotal());
     return $this;
 }
Esempio n. 16
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
     $paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
     if (!in_array($paymentMethod, self::$_allowed_methods) && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if (!in_array($paymentMethod->getCode(), self::$_allowed_methods)) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address->setBasePayexPaymentFee(0);
     $address->setBasePayexPaymentFeeTax(0);
     $address->setPayexPaymentFee(0);
     $address->setPayexPaymentFeeTax(0);
     // Get totals
     $address1 = clone $address;
     foreach ($address1->getTotalCollector()->getCollectors() as $model) {
         if ($model->getCode() !== $this->getCode()) {
             $model->collect($address1);
         }
     }
     // Address is the reference for grand total
     // Calculated total is $address1->getGrandTotal()
     $price = (double) $paymentMethod->getConfigData('paymentfee');
     $tax_class = $paymentMethod->getConfigData('paymentfee_tax_class');
     if (!$price) {
         return $this;
     }
     // Get Payment Fee
     $fee = Mage::helper('payex/fee')->getPaymentFeePrice($price, $tax_class);
     $baseTotal = $address->getBaseGrandTotal();
     $baseTotal += $fee->getPaymentFeePrice() + $fee->getPaymentFeeTax();
     $address->setBasePayexPaymentFee($fee->getPaymentFeePrice());
     $address->setBasePayexPaymentFeeTax($fee->getPaymentFeeTax());
     $address->setPayexPaymentFee($address->getQuote()->getStore()->convertPrice($fee->getPaymentFeePrice(), false));
     $address->setPayexPaymentFeeTax($address->getQuote()->getStore()->convertPrice($fee->getPaymentFeeTax(), false));
     // update totals
     $address->setBaseGrandTotal($baseTotal);
     $address->setGrandTotal($address->getQuote()->getStore()->convertPrice($baseTotal, false));
     return $this;
 }
Esempio n. 17
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $session = Mage::getSingleton('checkout/session');
     $discount = $session->getData('onestepcheckout_admin_discount');
     if (!$discount) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $session->setData('onestepcheckout_admin_discount', $discount);
     $address->setOnestepcheckoutDiscountAmount($discount);
     $address->setData('onestepcheckout_discount_amount', $discount);
     $address->setGrandTotal($address->getGrandTotal() - $address->getOnestepcheckoutDiscountAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getOnestepcheckoutDiscountAmount());
     return $this;
 }
Esempio n. 18
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $credit = Mage::helper('credit')->exchangeCreditToMoney(Mage::getSingleton('checkout/session')->getCredit());
     $subtotalWithDiscount = 0;
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address->setCreditDiscount($credit);
     $address->setSubtotalWithDiscount($subtotalWithDiscount - $credit);
     $address->setBaseCreditDiscount($credit);
     $address->setBaseSubtotalWithDiscount($subtotalWithDiscount - $credit);
     $address->setGrandTotal($address->getGrandTotal() - $address->getCreditDiscount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseCreditDiscount());
     $address->setBaseDiscountAmount($address->getBaseDiscountAmount() - $address->getBaseCreditDiscount());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setPaymentCharge(0);
     $address->setBasePaymentCharge(0);
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     if ($paymentMethod) {
         $amount = Mage::helper('paymentcharge')->getPaymentCharge($paymentMethod, $address->getQuote());
         $address->setPaymentCharge($amount['amount']);
         $address->setBasePaymentCharge($amount['base_amount']);
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentCharge());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentCharge());
     return $this;
 }
Esempio n. 20
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $oldWeight = $address->getWeight();
     $address->setWeight(0);
     $address->setShippingAmount(0);
     $method = $address->getShippingMethod();
     $freeAddress = $address->getFreeShipping();
     $address->setFreeMethodWeight(0);
     foreach ($address->getAllItems() as $item) {
         $item->calcRowWeight();
         $address->setWeight($address->getWeight() + $item->getRowWeight());
         if ($freeAddress || $item->getFreeShipping() === true) {
             $item->setRowWeight(0);
         } elseif (is_numeric($item->getFreeShipping())) {
             $origQty = $item->getQty();
             if ($origQty > $item->getFreeShipping()) {
                 $item->setQty($origQty - $item->getFreeShipping());
                 $item->calcRowWeight();
                 $item->setQty($origQty);
             } else {
                 $item->setRowWeight(0);
             }
         }
         $address->setFreeMethodWeight($address->getFreeMethodWeight() + $item->getRowWeight());
     }
     $address->collectShippingRates();
     $address->setShippingAmount(0);
     $address->setBaseShippingAmount(0);
     $method = $address->getShippingMethod();
     if ($method) {
         foreach ($address->getAllShippingRates() as $rate) {
             if ($rate->getCode() == $method) {
                 $amountPrice = $address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                 $address->setShippingAmount($amountPrice);
                 $address->setBaseShippingAmount($rate->getPrice());
                 $address->setShippingDescription($rate->getCarrierTitle() . ' - ' . $rate->getMethodDescription());
                 break;
             }
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getShippingAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseShippingAmount());
     return $this;
 }
Esempio n. 21
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $quote = $address->getQuote();
     $eventArgs = array('website_id' => Mage::app()->getStore($quote->getStoreId())->getWebsiteId(), 'customer_group_id' => $quote->getCustomerGroupId(), 'coupon_code' => $quote->getCouponCode());
     $address->setFreeShipping(0);
     $totalDiscountAmount = 0;
     $subtotalWithDiscount = 0;
     $baseTotalDiscountAmount = 0;
     $baseSubtotalWithDiscount = 0;
     $hasDiscount = false;
     foreach ($address->getAllItems() as $item) {
         if ($item->getNoDiscount()) {
             $item->setDiscountAmount(0);
             $item->setBaseDiscountAmount(0);
             $item->setRowTotalWithDiscount($item->getRowTotal());
             $item->setBaseRowTotalWithDiscount($item->getRowTotal());
             $subtotalWithDiscount += $item->getRowTotal();
             $baseSubtotalWithDiscount += $item->getBaseRowTotal();
         } else {
             $eventArgs['item'] = $item;
             Mage::dispatchEvent('sales_quote_address_discount_item', $eventArgs);
             if ($item->getDiscountAmount()) {
                 $hasDiscount = true;
             }
             $totalDiscountAmount += $item->getDiscountAmount();
             $baseTotalDiscountAmount += $item->getBaseDiscountAmount();
             $item->setRowTotalWithDiscount($item->getRowTotal() - $item->getDiscountAmount());
             $item->setBaseRowTotalWithDiscount($item->getBaseRowTotal() - $item->getBaseDiscountAmount());
             $subtotalWithDiscount += $item->getRowTotalWithDiscount();
             $baseSubtotalWithDiscount += $item->getBaseRowTotalWithDiscount();
         }
     }
     $address->setDiscountAmount($totalDiscountAmount);
     $address->setSubtotalWithDiscount($subtotalWithDiscount);
     $address->setBaseDiscountAmount($baseTotalDiscountAmount);
     $address->setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
     if (!$hasDiscount) {
         $quote->setCouponCode(null);
     }
     $address->setGrandTotal($address->getGrandTotal() - $address->getDiscountAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getBaseDiscountAmount());
     return $this;
 }
Esempio n. 22
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $store = $address->getQuote()->getStore();
     $address->setTaxAmount(0);
     $address->setBaseTaxAmount(0);
     $tax = Mage::getModel('tax/rate_data')->setCustomerClassId($address->getQuote()->getCustomerTaxClassId());
     /* @var $tax Mage_Tax_Model_Rate_Data */
     $taxAddress = $address;
     switch (Mage::getStoreConfig('sales/tax/based_on')) {
         case 'billing':
             $taxAddress = $address->getQuote()->getBillingAddress();
         case 'shipping':
             $tax->setCountryId($taxAddress->getCountryId())->setRegionId($taxAddress->getRegionId())->setPostcode($taxAddress->getPostcode());
             break;
         case 'origin':
             $tax->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $store))->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $store))->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $store));
             break;
     }
     foreach ($address->getAllItems() as $item) {
         $tax->setProductClassId($item->getProduct()->getTaxClassId());
         $rate = $tax->getRate();
         $item->setTaxPercent($rate);
         $item->calcTaxAmount();
         $address->setTaxAmount($address->getTaxAmount() + $item->getTaxAmount());
         $address->setBaseTaxAmount($address->getBaseTaxAmount() + $item->getBaseTaxAmount());
     }
     $shippingTaxClass = Mage::getStoreConfig('sales/tax/shipping_tax_class', $store);
     if ($shippingTaxClass) {
         $tax->setProductClassId($shippingTaxClass);
         if ($rate = $tax->getRate()) {
             $shippingTax = $address->getShippingAmount() * $rate / 100;
             $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100;
             $shippingTax = $store->roundPrice($shippingTax);
             $shippingBaseTax = $store->roundPrice($shippingBaseTax);
             $address->setTaxAmount($address->getTaxAmount() + $shippingTax);
             $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax);
         }
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getTaxAmount());
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTaxAmount());
     return $this;
 }
Esempio n. 23
0
 /**
  * collect reward point label 
  * 
  * @param Mage_Sales_Model_Quote_Address $address
  * @return Magestore_RewardPoints_Model_Total_Quote_Label
  */
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setRewardpointsSpent(0);
     $address->setRewardpointsBaseDiscount(0);
     $address->setRewardpointsDiscount(0);
     $address->setRewardpointsEarn(0);
     $address->setMagestoreBaseDiscount(0);
     foreach ($address->getAllItems() as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $child->setRewardpointsBaseDiscount(0)->setRewardpointsDiscount(0)->setMagestoreBaseDiscount(0)->setRewardpointsSpent(0);
             }
         } elseif ($item->getProduct()) {
             $item->setRewardpointsBaseDiscount(0)->setRewardpointsDiscount(0)->setMagestoreBaseDiscount(0)->setRewardpointsSpent(0);
         }
     }
     return $this;
 }
Esempio n. 24
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setBaseCodFee(0);
     $address->setCodFee(0);
     $address->setCodTaxAmount(0);
     $address->setBaseCodTaxAmount(0);
     $collection = $address->getQuote()->getPaymentsCollection();
     if ($collection->count() <= 0 || $address->getQuote()->getPayment()->getMethod() == null) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if ($paymentMethod->getCode() != 'cashondelivery') {
         return $this;
     }
     $items = $address->getAllItems();
     //print_r($address->getAddressType());
     //print_r(count($items));
     if (!count($items)) {
         //return $this;
     }
     $baseTotal = $address->getBaseGrandTotal();
     $baseCodFee = $paymentMethod->getAddressCodFee($address);
     if (!$baseCodFee > 0) {
         return $this;
     }
     // adress is the reference for grand total
     $quote = $address->getQuote();
     $store = $quote->getStore();
     $baseTotal += $baseCodFee;
     $address->setBaseCodFee($baseCodFee);
     $address->setCodFee($store->convertPrice($baseCodFee, false));
     // update totals
     $address->setBaseGrandTotal($baseTotal);
     $address->setGrandTotal($store->convertPrice($baseTotal, false));
     //Updating cod tax if it is already included into a COD fee
     $baseCodTaxAmount = $paymentMethod->getAddressCodTaxAmount($address);
     $address->setBaseCodTaxAmount($baseCodTaxAmount);
     $address->setCodTaxAmount($store->convertPrice($baseCodTaxAmount, false));
     return $this;
 }
Esempio n. 25
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setBaseCodFee(0);
     $address->setCodFee(0);
     $address->setCodTaxAmount(0);
     $address->setBaseCodTaxAmount(0);
     $paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
     $paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
     if ($paymentMethod != 'cashondelivery' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if ($paymentMethod->getCode() != 'cashondelivery') {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $baseTotal = $address->getBaseGrandTotal();
     $baseCodFee = $paymentMethod->getAddressCodFee($address);
     if (!$baseCodFee > 0) {
         return $this;
     }
     // adress is the reference for grand total
     $quote = $address->getQuote();
     $store = $quote->getStore();
     $baseTotal += $baseCodFee;
     $address->setBaseCodFee($baseCodFee);
     $address->setCodFee($store->convertPrice($baseCodFee, false));
     // update totals
     $address->setBaseGrandTotal($baseTotal);
     $address->setGrandTotal($store->convertPrice($baseTotal, false));
     //Updating cod tax if it is already included into a COD fee
     $baseCodTaxAmount = $paymentMethod->getAddressCodTaxAmount($address);
     $address->setBaseCodTaxAmount($baseCodTaxAmount);
     $address->setCodTaxAmount($store->convertPrice($baseCodTaxAmount, false));
     return $this;
 }
Esempio n. 26
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $paymentMethod = Mage::app()->getFrontController()->getRequest()->getParam('payment');
     $paymentMethod = Mage::app()->getStore()->isAdmin() && isset($paymentMethod['method']) ? $paymentMethod['method'] : null;
     if ($paymentMethod !== 'payexinvoice' && (!count($address->getQuote()->getPaymentsCollection()) || !$address->getQuote()->getPayment()->hasMethodInstance())) {
         return $this;
     }
     $paymentMethod = $address->getQuote()->getPayment()->getMethodInstance();
     if ($paymentMethod->getCode() !== 'payexinvoice') {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $address->setBasePayexinvoicePaymentFee(0);
     $address->setPayexinvoicePaymentFee(0);
     // Get totals
     $address1 = clone $address;
     foreach ($address1->getTotalCollector()->getCollectors() as $model) {
         if ($model->getCode() !== $this->getCode()) {
             $model->collect($address1);
         }
     }
     // Address is the reference for grand total
     // Calculated total is $address1->getGrandTotal()
     $fee = (double) Mage::getSingleton('payexinvoice/fee')->getPaymentFee($address1);
     if (!$fee) {
         return $this;
     }
     $baseTotal = $address->getBaseGrandTotal();
     $baseTotal += $fee;
     $address->setBasePayexinvoicePaymentFee($fee);
     $address->setPayexinvoicePaymentFee($address->getQuote()->getStore()->convertPrice($fee, false));
     // update totals
     $address->setBaseGrandTotal($baseTotal);
     $address->setGrandTotal($address->getQuote()->getStore()->convertPrice($baseTotal, false));
     return $this;
 }
Esempio n. 27
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $store = $address->getQuote()->getStore();
     $session = Mage::getSingleton('checkout/session');
     $discount = $session->getData('webpos_admin_discount');
     if (!$discount) {
         return $this;
     }
     $items = $address->getAllItems();
     if (!count($items)) {
         return $this;
     }
     $session->setData('webpos_admin_discount', $discount);
     $address->setWebposDiscountAmount($discount);
     $address->setData('webpos_discount_amount', $discount);
     /* Daniel - tax for discount */
     $afterDiscount = Mage::getStoreConfig('tax/calculation/apply_after_discount');
     if ($afterDiscount) {
         $country = Mage::getModel('checkout/session')->getQuote()->getShippingAddress()->getCountry();
         $oldTax = $address->getTaxAmount();
         $oldBaseTax = $address->getBaseTaxAmount();
         if ($country) {
             $rateTax = Mage::getModel('tax/calculation_rate')->getCollection()->addFieldToFilter('tax_country_id', $country)->setOrder('rate', 'DESC')->getFirstItem();
             $address->setTaxAmount(($address->getBaseSubtotal() - $discount + $address->getShippingAmount() + $address->getDiscountAmount()) * $rateTax->getRate() / 100)->setBaseTaxAmount(($address->getBaseSubtotal() - $discount + $address->getShippingAmount() + $address->getDiscountAmount()) * $rateTax->getRate() / 100);
             $taxCalculationModel = Mage::getSingleton('tax/calculation');
             $request = Mage::getSingleton('tax/calculation')->getRateRequest($address, $address->getQuote()->getBillingAddress(), $address->getQuote()->getCustomerTaxClassId(), $store);
             $rate = Mage::getSingleton('tax/calculation')->getRate($request);
             $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $address->getTaxAmount(), $address->getBaseTaxAmount(), $rate);
         }
         $address->setGrandTotal($address->getGrandTotal() - $address->getWebposDiscountAmount());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getWebposDiscountAmount());
     } else {
         $address->setGrandTotal($address->getGrandTotal() - $address->getWebposDiscountAmount());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() - $address->getWebposDiscountAmount());
     }
     /* end */
     return $this;
 }
Esempio n. 28
0
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $count = Mage::getModel('customerreward/count')->loadByKey(Mage::getSingleton('core/cookie')->get('customerreward_offer_key'));
     if (!$count || !$count->getId() || !$count->validateCount()) {
         return $this;
     }
     $offer = Mage::getModel('customerreward/offer')->loadByCount($count);
     if ($offer && $offer->getId()) {
         if ($offer->getDiscountMethod() != Magestore_Customerreward_Helper_Offer::OFFER_METHOD_DISCOUNT || $offer->getDiscountShow() != Magestore_Customerreward_Helper_Offer::SHOW_OFFER_IN_CART) {
             return $this;
         }
         $productIds = $offer->getProductIds();
         $items = $address->getAllItems();
         $baseDiscount = 0;
         foreach ($items as $item) {
             if (in_array($item->getProduct()->getId(), $productIds)) {
                 if ($offer->getDiscountType() == Magestore_Customerreward_Helper_Offer::OFFER_TYPE_FIXED) {
                     $discount = $item->getProduct()->getFinalPrice() < $offer->getDiscount() ? $item->getProduct()->getFinalPrice() : $offer->getDiscount();
                 } else {
                     $discount = $item->getProduct()->getFinalPrice() * $offer->getDiscount() / 100;
                 }
                 $baseDiscount += $item->getQty() * $discount;
             }
         }
         if ($baseDiscount <= 0) {
             return $this;
         }
         $discount = Mage::app()->getStore()->convertPrice($baseDiscount);
         $address->setOfferDiscount(-$discount);
         $address->setBaseOfferDiscount(-$baseDiscount);
         $address->setGrandTotal($address->getGrandTotal() + $address->getOfferDiscount());
         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseOfferDiscount());
         $session = Mage::getSingleton('checkout/session');
         $session->setData('offer_discount', -$discount);
         $session->setData('base_offer_discount', -$baseDiscount);
     }
     return $this;
 }
Esempio n. 29
0
 /**
  * Returns a total discount on the cart from the provided items
  *
  * @param Mage_Sales_Model_Quote_Item $item
  * @param Mage_Sales_Model_Quote_Address $address
  * @param TBT_Rewards_Model_Sales_Rule $rule
  * @param int $qty	max discount qty or unlimited if null
  * @return float
  */
 protected function _getTotalPercentDiscount($item, $address, $rule, $qty = null)
 {
     $all_items = $address->getAllItems();
     $store = $item->getQuote()->getStore();
     $totalDiscountOnCart = 0;
     $discountPercent = $this->_getRulePercent($rule);
     // TODO move this to a method
     if ($rule->getPointsAction() != TBT_Rewards_Model_Salesrule_Actions::ACTION_DISCOUNT_BY_POINTS_SPENT) {
         foreach ($all_items as $cartItem) {
             if (!$rule->getActions()->validate($cartItem)) {
                 continue;
             }
             list($item_row_total, $item_base_row_total) = $this->_getDiscountableRowTotal($address, $item, $rule);
             $discountOnItem = $item_row_total * $discountPercent;
             $totalDiscountOnCart += $discountOnItem;
         }
         return $totalDiscountOnCart;
     }
     $totalAmountToDiscount = 0;
     foreach ($all_items as $cartItem) {
         if (!$rule->getActions()->validate($cartItem)) {
             continue;
         }
         list($item_row_total, $item_base_row_total) = $this->_getDiscountableRowTotal($address, $item, $rule);
         $totalAmountToDiscount += $item_row_total;
         // $cartItem->getTaxAmount();
         /*// Fetch the catalog rewards discounts.  Add this NEGATIVE amount to the total.
           list($catalog_discount, $base_catalog_discount) = $this->_collectCatalogRewardsDiscounts($address, $cartItem);
           $totalAmountToDiscount += $base_catalog_discount;*/
     }
     // @nelkaake -a 16/11/10:
     if ($rule->getApplyToShipping()) {
         $totalAmountToDiscount += $address->getBaseShippingAmountForDiscount();
     }
     $totalDiscountOnCart = $totalAmountToDiscount * $discountPercent;
     return $totalDiscountOnCart;
 }
Esempio n. 30
0
 public function _prepareDiscountCreditForAmount(Mage_Sales_Model_Quote_Address $address, $baseDiscount)
 {
     $items = $address->getAllItems();
     $store = $address->getQuote()->getStoreId();
     if (!count($items)) {
         return $this;
     }
     // Calculate total item prices
     $baseItemsPrice = 0;
     foreach ($items as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $baseItemsPrice += $item->getQty() * ($child->getQty() * $child->getBasePrice() - $child->getBaseDiscountAmount());
             }
         } elseif ($item->getProduct()) {
             $baseItemsPrice += $item->getQty() * $item->getBasePrice() - $item->getBaseDiscountAmount() - $item->getBaseCustomercreditDiscount();
         }
     }
     if ($baseItemsPrice < 0.0001) {
         return $this;
     }
     // Update discount for each item
     foreach ($items as $item) {
         if ($item->getParentItemId()) {
             continue;
         }
         if ($item->getHasChildren() && $item->isChildrenCalculated()) {
             foreach ($item->getChildren() as $child) {
                 $baseItemPrice = $item->getQty() * ($child->getQty() * $child->getBasePrice() - $child->getBaseDiscountAmount());
                 $itemBaseDiscount = $baseDiscount * $baseItemPrice / $baseItemsPrice;
                 $itemDiscount = Mage::app()->getStore()->convertPrice($itemBaseDiscount);
                 $child->setBaseCustomercreditDiscount($child->getBaseCustomercreditDiscount())->setCustomercreditDiscount($child->getCustomercreditDiscount());
             }
         } elseif ($item->getProduct()) {
             $baseItemPrice = $item->getQty() * $item->getBasePrice() - $item->getBaseDiscountAmount() - $item->getBaseCustomercreditDiscount();
             $itemBaseDiscount = $baseDiscount * $baseItemPrice / $baseItemsPrice;
             $itemDiscount = Mage::app()->getStore()->convertPrice($itemBaseDiscount);
             $item->setBaseCustomercreditDiscount($itemBaseDiscount)->setCustomercreditDiscount($itemDiscount);
         }
     }
     return $this;
 }