Mage_Tax_Model_Calculation Class Reference

Inheritance diagram for Mage_Tax_Model_Calculation:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 deleteByRuleId ($ruleId)
 getRates ($ruleId)
 getCustomerTaxClasses ($ruleId)
 getProductTaxClasses ($ruleId)
 getRate ($request)
 getRateRequest ($shippingAddress=null, $billingAddress=null, $customerTaxClass=null, $store=null)
 getRatesForAllProductTaxClasses ($request)
 getRatesForAllCustomerTaxClasses ($request)
 getAppliedRates ($request)
 reproduceProcess ($rates)
 getRatesByCustomerTaxClass ($customerTaxClass)
 getRatesByCustomerAndProductTaxClasses ($customerTaxClass, $productTaxClass)

Protected Member Functions

 _construct ()
 _formCalculationProcess ()
 _getRates ($request, $fieldName, $type)

Protected Attributes

 $_rates = array()
 $_ctc = array()
 $_ptc = array()
 $_rateCache = array()
 $_rateCalculationProcess = array()


Detailed Description

Tax Calculation Model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Calculation.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 41 of file Calculation.php.

00042     {
00043         $this->_init('tax/calculation');
00044     }

_formCalculationProcess (  )  [protected]

Definition at line 76 of file Calculation.php.

00077     {
00078         $title = $this->getRateTitle();
00079         $value = $this->getRateValue();
00080         $id = $this->getRateId();
00081 
00082         $rate = array('code'=>$title, 'title'=>$title, 'percent'=>$value, 'position'=>1, 'priority'=>1);
00083 
00084         $process = array();
00085         $process['percent'] = $value;
00086         $process['id'] = "{$id}-{$value}";
00087         $process['rates'][] = $rate;
00088 
00089         return array($process);
00090     }

_getRates ( request,
fieldName,
type 
) [protected]

Definition at line 182 of file Calculation.php.

00183     {
00184         $result = array();
00185         $classes = Mage::getModel('tax/class')->getCollection()
00186             ->addFieldToFilter('class_type', $type)
00187             ->load();
00188         foreach ($classes as $class) {
00189             $request->setData($fieldName, $class->getId());
00190             $result[$class->getId()] = $this->getRate($request);
00191         }
00192 
00193         return $result;
00194     }

deleteByRuleId ( ruleId  ) 

Definition at line 46 of file Calculation.php.

00047     {
00048         $this->getResource()->deleteByRuleId($ruleId);
00049         return $this;
00050     }

getAppliedRates ( request  ) 

Definition at line 205 of file Calculation.php.

00206     {
00207         $cacheKey = "{$request->getStore()->getId()}|{$request->getProductClassId()}|{$request->getCustomerClassId()}|{$request->getCountryId()}|{$request->getRegionId()}|{$request->getPostcode()}";
00208         if (!isset($this->_rateCalculationProcess[$cacheKey])) {
00209             $this->_rateCalculationProcess[$cacheKey] = $this->_getResource()->getCalculationProcess($request);
00210         }
00211         return $this->_rateCalculationProcess[$cacheKey];
00212     }

getCustomerTaxClasses ( ruleId  ) 

Definition at line 60 of file Calculation.php.

00061     {
00062         if (!isset($this->_ctc[$ruleId])) {
00063             $this->_ctc[$ruleId] = $this->getResource()->getDistinct('customer_tax_class_id', $ruleId);
00064         }
00065         return $this->_ctc[$ruleId];
00066     }

getProductTaxClasses ( ruleId  ) 

Definition at line 68 of file Calculation.php.

00069     {
00070         if (!isset($this->_ptc[$ruleId])) {
00071             $this->_ptc[$ruleId] = $this->getResource()->getDistinct('product_tax_class_id', $ruleId);
00072         }
00073         return $this->_ptc[$ruleId];
00074     }

getRate ( request  ) 

Definition at line 92 of file Calculation.php.

00093     {
00094         if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
00095             return 0;
00096         }
00097 
00098         $cacheKey = "{$request->getProductClassId()}|{$request->getCustomerClassId()}|{$request->getCountryId()}|{$request->getRegionId()}|{$request->getPostcode()}";
00099         if (!isset($this->_rateCache[$cacheKey])) {
00100             $this->unsRateValue();
00101             $this->unsCalculationProcess();
00102             $this->unsEventModuleId();
00103             Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$this));
00104             if (!$this->hasRateValue()) {
00105                 $this->setCalculationProcess($this->_getResource()->getCalculationProcess($request));
00106                 $this->setRateValue($this->_getResource()->getRate($request));
00107             } else {
00108                 $this->setCalculationProcess($this->_formCalculationProcess());
00109             }
00110             $this->_rateCache[$cacheKey] = $this->getRateValue();
00111             $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
00112         }
00113         return $this->_rateCache[$cacheKey];
00114     }

