/**
  * 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;
 }
Example #2
0
 /**
  * Calculate item price and row total including/excluding tax based on row total price rounding level
  *
  * @param Mage_Sales_Model_Quote_Item_Abstract $item
  * @param Varien_Object $request
  * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal
  */
 protected function _rowBaseCalculation($item, $request)
 {
     $rate = $this->_calculator->getRate($request->setProductClassId($item->getProduct()->getTaxClassId()));
     $qty = $item->getTotalQty();
     $price = $taxPrice = $item->getCalculationPrice();
     $basePrice = $baseTaxPrice = $item->getBaseCalculationPrice();
     $subtotal = $taxSubtotal = $item->getRowTotal();
     $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal();
     $taxOnOrigPrice = !$this->_helper->applyTaxOnCustomPrice($this->_store) && $item->hasCustomPrice();
     if ($taxOnOrigPrice) {
         $origSubtotal = $item->getOriginalPrice() * $qty;
         $baseOrigSubtotal = $item->getBaseOriginalPrice() * $qty;
     }
     $item->setTaxPercent($rate);
     if ($this->_config->priceIncludesTax($this->_store)) {
         if ($this->_areTaxRequestsSimilar) {
             $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, true);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, true);
             $taxPrice = $price;
             $baseTaxPrice = $basePrice;
             $taxSubtotal = $subtotal;
             $baseTaxSubtotal = $baseSubtotal;
             $subtotal = $subtotal - $rowTax;
             $baseSubtotal = $baseSubtotal - $baseRowTax;
             $price = $this->_calculator->round($subtotal / $qty);
             $basePrice = $this->_calculator->round($baseSubtotal / $qty);
             if ($taxOnOrigPrice) {
                 $taxable = $origSubtotal;
                 $baseTaxable = $baseOrigSubtotal;
             } else {
                 $taxable = $taxSubtotal;
                 $baseTaxable = $baseTaxSubtotal;
             }
             $isPriceInclTax = true;
         } else {
             $storeRate = $this->_calculator->getStoreRate($request, $this->_store);
             $storeTax = $this->_calculator->calcTaxAmount($subtotal, $storeRate, true, false);
             $baseStoreTax = $this->_calculator->calcTaxAmount($baseSubtotal, $storeRate, true, false);
             $subtotal = $this->_calculator->round($subtotal - $storeTax);
             $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseStoreTax);
             $price = $this->_calculator->round($subtotal / $qty);
             $basePrice = $this->_calculator->round($baseSubtotal / $qty);
             $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, false);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, false);
             $taxSubtotal = $subtotal + $rowTax;
             $baseTaxSubtotal = $baseSubtotal + $baseRowTax;
             $taxPrice = $this->_calculator->round($taxSubtotal / $qty);
             $baseTaxPrice = $this->_calculator->round($baseTaxSubtotal / $qty);
             if ($taxOnOrigPrice) {
                 $taxable = $this->_calculator->round($origSubtotal - $storeTax);
                 $baseTaxable = $this->_calculator->round($baseOrigSubtotal - $baseStoreTax);
             } else {
                 $taxable = $subtotal;
                 $baseTaxable = $baseSubtotal;
             }
             $isPriceInclTax = false;
         }
     } else {
         $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, false);
         $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, false);
         $taxSubtotal = $subtotal + $rowTax;
         $baseTaxSubtotal = $baseSubtotal + $baseRowTax;
         $taxPrice = $this->_calculator->round($taxSubtotal / $qty);
         $baseTaxPrice = $this->_calculator->round($baseTaxSubtotal / $qty);
         if ($taxOnOrigPrice) {
             $taxable = $origSubtotal;
             $baseTaxable = $baseOrigSubtotal;
         } else {
             $taxable = $subtotal;
             $baseTaxable = $baseSubtotal;
         }
         $isPriceInclTax = false;
     }
     if ($item->hasCustomPrice()) {
         $item->setCustomPrice($price);
         $item->setBaseCustomPrice($basePrice);
     } else {
         $item->setOriginalPrice($price);
     }
     $item->setPrice($basePrice);
     $item->setBasePrice($basePrice);
     $item->setRowTotal($subtotal);
     $item->setBaseRowTotal($baseSubtotal);
     $item->setPriceInclTax($taxPrice);
     $item->setBasePriceInclTax($baseTaxPrice);
     $item->setRowTotalInclTax($taxSubtotal);
     $item->setBaseRowTotalInclTax($baseTaxSubtotal);
     $item->setTaxableAmount($taxable);
     $item->setBaseTaxableAmount($baseTaxable);
     $item->setIsPriceInclTax($isPriceInclTax);
     if ($this->_config->discountTax($this->_store)) {
         $item->setDiscountCalculationPrice($taxSubtotal / $qty);
         $item->setBaseDiscountCalculationPrice($baseTaxSubtotal / $qty);
     } elseif ($isPriceInclTax) {
         $item->setDiscountCalculationPrice($subtotal / $qty);
         $item->setBaseDiscountCalculationPrice($baseSubtotal / $qty);
     }
     return $this;
 }