Mage_Tax_Helper_Data Class Reference

Inheritance diagram for Mage_Tax_Helper_Data:

Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 getProductPrice ($product, $format=null)
 priceIncludesTax ($store=null)
 applyTaxAfterDiscount ($store=null)
 getIncExcText ($flag, $store=null)
 getPriceDisplayType ($store=null)
 needPriceConversion ($store=null)
 displayFullSummary ($store=null)
 displayZeroTax ($store=null)
 displayCartPriceInclTax ($store=null)
 displayCartPriceExclTax ($store=null)
 displayCartBothPrices ($store=null)
 displayTaxColumn ($store=null)
 getPriceFormat ($store=null)
 getTaxRatesByProductClass ()
 getPrice ($product, $price, $includingTax=null, $shippingAddress=null, $billingAddress=null, $ctc=null, $store=null, $priceIncludesTax=null)
 displayPriceIncludingTax ()
 displayPriceExcludingTax ()
 displayBothPrices ()
 getIncExcTaxLabel ($flag)
 shippingPriceIncludesTax ($store=null)
 getShippingPriceDisplayType ($store=null)
 displayShippingPriceIncludingTax ()
 displayShippingPriceExcludingTax ()
 displayShippingBothPrices ()
 getShippingTaxClass ($store)
 getShippingPrice ($price, $includingTax=null, $shippingAddress=null, $ctc=null, $store=null)
 getPriceTaxSql ($priceField, $taxClassField)
 joinTaxClass ($select, $storeId, $priceTable='main_table')
 discountTax ($store=null)
 getTaxBasedOn ($store=null)
 applyTaxOnCustomPrice ($store=null)
 applyTaxOnOriginalPrice ($store=null)

Public Attributes

const PRICE_CONVERSION_PLUS = 1
const PRICE_CONVERSION_MINUS = 2

Protected Member Functions

 _calculatePrice ($price, $percent, $type)

Protected Attributes

 $_displayTaxColumn
 $_taxData
 $_priceIncludesTax
 $_shippingPriceIncludesTax
 $_applyTaxAfterDiscount
 $_priceDisplayType
 $_shippingPriceDisplayType


Detailed Description

Catalog data helper

Definition at line 30 of file Data.php.


Member Function Documentation

_calculatePrice ( price,
percent,
type 
) [protected]

Definition at line 370 of file Data.php.

00371     {
00372         $store = Mage::app()->getStore();
00373         if ($type) {
00374             return $price * (1+($percent/100));
00375         } else {
00376             return $price - ($price/(100+$percent)*$percent);
00377         }
00378     }

applyTaxAfterDiscount ( store = null  ) 

Check what taxes should be applied after discount

Parameters:
mixed $store
Returns:
bool

Definition at line 81 of file Data.php.

00082     {
00083         $storeId = Mage::app()->getStore($store)->getId();
00084         if (!isset($this->_applyTaxAfterDiscount[$storeId])) {
00085             $this->_applyTaxAfterDiscount[$storeId] = (int)Mage::getStoreConfig(
00086                 Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT,
00087                 $store
00088             );
00089         }
00090         return $this->_applyTaxAfterDiscount[$storeId];
00091     }

applyTaxOnCustomPrice ( store = null  ) 

Definition at line 515 of file Data.php.

00515                                                          {
00516         return ((int) Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store) == 0);
00517     }

applyTaxOnOriginalPrice ( store = null  ) 

Definition at line 519 of file Data.php.

00519                                                            {
00520         return ((int) Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store) == 1);
00521     }

discountTax ( store = null  ) 

Definition at line 505 of file Data.php.

00506     {
00507         return ((int)Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DISCOUNT_TAX, $store) == 1);
00508     }

displayBothPrices (  ) 

Definition at line 365 of file Data.php.

00366     {
00367         return $this->getPriceDisplayType() == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH;
00368     }

displayCartBothPrices ( store = null  ) 

Check if need display cart prices excluding and including tax

Parameters:
mixed $store
Returns:
bool

Definition at line 215 of file Data.php.

00216     {
00217         return $this->displayTaxColumn($store) == Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH;
00218     }

displayCartPriceExclTax ( store = null  ) 

Check if need display cart prices excluding price

Parameters:
mixed $store
Returns:
bool

Definition at line 204 of file Data.php.

00205     {
00206         return $this->displayTaxColumn($store) == Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX;
00207     }

displayCartPriceInclTax ( store = null  ) 

Check if need display cart prices included tax

Parameters:
mixed $store
Returns:
bool

Definition at line 193 of file Data.php.

