Mage_Sales_Model_Quote_Address_Total_Tax Class Reference

Inheritance diagram for Mage_Sales_Model_Quote_Address_Total_Tax:

Mage_Sales_Model_Quote_Address_Total_Abstract Mage_Weee_Model_Total_Quote_Weee

List of all members.

Public Member Functions

 __construct ()
 collect (Mage_Sales_Model_Quote_Address $address)
 fetch (Mage_Sales_Model_Quote_Address $address)

Protected Member Functions

 _saveAppliedTaxes (Mage_Sales_Model_Quote_Address $address, $applied, $amount, $baseAmount, $rate)

Protected Attributes

 $_appliedTaxes = array()


Detailed Description

Definition at line 28 of file Tax.php.


Constructor & Destructor Documentation

__construct (  ) 

Reimplemented in Mage_Weee_Model_Total_Quote_Weee.

Definition at line 32 of file Tax.php.

00032                                  {
00033         $this->setCode('tax');
00034     }


Member Function Documentation

_saveAppliedTaxes ( Mage_Sales_Model_Quote_Address address,
applied,
amount,
baseAmount,
rate 
) [protected]

Definition at line 169 of file Tax.php.

00170     {
00171         $previouslyAppliedTaxes = $address->getAppliedTaxes();
00172         $process = count($previouslyAppliedTaxes);
00173 
00174         foreach ($applied as $row) {
00175             if (!isset($previouslyAppliedTaxes[$row['id']])) {
00176                 $row['process'] = $process;
00177                 $row['amount'] = 0;
00178                 $row['base_amount'] = 0;
00179                 $previouslyAppliedTaxes[$row['id']] = $row;
00180             }
00181 
00182             if (!is_null($row['percent'])) {
00183                 $row['percent'] = $row['percent'] ? $row['percent'] : 1;
00184                 $rate = $rate ? $rate : 1;
00185 
00186                 $appliedAmount = $amount/$rate*$row['percent'];
00187                 $baseAppliedAmount = $baseAmount/$rate*$row['percent'];
00188             } else {
00189                 $appliedAmount = 0;
00190                 $baseAppliedAmount = 0;
00191                 foreach ($row['rates'] as $rate) {
00192                     $appliedAmount += $rate['amount'];
00193                     $baseAppliedAmount += $rate['base_amount'];
00194                 }
00195             }
00196 
00197 
00198             if ($appliedAmount || $previouslyAppliedTaxes[$row['id']]['amount']) {
00199                 $previouslyAppliedTaxes[$row['id']]['amount'] += $appliedAmount;
00200                 $previouslyAppliedTaxes[$row['id']]['base_amount'] += $baseAppliedAmount;
00201             } else {
00202                 unset($previouslyAppliedTaxes[$row['id']]);
00203             }
00204         }
00205         $address->setAppliedTaxes($previouslyAppliedTaxes);
00206     }

collect ( Mage_Sales_Model_Quote_Address address  ) 

Collect totals process

Parameters:
Mage_Sales_Model_Quote_Address $address
Returns:
Mage_Sales_Model_Quote_Address_Total_Abstract

Child item's tax we calculate for parent

We calculate parent tax amount as sum of children's tax amounts

Reimplemented from Mage_Sales_Model_Quote_Address_Total_Abstract.

Reimplemented in Mage_Weee_Model_Total_Quote_Weee.

Definition at line 36 of file Tax.php.

