Esempio n. 1
0
 /**
  * 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);
     $storeTaxRequest->setProductClassId($this->_config->getShippingTaxClass($store));
     $addressTaxRequest->setProductClassId($this->_config->getShippingTaxClass($store));
     $this->_areTaxRequestsSimilar = $calc->compareRequests($addressTaxRequest, $storeTaxRequest);
     $shipping = $taxShipping = $address->getShippingAmount();
     $baseShipping = $baseTaxShipping = $address->getBaseShippingAmount();
     $rate = $calc->getRate($addressTaxRequest);
     if ($this->_config->shippingPriceIncludesTax($store)) {
         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), false, $rate);
             $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), false, $rate);
         $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;
 }
Esempio n. 2
0
 /**
  * Tax caclulation for shipping price
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $store = $address->getQuote()->getStore();
     $shippingTaxClass = $this->_config->getShippingTaxClass($store);
     $shippingAmount = $address->getShippingAmount();
     $baseShippingAmount = $address->getBaseShippingAmount();
     $shippingDiscountAmount = $address->getShippingDiscountAmount();
     $baseShippingDiscountAmount = $address->getBaseShippingDiscountAmount();
     /**
      * Subtract discount before calculate tax amount
      */
     if ($this->_config->applyTaxAfterDiscount($store)) {
         $calcAmount = $shippingAmount - $shippingDiscountAmount;
         $baseCalcAmount = $baseShippingAmount - $baseShippingDiscountAmount;
     } else {
         $calcAmount = $shippingAmount;
         $baseCalcAmount = $baseShippingAmount;
     }
     $shippingTax = 0;
     $shippingBaseTax = 0;
     if ($shippingTaxClass) {
         $taxRateRequest->setProductClassId($shippingTaxClass);
         $rate = $this->_calculator->getRate($taxRateRequest);
         if ($rate) {
             if ($this->_config->shippingPriceIncludesTax($store) && $this->_areTaxRequestsSimilar) {
                 $shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate, true);
                 $shippingBaseTax = $this->_calculator->calcTaxAmount($baseCalcAmount, $rate, true);
                 $shippingAmount -= $shippingTax;
                 $baseShippingAmount -= $shippingBaseTax;
             } else {
                 $shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate);
                 $shippingBaseTax = $this->_calculator->calcTaxAmount($baseCalcAmount, $rate);
             }
             $address->setTotalAmount('shipping', $shippingAmount);
             $address->setBaseTotalAmount('shipping', $baseShippingAmount);
             /**
              * Provide additional attributes for apply discount on price include tax
              */
             if ($this->_config->discountTax($store)) {
                 $address->setShippingAmountForDiscount($shippingAmount + $shippingTax);
                 $address->setBaseShippingAmountForDiscount($baseShippingAmount + $shippingBaseTax);
             }
             $this->_addAmount($shippingTax);
             $this->_addBaseAmount($shippingBaseTax);
             $applied = $this->_calculator->getAppliedRates($taxRateRequest);
             $this->_saveAppliedTaxes($address, $applied, $shippingTax, $shippingBaseTax, $rate);
         }
     }
     $address->setShippingTaxAmount($shippingTax);
     $address->setBaseShippingTaxAmount($shippingBaseTax);
     return $this;
 }