00194     {
00195         return $this->displayTaxColumn($store) == Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX;
00196     }

displayFullSummary ( store = null  ) 

Check if need display full tax summary information in totals block

Parameters:
mixed $store
Returns:
bool

Definition at line 171 of file Data.php.

00172     {
00173         return ((int)Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DISPLAY_FULL_SUMMARY, $store) == 1);
00174     }

displayPriceExcludingTax (  ) 

Definition at line 360 of file Data.php.

displayPriceIncludingTax (  ) 

Definition at line 355 of file Data.php.

displayShippingBothPrices (  ) 

Definition at line 417 of file Data.php.

displayShippingPriceExcludingTax (  ) 

Definition at line 412 of file Data.php.

displayShippingPriceIncludingTax (  ) 

Definition at line 407 of file Data.php.

displayTaxColumn ( store = null  ) 

Check if need display tax column in for shopping cart/order items

Parameters:
mixed $store
Returns:
bool

Definition at line 226 of file Data.php.

00227     {
00228         if (is_null($this->_displayTaxColumn)) {
00229             $this->_displayTaxColumn = (int)Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DISPLAY_TAX_COLUMN, $store);
00230         }
00231         return $this->_displayTaxColumn;
00232     }

displayZeroTax ( store = null  ) 

Check if need display zero tax in subtotal

Parameters:
mixed $store
Returns:
bool

Definition at line 182 of file Data.php.

getIncExcTaxLabel ( flag  ) 

Definition at line 380 of file Data.php.

00381     {
00382         $text = $this->getIncExcText($flag);
00383         return $text ? ' <span class="tax-flag">('.$text.')</span>' : '';
00384     }

getIncExcText ( flag,
store = null 
)

Output

Parameters:
boolean $includes

Definition at line 98 of file Data.php.

00099     {
00100         if ($flag) {
00101             $s = $this->__('Incl. Tax');
00102         } else {
00103             $s = $this->__('Excl. Tax');
00104         }
00105         return $s;
00106     }

getPrice ( product,
price,
includingTax = null,
shippingAddress = null,
billingAddress = null,
ctc = null,
store = null,
priceIncludesTax = null 
)

Get product price with all tax settings processing

Parameters:
Mage_Catalog_Model_Product $product
float $price inputed product price
bool $includingTax return price include tax flag
null|Mage_Customer_Model_Address $shippingAddress
null|Mage_Customer_Model_Address $billingAddress
null|int $ctc customer tax class
mixed $store
bool $priceIncludesTax flag what price parameter contain tax
Returns:
float

Definition at line 280 of file Data.php.

00281     {
00282         $store = Mage::app()->getStore($store);
00283         if (!$this->needPriceConversion($store)) {
00284             return $store->roundPrice($price);
00285         }
00286         if (is_null($priceIncludesTax)) {
00287             $priceIncludesTax = $this->priceIncludesTax($store);
00288         }
00289 
00290         $percent = $product->getTaxPercent();
00291         $includingPercent = null;
00292 
00293         $taxClassId = $product->getTaxClassId();
00294         if (is_null($percent)) {
00295             if ($taxClassId) {
00296                 $request = Mage::getSingleton('tax/calculation')->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
00297                 $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
00298             }
00299         }
00300         if ($taxClassId && $priceIncludesTax) {
00301             $request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false, $store);
00302             $includingPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
00303         }
00304 
00305         if ($percent === false || is_null($percent)) {
00306             if ($priceIncludesTax && !$includingPercent) {
00307                 return $price;
00308             }
00309         }
00310 
00311         $product->setTaxPercent($percent);
00312 
00313         if (!is_null($includingTax)) {
00314             if ($priceIncludesTax) {
00315                 if ($includingTax) {
00316                     $price = $this->_calculatePrice($price, $includingPercent, false);
00317                     $price = $this->_calculatePrice($price, $percent, true);
00318                 } else {
00319                     $price = $this->_calculatePrice($price, $includingPercent, false);
00320                 }
00321             } else {
00322                 if ($includingTax) {
00323                     $price = $this->_calculatePrice($price, $percent, true);
00324                 }
00325             }
00326         } else {
00327             if ($priceIncludesTax) {
00328                 switch ($this->getPriceDisplayType($store)) {
00329                     case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
00330                     case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
00331                         $price = $this->_calculatePrice($price, $includingPercent, false);
00332                         break;
00333 
00334                     case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
00335                         $price = $this->_calculatePrice($price, $includingPercent, false);
00336                         $price = $this->_calculatePrice($price, $percent, true);
00337                         break;
00338                 }
00339             } else {
00340                 switch ($this->getPriceDisplayType($store)) {
00341                     case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
00342                         $price = $this->_calculatePrice($price, $percent, true);
00343                         break;
00344 
00345                     case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
00346                     case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
00347                         break;
00348                 }
00349             }
00350         }
00351 
00352         return $store->roundPrice($price);
00353     }