00037     {
00038         $store = $address->getQuote()->getStore();
00039 
00040         $address->setTaxAmount(0);
00041         $address->setBaseTaxAmount(0);
00042         //$address->setShippingTaxAmount(0);
00043         //$address->setBaseShippingTaxAmount(0);
00044         $address->setAppliedTaxes(array());
00045 
00046         $items = $address->getAllItems();
00047         if (!count($items)) {
00048             return $this;
00049         }
00050         $custTaxClassId = $address->getQuote()->getCustomerTaxClassId();
00051 
00052         $taxCalculationModel = Mage::getSingleton('tax/calculation');
00053         /* @var $taxCalculationModel Mage_Tax_Model_Calculation */
00054         $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store);
00055 
00056         foreach ($items as $item) {
00057             /**
00058              * Child item's tax we calculate for parent
00059              */
00060             if ($item->getParentItemId()) {
00061                 continue;
00062             }
00063             /**
00064              * We calculate parent tax amount as sum of children's tax amounts
00065              */
00066 
00067             if ($item->getHasChildren() && $item->isChildrenCalculated()) {
00068                 foreach ($item->getChildren() as $child) {
00069                     $discountBefore = $item->getDiscountAmount();
00070                     $baseDiscountBefore = $item->getBaseDiscountAmount();
00071 
00072                     $rate = $taxCalculationModel->getRate($request->setProductClassId($child->getProduct()->getTaxClassId()));
00073 
00074                     $child->setTaxPercent($rate);
00075                     $child->calcTaxAmount();
00076 
00077                     if ($discountBefore != $item->getDiscountAmount()) {
00078                         $address->setDiscountAmount($address->getDiscountAmount()+($item->getDiscountAmount()-$discountBefore));
00079                         $address->setBaseDiscountAmount($address->getBaseDiscountAmount()+($item->getBaseDiscountAmount()-$baseDiscountBefore));
00080 
00081                         $address->setGrandTotal($address->getGrandTotal() - ($item->getDiscountAmount()-$discountBefore));
00082                         $address->setBaseGrandTotal($address->getBaseGrandTotal() - ($item->getBaseDiscountAmount()-$baseDiscountBefore));
00083                     }
00084 
00085                     $this->_saveAppliedTaxes(
00086                        $address,
00087                        $taxCalculationModel->getAppliedRates($request),
00088                        $child->getTaxAmount(),
00089                        $child->getBaseTaxAmount(),
00090                        $rate
00091                     );
00092                 }
00093                 $address->setTaxAmount($address->getTaxAmount() + $item->getTaxAmount());
00094                 $address->setBaseTaxAmount($address->getBaseTaxAmount() + $item->getBaseTaxAmount());
00095             }
00096             else {
00097                 $discountBefore = $item->getDiscountAmount();
00098                 $baseDiscountBefore = $item->getBaseDiscountAmount();
00099 
00100                 $rate = $taxCalculationModel->getRate($request->setProductClassId($item->getProduct()->getTaxClassId()));
00101 
00102                 $item->setTaxPercent($rate);
00103                 $item->calcTaxAmount();
00104 
00105                 if ($discountBefore != $item->getDiscountAmount()) {
00106                     $address->setDiscountAmount($address->getDiscountAmount()+($item->getDiscountAmount()-$discountBefore));
00107                     $address->setBaseDiscountAmount($address->getBaseDiscountAmount()+($item->getBaseDiscountAmount()-$baseDiscountBefore));
00108 
00109                     $address->setGrandTotal($address->getGrandTotal() - ($item->getDiscountAmount()-$discountBefore));
00110                     $address->setBaseGrandTotal($address->getBaseGrandTotal() - ($item->getBaseDiscountAmount()-$baseDiscountBefore));
00111                 }
00112 
00113                 $address->setTaxAmount($address->getTaxAmount() + $item->getTaxAmount());
00114                 $address->setBaseTaxAmount($address->getBaseTaxAmount() + $item->getBaseTaxAmount());
00115 
00116                 $applied = $taxCalculationModel->getAppliedRates($request);
00117                 $this->_saveAppliedTaxes(
00118                    $address,
00119                    $applied,
00120                    $item->getTaxAmount(),
00121                    $item->getBaseTaxAmount(),
00122                    $rate
00123                 );
00124             }
00125         }
00126 
00127 
00128         $shippingTaxClass = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store);
00129 
00130         $shippingTax      = 0;
00131         $shippingBaseTax  = 0;
00132 
00133         if ($shippingTaxClass) {
00134             if ($rate = $taxCalculationModel->getRate($request->setProductClassId($shippingTaxClass))) {
00135                 if (!Mage::helper('tax')->shippingPriceIncludesTax()) {
00136                     $shippingTax    = $address->getShippingAmount() * $rate/100;
00137                     $shippingBaseTax= $address->getBaseShippingAmount() * $rate/100;
00138                 } else {
00139                     $shippingTax    = $address->getShippingTaxAmount();
00140                     $shippingBaseTax= $address->getBaseShippingTaxAmount();
00141                 }
00142 
00143                 $shippingTax    = $store->roundPrice($shippingTax);
00144                 $shippingBaseTax= $store->roundPrice($shippingBaseTax);
00145 
00146                 $address->setTaxAmount($address->getTaxAmount() + $shippingTax);
00147                 $address->setBaseTaxAmount($address->getBaseTaxAmount() + $shippingBaseTax);
00148 
00149                 $this->_saveAppliedTaxes(
00150                     $address,
00151                     $taxCalculationModel->getAppliedRates($request),
00152                     $shippingTax,
00153                     $shippingBaseTax,
00154                     $rate
00155                 );
00156             }
00157         }
00158 
00159         if (!Mage::helper('tax')->shippingPriceIncludesTax()) {
00160             $address->setShippingTaxAmount($shippingTax);
00161             $address->setBaseShippingTaxAmount($shippingBaseTax);
00162         }
00163 
00164         $address->setGrandTotal($address->getGrandTotal() + $address->getTaxAmount());
00165         $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseTaxAmount());
00166         return $this;
00167     }

fetch ( Mage_Sales_Model_Quote_Address address  ) 

Fetch (Retrieve data as array)

Parameters:
Mage_Sales_Model_Quote_Address $address
Returns:
array

Reimplemented from Mage_Sales_Model_Quote_Address_Total_Abstract.

Reimplemented in Mage_Weee_Model_Total_Quote_Weee.

Definition at line 208 of file Tax.php.

00209     {
00210         $applied = $address->getAppliedTaxes();
00211         $store = $address->getQuote()->getStore();
00212         $amount = $address->getTaxAmount();
00213 
00214         if (($amount!=0) || (Mage::helper('tax')->displayZeroTax($store))) {
00215             $address->addTotal(array(
00216                 'code'=>$this->getCode(),
00217                 'title'=>Mage::helper('sales')->__('Tax'),
00218                 'full_info'=>$applied ? $applied : array(),
00219                 'value'=>$amount
00220             ));
00221         }
00222         return $this;
00223     }


Member Data Documentation

$_appliedTaxes = array() [protected]

Definition at line 30 of file Tax.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:49 2009 for Magento by  doxygen 1.5.8