/** * Get calculation tax rate by specific request * * @param Varien_Object $request * @return float */ public function getRate($request) { if ($this->_getDataHelper()->isServiceEnabled($this->_getStore($request))) { return 0; } return parent::getRate($request); }
/** * Init gift wrapping and printed card tax rate for address * * @param Mage_Sales_Model_Quote_Address $address * @return Enterprise_GiftWrapping_Model_Total_Quote_Tax_Giftwrapping */ protected function _initRate($address) { $store = $address->getQuote()->getStore(); $billingAddress = $address->getQuote()->getBillingAddress(); $custTaxClassId = $address->getQuote()->getCustomerTaxClassId(); $this->_request = $this->_taxCalculationModel->getRateRequest($address, $billingAddress, $custTaxClassId, $store); $this->_request->setProductClassId($this->_helper->getWrappingTaxClass($store)); $this->_rate = $this->_taxCalculationModel->getRate($this->_request); return $this; }
/** * Checks whether request for an item has same rate as store one * Used only after collect() started, as far as uses optimized $_areTaxRequestsSimilar property * Used only in case of prices including tax * * @param Varien_Object $request * @return bool */ protected function _sameRateAsStore($request) { // Maybe we know that all requests for currently collected items have same rates if ($this->_areTaxRequestsSimilar) { return true; } // Check current request individually $rate = $this->_calculator->getRate($request); $storeRate = $this->_calculator->getStoreRate($request, $this->_store); return $rate == $storeRate; }
/** * 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 = $this->_getAddressItems($address); $store = $address->getQuote()->getStore(); $taxGroups = array(); $itemTaxGroups = array(); foreach ($items as $item) { if ($item->getParentItem()) { continue; } if ($item->getHasChildren() && $item->isChildrenCalculated()) { foreach ($item->getChildren() as $child) { $taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($taxRateRequest); $applied_rates = $this->_calculator->getAppliedRates($taxRateRequest); $taxGroups[(string) $rate]['applied_rates'] = $applied_rates; $taxGroups[(string) $rate]['incl_tax'] = $child->getIsPriceInclTax(); $this->_aggregateTaxPerRate($child, $rate, $taxGroups); if ($rate > 0) { $itemTaxGroups[$child->getId()] = $applied_rates; } } $this->_recalculateParent($item); } else { $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($taxRateRequest); $applied_rates = $this->_calculator->getAppliedRates($taxRateRequest); $taxGroups[(string) $rate]['applied_rates'] = $applied_rates; $taxGroups[(string) $rate]['incl_tax'] = $item->getIsPriceInclTax(); $this->_aggregateTaxPerRate($item, $rate, $taxGroups); if ($rate > 0) { $itemTaxGroups[$item->getId()] = $applied_rates; } } } if ($address->getQuote()->getTaxesForItems()) { $itemTaxGroups += $address->getQuote()->getTaxesForItems(); } $address->getQuote()->setTaxesForItems($itemTaxGroups); foreach ($taxGroups as $rateKey => $data) { $rate = (double) $rateKey; $inclTax = $data['incl_tax']; $totalTax = $this->_calculator->calcTaxAmount(array_sum($data['totals']), $rate, $inclTax, false); $totalTax += array_sum($data['weee_tax']); $baseTotalTax = $this->_calculator->calcTaxAmount(array_sum($data['base_totals']), $rate, $inclTax, false); $baseTotalTax += array_sum($data['base_weee_tax']); $this->_addAmount($totalTax); $this->_addBaseAmount($baseTotalTax); $totalTaxRounded = $this->_calculator->round($totalTax); $baseTotalTaxRounded = $this->_calculator->round($totalTaxRounded); $this->_saveAppliedTaxes($address, $data['applied_rates'], $totalTaxRounded, $baseTotalTaxRounded, $rate); } return $this; }
/** * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param Varien_Object $taxRateRequest * @param array $taxGroups * @param array $itemTaxGroups * @param boolean $catalogPriceInclTax */ protected function _totalBaseProcessItemTax($item, $taxRateRequest, &$taxGroups, &$itemTaxGroups, $catalogPriceInclTax) { $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($taxRateRequest); $item->setTaxAmount(0); $item->setBaseTaxAmount(0); $item->setHiddenTaxAmount(0); $item->setBaseHiddenTaxAmount(0); $item->setTaxPercent($rate); $item->setDiscountTaxCompensation(0); $rowTotalInclTax = $item->getRowTotalInclTax(); $recalculateRowTotalInclTax = false; if (!isset($rowTotalInclTax)) { $item->setRowTotalInclTax($item->getTaxableAmount()); $item->setBaseRowTotalInclTax($item->getBaseTaxableAmount()); $recalculateRowTotalInclTax = true; } $appliedRates = $this->_calculator->getAppliedRates($taxRateRequest); if ($catalogPriceInclTax) { $taxGroups[(string) $rate]['applied_rates'] = $appliedRates; $taxGroups[(string) $rate]['incl_tax'] = $item->getIsPriceInclTax(); $this->_aggregateTaxPerRate($item, $rate, $taxGroups); } else { //need to calculate each tax separately foreach ($appliedRates as $appliedTax) { $taxId = $appliedTax['id']; $taxRate = $appliedTax['percent']; $taxGroups[$taxId]['applied_rates'] = array($appliedTax); $taxGroups[$taxId]['incl_tax'] = $item->getIsPriceInclTax(); $this->_aggregateTaxPerRate($item, $taxRate, $taxGroups, $taxId, $recalculateRowTotalInclTax); } //We need to calculate weeeAmountInclTax using multiple tax rate here //because the _calculateWeeeTax and _calculateRowWeeeTax only take one tax rate if ($this->_weeeHelper->isEnabled() && $this->_weeeHelper->isTaxable()) { $this->_calculateWeeeAmountInclTax($item, $appliedRates, false); $this->_calculateWeeeAmountInclTax($item, $appliedRates, true); } } if ($rate > 0) { $itemTaxGroups[$item->getId()] = $appliedRates; } return; }
/** * 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(); foreach ($items as $item) { /** * Child item's tax we calculate for parent - that why we skip them */ if ($item->getParentItemId()) { continue; } if ($item->getHasChildren() && $item->isChildrenCalculated()) { foreach ($item->getChildren() as $child) { $rate = $this->_calculator->getRate($taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId())); $taxGroups[(string) $rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest); $this->_aggregateTaxPerRate($child, $rate, $taxGroups); } $this->_recalculateParent($item); } else { $rate = $this->_calculator->getRate($taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId())); $taxGroups[(string) $rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest); $this->_aggregateTaxPerRate($item, $rate, $taxGroups); } } $inclTax = $this->_usePriceIncludeTax($store); 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); $this->_addAmount($totalTax); $this->_addBaseAmount($baseTotalTax); $this->_saveAppliedTaxes($address, $data['applied_rates'], $totalTax, $baseTotalTax, $rate); } return $this; }
/** * Recollect item price and row total using after taxes subtract. * Declare item price including tax attributes * * @deprecated after 1.4.1 * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recollectItem($address, Mage_Sales_Model_Quote_Item_Abstract $item) { $store = $address->getQuote()->getStore(); $request = $this->_getStoreTaxRequest($address); $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); if ($this->_config->discountTax($store)) { $item->setDiscountCalculationPrice($price); $item->setBaseDiscountCalculationPrice($basePrice); } /** * Use original price for tax calculation */ if ($item->hasCustomPrice() && !$this->_helper->applyTaxOnCustomPrice($store)) { $taxPrice = $item->getOriginalPrice(); $baseTaxPrice = $item->getBaseOriginalPrice(); $taxSubtotal = $taxPrice * $qty; $baseTaxSubtotal = $baseTaxPrice * $qty; } if ($this->_areTaxRequestsSimilar) { $item->setRowTotalInclTax($subtotal); $item->setBaseRowTotalInclTax($baseSubtotal); $item->setPriceInclTax($price); $item->setBasePriceInclTax($basePrice); $item->setTaxCalcPrice($taxPrice); $item->setBaseTaxCalcPrice($baseTaxPrice); $item->setTaxCalcRowTotal($taxSubtotal); $item->setBaseTaxCalcRowTotal($baseTaxSubtotal); } $this->_subtotalInclTax += $subtotal; $this->_baseSubtotalInclTax += $baseSubtotal; if ($this->_config->getAlgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { $taxAmount = $this->_calculator->calcTaxAmount($taxPrice, $rate, true); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxPrice, $rate, true); $unitPrice = $this->_calculator->round($price - $taxAmount); $baseUnitPrice = $this->_calculator->round($basePrice - $baseTaxAmount); $subtotal = $this->_calculator->round($unitPrice * $qty); $baseSubtotal = $this->_calculator->round($baseUnitPrice * $qty); } else { $taxAmount = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, true, false); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, true, false); $unitPrice = ($subtotal - $taxAmount) / $qty; $baseUnitPrice = ($baseSubtotal - $baseTaxAmount) / $qty; $subtotal = $this->_calculator->round($subtotal - $taxAmount); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseTaxAmount); } if ($item->hasCustomPrice()) { $item->setCustomPrice($unitPrice); $item->setBaseCustomPrice($baseUnitPrice); } $item->setPrice($baseUnitPrice); $item->setOriginalPrice($unitPrice); $item->setBasePrice($baseUnitPrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); return $this; }