setCode('shipping'); $this->_calculator = Mage::getSingleton('tax/calculation'); $this->_config = Mage::getSingleton('tax/config'); } /** * Collect totals information about shipping * * @param Mage_Sales_Model_Quote_Address $address * @return Mage_Sales_Model_Quote_Address_Total_Shipping */ public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $calc = $this->_calculator; $store = $address->getQuote()->getStore(); $storeTaxRequest = $calc->getRateOriginRequest($store); $addressTaxRequest = $calc->getRateRequest( $address, $address->getQuote()->getBillingAddress(), $address->getQuote()->getCustomerTaxClassId(), $store ); $shippingTaxClass = $this->_config->getShippingTaxClass($store); $storeTaxRequest->setProductClassId($shippingTaxClass); $addressTaxRequest->setProductClassId($shippingTaxClass); $priceIncludesTax = $this->_config->shippingPriceIncludesTax($store); if ($priceIncludesTax) { $this->_areTaxRequestsSimilar = $calc->compareRequests($addressTaxRequest, $storeTaxRequest); } $shipping = $taxShipping = $address->getShippingAmount(); $baseShipping = $baseTaxShipping = $address->getBaseShippingAmount(); $rate = $calc->getRate($addressTaxRequest); if ($priceIncludesTax) { if ($this->_areTaxRequestsSimilar) { $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, true, false), $rate, true); $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, true, false), $rate, true, 'base'); $taxShipping = $shipping; $baseTaxShipping= $baseShipping; $shipping = $shipping - $tax; $baseShipping = $baseShipping - $baseTax; $taxable = $taxShipping; $baseTaxable = $baseTaxShipping; $isPriceInclTax = true; } else { $storeRate = $calc->getStoreRate($addressTaxRequest, $store); $storeTax = $calc->calcTaxAmount($shipping, $storeRate, true, false); $baseStoreTax = $calc->calcTaxAmount($baseShipping, $storeRate, true, false); $shipping = $calc->round($shipping - $storeTax); $baseShipping = $calc->round($baseShipping - $baseStoreTax); $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false); $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base'); $taxShipping = $shipping + $tax; $baseTaxShipping= $baseShipping + $baseTax; $taxable = $shipping; $baseTaxable = $baseShipping; $isPriceInclTax = false; } } else { $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false); $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base'); $taxShipping = $shipping + $tax; $baseTaxShipping= $baseShipping + $baseTax; $taxable = $shipping; $baseTaxable = $baseShipping; $isPriceInclTax = false; } $address->setTotalAmount('shipping', $shipping); $address->setBaseTotalAmount('shipping', $baseShipping); $address->setShippingInclTax($taxShipping); $address->setBaseShippingInclTax($baseTaxShipping); $address->setShippingTaxable($taxable); $address->setBaseShippingTaxable($baseTaxable); $address->setIsShippingInclTax($isPriceInclTax); if ($this->_config->discountTax($store)) { $address->setShippingAmountForDiscount($taxShipping); $address->setBaseShippingAmountForDiscount($baseTaxShipping); } return $this; } /** * Round price based on tax rounding settings * * @param float $price * @param string $rate * @param bool $direction * @param string $type * @return float */ protected function _round($price, $rate, $direction, $type = 'regular') { if (!$price) { return $this->_calculator->round($price); } $deltas = $this->_address->getRoundingDeltas(); $key = $type.$direction; $rate = (string) $rate; $delta = isset($deltas[$key][$rate]) ? $deltas[$key][$rate] : 0; return $this->_calculator->round($price+$delta); } /** * Get request for fetching store tax rate * * @deprecated after 1.4.0.0 * @param Mage_Sales_Model_Quote_Address $address * @return Varien_Object */ protected function _getStoreTaxRequest($address) { if (is_null($this->_storeTaxRequest)) { $this->_storeTaxRequest = $this->_calculator->getRateOriginRequest($address->getQuote()->getStore()); } return $this->_storeTaxRequest; } /** * Get request for fetching address tax rate * * @deprecated after 1.4.0.0 * @param Mage_Sales_Model_Quote_Address $address * @return Varien_Object */ protected function _getAddressTaxRequest($address) { $addressTaxRequest = $this->_calculator->getRateRequest( $address, $address->getQuote()->getBillingAddress(), $address->getQuote()->getCustomerTaxClassId(), $address->getQuote()->getStore() ); return $addressTaxRequest; } /** * Check if we need subtract store tax amount from shipping * * @deprecated after 1.4.0.0 * @param Mage_Sales_Model_Quote_Address $address * @return bool */ protected function _needSubtractShippingTax($address) { $store = $address->getQuote()->getStore(); if ($this->_config->shippingPriceIncludesTax($store) || $this->_config->getNeedUseShippingExcludeTax()) { return true; } return false; } /** * Calculate shipping price without store tax * * @deprecated after 1.4.0.0 * @param Mage_Sales_Model_Quote_Address $address * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _processShippingAmount($address) { } }