getRateRequest ( shippingAddress = null,
billingAddress = null,
customerTaxClass = null,
store = null 
)

Definition at line 116 of file Calculation.php.

00117     {
00118         $address = new Varien_Object();
00119         $session = Mage::getSingleton('customer/session');
00120         $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store);
00121         if (($shippingAddress === false && $basedOn == 'shipping') || ($billingAddress === false && $basedOn == 'billing')) {
00122             $basedOn = 'default';
00123         } else {
00124             if ((($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId()) && $basedOn == 'billing') || (($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId()) && $basedOn == 'shipping')){
00125                 if (!$session->isLoggedIn()) {
00126                     $basedOn = 'default';
00127                 } else {
00128                     $defBilling = $session->getCustomer()->getDefaultBillingAddress();
00129                     $defShipping = $session->getCustomer()->getDefaultShippingAddress();
00130 
00131                     if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) {
00132                         $billingAddress = $defBilling;
00133                     } else if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) {
00134                         $shippingAddress = $defShipping;
00135                     } else {
00136                         $basedOn = 'default';
00137                     }
00138                 }
00139             }
00140         }
00141 
00142         switch ($basedOn) {
00143             case 'billing':
00144                 $address = $billingAddress;
00145                 break;
00146 
00147             case 'shipping':
00148                 $address = $shippingAddress;
00149                 break;
00150 
00151             case 'origin':
00152                 $address
00153                     ->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $store))
00154                     ->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $store))
00155                     ->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $store));
00156                 break;
00157 
00158             case 'default':
00159                 $address
00160                     ->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))
00161                     ->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))
00162                     ->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store));
00163                 break;
00164         }
00165 
00166         if (is_null($customerTaxClass) && $session->isLoggedIn()) {
00167             $customerTaxClass = $session->getCustomer()->getTaxClassId();
00168         } elseif (($customerTaxClass === false) || !$session->isLoggedIn()) {
00169             $defaultCustomerGroup = Mage::getStoreConfig('customer/create_account/default_group', $store);
00170             $customerTaxClass = Mage::getModel('customer/group')->getTaxClassId($defaultCustomerGroup);
00171         }
00172         $request = new Varien_Object();
00173         $request
00174             ->setCountryId($address->getCountryId())
00175             ->setRegionId($address->getRegionId())
00176             ->setPostcode($address->getPostcode())
00177             ->setStore($store)
00178             ->setCustomerClassId($customerTaxClass);
00179         return $request;
00180     }

getRates ( ruleId  ) 

Definition at line 52 of file Calculation.php.

00053     {
00054         if (!isset($this->_rates[$ruleId])) {
00055             $this->_rates[$ruleId] = $this->getResource()->getDistinct('tax_calculation_rate_id', $ruleId);
00056         }
00057         return $this->_rates[$ruleId];
00058     }

getRatesByCustomerAndProductTaxClasses ( customerTaxClass,
productTaxClass 
)

Definition at line 224 of file Calculation.php.

00225     {
00226         return $this->getResource()->getRatesByCustomerTaxClass($customerTaxClass, $productTaxClass);
00227     }

getRatesByCustomerTaxClass ( customerTaxClass  ) 

Definition at line 219 of file Calculation.php.

00220     {
00221         return $this->getResource()->getRatesByCustomerTaxClass($customerTaxClass);
00222     }

getRatesForAllCustomerTaxClasses ( request  ) 

Definition at line 200 of file Calculation.php.

00201     {
00202         return $this->_getRates($request, 'customer_class_id', 'CUSTOMER');
00203     }

getRatesForAllProductTaxClasses ( request  ) 

Definition at line 196 of file Calculation.php.

00197     {
00198         return $this->_getRates($request, 'product_class_id', 'PRODUCT');
00199     }

reproduceProcess ( rates  ) 

Definition at line 214 of file Calculation.php.

00215     {
00216         return $this->getResource()->getCalculationProcess(null, $rates);
00217     }


Member Data Documentation

$_ctc = array() [protected]

Definition at line 35 of file Calculation.php.

$_ptc = array() [protected]

Definition at line 36 of file Calculation.php.

$_rateCache = array() [protected]

Definition at line 38 of file Calculation.php.

$_rateCalculationProcess = array() [protected]

Definition at line 39 of file Calculation.php.

$_rates = array() [protected]

Definition at line 34 of file Calculation.php.


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

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