getPriceDisplayType ( store = null  ) 

Get product price display tax 1 - Excluding tax 2 - Including tax 3 - Both

Parameters:
mixed $store
Returns:
int

Definition at line 117 of file Data.php.

00118     {
00119         $storeId = Mage::app()->getStore($store)->getId();
00120         if (!isset($this->_priceDisplayType[$storeId])) {
00121             $this->_priceDisplayType[$storeId] = (int)Mage::getStoreConfig(
00122                 Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE,
00123                 $store
00124             );
00125         }
00126         return $this->_priceDisplayType[$storeId];
00127     }

getPriceFormat ( store = null  ) 

Get prices javascript format json

Parameters:
mixed $store
Returns:
string

Definition at line 240 of file Data.php.

00241     {
00242         return Zend_Json::encode(Mage::app()->getLocale()->getJsPriceFormat());
00243     }

getPriceTaxSql ( priceField,
taxClassField 
)

Definition at line 439 of file Data.php.

00440     {
00441         if (!$this->priceIncludesTax() && $this->displayPriceExcludingTax()) {
00442             return '';
00443         }
00444 
00445         $request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false);
00446         $defaultTaxes = Mage::getSingleton('tax/calculation')->getRatesForAllProductTaxClasses($request);
00447 
00448         $request = Mage::getSingleton('tax/calculation')->getRateRequest();
00449         $currentTaxes = Mage::getSingleton('tax/calculation')->getRatesForAllProductTaxClasses($request);
00450 
00451         $defaultTaxString = $currentTaxString = '';
00452 
00453         $rateToVariable = array(
00454                             'defaultTaxString'=>'defaultTaxes',
00455                             'currentTaxString'=>'currentTaxes',
00456                             );
00457         foreach ($rateToVariable as $rateVariable=>$rateArray) {
00458             if ($$rateArray && is_array($$rateArray)) {
00459                 $$rateVariable = '';
00460                 foreach ($$rateArray as $classId=>$rate) {
00461                     if ($rate) {
00462                         $$rateVariable .= "WHEN '{$classId}' THEN '".($rate/100)."'";
00463                     }
00464                 }
00465                 if ($$rateVariable) {
00466                     $$rateVariable = "CASE {$taxClassField} {$$rateVariable} ELSE 0 END";
00467                 }
00468             }
00469         }
00470 
00471         $result = '';
00472 
00473         if ($this->priceIncludesTax()) {
00474             if ($defaultTaxString) {
00475                 $result  = "-({$priceField}/(1+({$defaultTaxString}))*{$defaultTaxString})";
00476             }
00477             if (!$this->displayPriceExcludingTax() && $currentTaxString) {
00478                 $result .= "+(({$priceField}{$result})*{$currentTaxString})";
00479             }
00480         } else {
00481             if ($this->displayPriceIncludingTax()) {
00482                 if ($currentTaxString) {
00483                     $result .= "+({$priceField}*{$currentTaxString})";
00484                 }
00485             }
00486         }
00487         return $result;
00488     }

getProductPrice ( product,
format = null 
)

Definition at line 45 of file Data.php.

00046     {
00047         try {
00048             $value = $product->getPrice();
00049             $value = Mage::app()->getStore()->convertPrice($value, $format);
00050         }
00051         catch (Exception $e){
00052             $value = $e->getMessage();
00053         }
00054         return $value;
00055     }

getShippingPrice ( price,
includingTax = null,
shippingAddress = null,
ctc = null,
store = null 
)

Definition at line 427 of file Data.php.

00427                                                                                                                        {
00428         $pseudoProduct = new Varien_Object();
00429         $pseudoProduct->setTaxClassId($this->getShippingTaxClass($store));
00430 
00431         $billingAddress = false;
00432         if ($shippingAddress && $shippingAddress->getQuote() && $shippingAddress->getQuote()->getBillingAddress()) {
00433             $billingAddress = $shippingAddress->getQuote()->getBillingAddress();
00434         }
00435 
00436         return $this->getPrice($pseudoProduct, $price, $includingTax, $shippingAddress, $billingAddress, $ctc, $store, $this->shippingPriceIncludesTax($store));
00437     }

getShippingPriceDisplayType ( store = null  ) 

Definition at line 396 of file Data.php.

