public function collectTotals() { $cod = Mage::getModel('cashOnDelivery/cashOnDelivery'); $res = parent::collectTotals(); $codamount = 0; /* * Check if COD is selected */ if (!is_null($this->_payments) && $this->getPayment()->hasMethodInstance() && $this->getPayment()->getMethodInstance()->getCode() == 'cashondelivery') { /* * Calculate cost */ foreach ($res->getAllShippingAddresses() as $address) { /* * Save old shipping taxes */ $oldTax = $address->getShippingTaxAmount(); $oldBaseTax = $address->getBaseShippingTaxAmount(); /* * Add COD cost */ if ($this->getShippingAddress()->getCountry() == Mage::getStoreConfig('shipping/origin/country_id')) { $codamount = $cod->getInlandCosts(); } else { $codamount = $cod->getForeignCountryCosts(); } $address->setShippingAmount($address->getShippingAmount() + $address->getShippingTaxAmount() + $codamount); $address->setBaseShippingAmount($address->getBaseShippingAmount() + $address->getBaseShippingTaxAmount() + $codamount); /* * Recalculate tax for shipping including COD */ $store = $address->getQuote()->getStore(); $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store); if ($shippingTaxClass) { $custTaxClassId = $address->getQuote()->getCustomerTaxClassId(); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store); if ($rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass))) { if (!Mage::helper('tax')->shippingPriceIncludesTax()) { $shippingTax = $address->getShippingAmount() * $rate / 100; $shippingBaseTax = $address->getBaseShippingAmount() * $rate / 100; $address->setShippingTaxAmount($shippingTax); $address->setBaseShippingTaxAmount($shippingBaseTax); } else { $shippingTax = $address->getShippingTaxAmount(); $shippingBaseTax = $address->getBaseShippingTaxAmount(); } $shippingTax = $store->roundPrice($shippingTax); $shippingBaseTax = $store->roundPrice($shippingBaseTax); $address->setTaxAmount($address->getTaxAmount() - $oldTax + $shippingTax); $address->setBaseTaxAmount($address->getBaseTaxAmount() - $oldBaseTax + $shippingBaseTax); $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $shippingTax - $oldTax, $shippingBaseTax - $oldBaseTax, $rate); } } $address->setBaseGrandTotal($address->getBaseGrandTotal() + $codamount); $address->setGrandTotal($address->getGrandTotal() + $codamount); } } return $res; }
/** * Collect totals patched for magento issue #26145 * * @return Mage_Sales_Model_Quote */ public function collectTotals() { /** * patch for magento issue #26145 */ if (!$this->getTotalsCollectedFlag()) { $items = $this->getAllItems(); foreach ($items as $item) { $item->setData('calculation_price', null); $item->setData('original_price', null); } } parent::collectTotals(); return $this; }