/** * If tax value differs tax which is setted on magento, * apply Google tax and recollect quote * * @param Varien_Object $qAddress * @return string | false */ protected function _applyCustomTax($qAddress) { $quote = $qAddress->getQuote(); $qTaxAmount = $qAddress->getBaseTaxAmount(); $newTaxAmount = $this->getData('root/order-adjustment/total-tax/VALUE'); if ($qTaxAmount != $newTaxAmount) { $taxQuotient = (int) $qTaxAmount ? $newTaxAmount / $qTaxAmount : $newTaxAmount; $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($newTaxAmount, $quote)); $qAddress->setBaseTaxAmount($newTaxAmount); $grandTotal = $qAddress->getBaseGrandTotal() - $qTaxAmount + $newTaxAmount; $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($grandTotal, $quote)); $qAddress->setBaseGrandTotal($grandTotal); $subtotalInclTax = $qAddress->getSubtotalInclTax() - $qTaxAmount + $newTaxAmount; $qAddress->setSubtotalInclTax($subtotalInclTax); foreach ($quote->getAllVisibleItems() as $item) { if ($item->getParentItem()) { continue; } if ($item->getTaxAmount()) { $item->setTaxAmount($item->getTaxAmount() * $taxQuotient); $item->setBaseTaxAmount($item->getBaseTaxAmount() * $taxQuotient); $taxPercent = round($item->getTaxAmount() / $item->getRowTotal() * 100); $item->setTaxPercent($taxPercent); } } $grandTotal = $quote->getBaseGrandTotal() - $qTaxAmount + $newTaxAmount; $quote->setGrandTotal($this->_reCalculateToStoreCurrency($grandTotal, $quote)); $quote->setBaseGrandTotal($grandTotal); $message = $this->__('The tax amount has been applied based on the information received from Google Checkout, because tax amount received from Google Checkout is different from the calculated tax amount'); return $message; } return false; }