00397     {
00398 
00399         $storeId = Mage::app()->getStore($store)->getId();
00400         if (!isset($this->_shippingPriceDisplayType[$storeId])) {
00401             $this->_shippingPriceDisplayType[$storeId] =
00402                 (int)Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DISPLAY_SHIPPING, $store);
00403         }
00404         return $this->_shippingPriceDisplayType[$storeId];
00405     }

getShippingTaxClass ( store  ) 

Definition at line 422 of file Data.php.

getTaxBasedOn ( store = null  ) 

Definition at line 510 of file Data.php.

getTaxRatesByProductClass (  ) 

Get all tax rates for all product tax classes

array( value_{$productTaxVlassId} => $rate )

Returns:
array

Definition at line 254 of file Data.php.

00255     {
00256         $result = array();
00257         $calc = Mage::getSingleton('tax/calculation');
00258         $rates = $calc->getRatesForAllProductTaxClasses($calc->getRateRequest());
00259 
00260         foreach ($rates as $class=>$rate) {
00261             $result["value_{$class}"] = $rate;
00262         }
00263 
00264         return Zend_Json::encode($result);
00265     }

joinTaxClass ( select,
storeId,
priceTable = 'main_table' 
)

Definition at line 490 of file Data.php.

00491     {
00492         $taxClassAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'tax_class_id');
00493         $select->joinLeft(
00494             array('tax_class_d'=>$taxClassAttribute->getBackend()->getTable()),
00495             "tax_class_d.entity_id = {$priceTable}.entity_id AND tax_class_d.attribute_id = '{$taxClassAttribute->getId()}'
00496             AND tax_class_d.store_id = 0",
00497              array());
00498         $select->joinLeft(
00499             array('tax_class_c'=>$taxClassAttribute->getBackend()->getTable()),
00500             "tax_class_c.entity_id = {$priceTable}.entity_id AND tax_class_c.attribute_id = '{$taxClassAttribute->getId()}'
00501             AND tax_class_c.store_id = '{$storeId}'",
00502             array());
00503     }

needPriceConversion ( store = null  ) 

Check if necessary do product price conversion If it necessary will be returned conversion type (minus or plus)

Parameters:
mixed $store
Returns:
false | int

Definition at line 136 of file Data.php.

00137     {
00138         $res = false;
00139         if ($this->priceIncludesTax($store)) {
00140             switch ($this->getPriceDisplayType($store)) {
00141                 case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
00142                 case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
00143                     return self::PRICE_CONVERSION_MINUS;
00144 
00145                 case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
00146                     $res = false;
00147             }
00148         } else {
00149             switch ($this->getPriceDisplayType($store)) {
00150                 case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
00151                 case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
00152                     return self::PRICE_CONVERSION_PLUS;
00153 
00154                 case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
00155                     $res = false;
00156             }
00157         }
00158 
00159         if ($res === false) {
00160             $res = $this->displayTaxColumn($store);
00161         }
00162         return $res;
00163     }

priceIncludesTax ( store = null  ) 

Check if product prices inputed include tax

Parameters:
mix $store
Returns:
bool

Definition at line 63 of file Data.php.

00064     {
00065         $storeId = Mage::app()->getStore($store)->getId();
00066         if (!isset($this->_priceIncludesTax[$storeId])) {
00067             $this->_priceIncludesTax[$storeId] = (int)Mage::getStoreConfig(
00068                 Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
00069                 $store
00070             );
00071         }
00072         return $this->_priceIncludesTax[$storeId];
00073     }

shippingPriceIncludesTax ( store = null  ) 

Definition at line 386 of file Data.php.

00387     {
00388         $storeId = Mage::app()->getStore($store)->getId();
00389         if (!isset($this->_shippingPriceIncludesTax[$storeId])) {
00390             $this->_shippingPriceIncludesTax[$storeId] =
00391                 (int)Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store);
00392         }
00393         return $this->_shippingPriceIncludesTax[$storeId];
00394     }


Member Data Documentation

$_applyTaxAfterDiscount [protected]

Definition at line 41 of file Data.php.

$_displayTaxColumn [protected]

Definition at line 37 of file Data.php.

$_priceDisplayType [protected]

Definition at line 42 of file Data.php.

$_priceIncludesTax [protected]

Definition at line 39 of file Data.php.

$_shippingPriceDisplayType [protected]

Definition at line 43 of file Data.php.

$_shippingPriceIncludesTax [protected]

Definition at line 40 of file Data.php.

$_taxData [protected]

Definition at line 38 of file Data.php.

Definition at line 33 of file Data.php.

Definition at line 32 of file Data.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