Esempio n. 3
0
 /**
  * Tax caclulation for shipping price
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $taxRateRequest->setProductClassId($this->_config->getShippingTaxClass($this->_store));
     $rate = $this->_calculator->getRate($taxRateRequest);
     $inclTax = $address->getIsShippingInclTax();
     $shipping = $address->getShippingTaxable();
     $baseShipping = $address->getBaseShippingTaxable();
     $hiddenTax = null;
     $baseHiddenTax = null;
     switch ($this->_helper->getCalculationSequence($this->_store)) {
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
             $tax = $this->_calculator->calcTaxAmount($shipping, $rate, $inclTax, false);
             $baseTax = $this->_calculator->calcTaxAmount($baseShipping, $rate, $inclTax, false);
             break;
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
             $discountAmount = $address->getShippingDiscountAmount();
             $baseDiscountAmount = $address->getBaseShippingDiscountAmount();
             $tax = $this->_calculator->calcTaxAmount($shipping - $discountAmount, $rate, $inclTax, false);
             $baseTax = $this->_calculator->calcTaxAmount($baseShipping - $baseDiscountAmount, $rate, $inclTax, false);
             break;
     }
     if ($this->_config->getAlgorithm($this->_store) == Mage_Tax_Model_Calculation::CALC_TOTAL_BASE) {
         $tax = $this->_deltaRound($tax, $rate, $inclTax);
         $baseTax = $this->_deltaRound($baseTax, $rate, $inclTax, 'base');
     } else {
         $tax = $this->_calculator->round($tax);
         $baseTax = $this->_calculator->round($baseTax);
     }
     if ($inclTax && !empty($discountAmount)) {
         $hiddenTax = $shipping - $tax - $address->getShippingAmount();
         $baseHiddenTax = $baseShipping - $baseTax - $address->getBaseShippingAmount();
     }
     $this->_addAmount(max(0, $tax));
     $this->_addBaseAmount(max(0, $baseTax));
     $address->setShippingTaxAmount(max(0, $tax));
     $address->setBaseShippingTaxAmount(max(0, $baseTax));
     $address->setShippingHiddenTaxAmount(max(0, $hiddenTax));
     $address->setBaseShippingHiddenTaxAmount(max(0, $baseHiddenTax));
     $address->addTotalAmount('shipping_hidden_tax', $hiddenTax);
     $address->addBaseTotalAmount('shipping_hidden_tax', $baseHiddenTax);
     $applied = $this->_calculator->getAppliedRates($taxRateRequest);
     $this->_saveAppliedTaxes($address, $applied, $tax, $baseTax, $rate);
     return $this;
 }
Esempio n. 4
0
 /**
  * Tax caclulation for shipping price
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @param   Varien_Object $taxRateRequest
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
 {
     $taxRateRequest->setProductClassId($this->_config->getShippingTaxClass($this->_store));
     $rate = $this->_calculator->getRate($taxRateRequest);
     $inclTax = $address->getIsShippingInclTax();
     $address->setShippingTaxAmount(0);
     $address->setBaseShippingTaxAmount(0);
     $address->setShippingHiddenTaxAmount(0);
     $address->setBaseShippingHiddenTaxAmount(0);
     $appliedRates = $this->_calculator->getAppliedRates($taxRateRequest);
     if ($inclTax) {
         $this->_calculateShippingTaxByRate($address, $rate, $appliedRates);
     } else {
         foreach ($appliedRates as $appliedRate) {
             $taxRate = $appliedRate['percent'];
             $taxId = $appliedRate['id'];
             $this->_calculateShippingTaxByRate($address, $taxRate, array($appliedRate), $taxId);
         }
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Calculate shipping price without store tax
  *
  * @param   Mage_Sales_Model_Quote_Address $address
  * @return  Mage_Tax_Model_Sales_Total_Quote_Subtotal
  */
 protected function _processShippingAmount($address)
 {
     if ($this->_areTaxRequestsSimilar) {
         return $this;
     }
     $store = $address->getQuote()->getStore();
     $shippingTaxClass = $this->_config->getShippingTaxClass($store);
     $shippingAmount = $address->getShippingAmount();
     $baseShippingAmount = $address->getBaseShippingAmount();
     if ($shippingTaxClass) {
         $request = $this->_getStoreTaxRequest($address);
         $request->setProductClassId($shippingTaxClass);
         $rate = $this->_calculator->getRate($request);
         if ($rate) {
             $shippingTax = $this->_calculator->calcTaxAmount($shippingAmount, $rate, true, false);
             $shippingBaseTax = $this->_calculator->calcTaxAmount($baseShippingAmount, $rate, true, false);
             $shippingAmount -= $shippingTax;
             $baseShippingAmount -= $shippingBaseTax;
             $address->setTotalAmount('shipping', $this->_calculator->roundUp($shippingAmount));
             $address->setBaseTotalAmount('shipping', $this->_calculator->roundUp($baseShippingAmount));
         }
     }
     return $this;
 }
Esempio n. 6
0
 /**
  * Get tax class id specified for shipping tax estimation
  *
  * @param mixed $store
  * @return int
  */
 public function getShippingTaxClass($store)
 {
     return $this->_config->getShippingTaxClass($store);
 }
Esempio n. 7
0
 /**
  * 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) {
         if ($this->_helper->isCrossBorderTradeEnabled($store)) {
             $this->_areTaxRequestsSimilar = true;
         } else {
             $this->_areTaxRequestsSimilar = $this->_calculator->compareRequests($storeTaxRequest, $addressTaxRequest);
         }
     }
     $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;
             $address->setTotalAmount('shipping', $shipping);
             $address->setBaseTotalAmount('shipping', $baseShipping);
         } 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, true);
             $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, true, 'base');
             $taxShipping = $shipping + $tax;
             $baseTaxShipping = $baseShipping + $baseTax;
             $taxable = $taxShipping;
             $baseTaxable = $baseTaxShipping;
             $isPriceInclTax = true;
             $address->setTotalAmount('shipping', $shipping);
             $address->setBaseTotalAmount('shipping', $baseShipping);
         }
     } else {
         $appliedRates = $calc->getAppliedRates($addressTaxRequest);
         $taxes = array();
         $baseTaxes = array();
         foreach ($appliedRates as $appliedRate) {
             $taxRate = $appliedRate['percent'];
             $taxId = $appliedRate['id'];
             $taxes[] = $this->_round($calc->calcTaxAmount($shipping, $taxRate, false, false), $taxId, false);
             $baseTaxes[] = $this->_round($calc->calcTaxAmount($baseShipping, $taxRate, false, false), $taxId, false, 'base');
         }
         $tax = array_sum($taxes);
         $baseTax = array_sum($baseTaxes);
         $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;
 }