Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Tax_Block_Adminhtml_Frontend_Region_Updater
  • Mage_Tax_Block_Checkout_Discount
  • Mage_Tax_Block_Checkout_Grandtotal
  • Mage_Tax_Block_Checkout_Shipping
  • Mage_Tax_Block_Checkout_Subtotal
  • Mage_Tax_Block_Checkout_Tax
  • Mage_Tax_Block_Sales_Order_Tax
  • Mage_Tax_Helper_Data
  • Mage_Tax_Model_Calculation
  • Mage_Tax_Model_Calculation_Rate
  • Mage_Tax_Model_Calculation_Rate_Title
  • Mage_Tax_Model_Calculation_Rule
  • Mage_Tax_Model_Class
  • Mage_Tax_Model_Class_Source_Customer
  • Mage_Tax_Model_Class_Source_Product
  • Mage_Tax_Model_Config
  • Mage_Tax_Model_Config_Price_Include
  • Mage_Tax_Model_Mysql4_Calculation
  • Mage_Tax_Model_Mysql4_Calculation_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rate
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Title
  • Mage_Tax_Model_Mysql4_Calculation_Rate_Title_Collection
  • Mage_Tax_Model_Mysql4_Calculation_Rule
  • Mage_Tax_Model_Mysql4_Calculation_Rule_Collection
  • Mage_Tax_Model_Mysql4_Class
  • Mage_Tax_Model_Mysql4_Class_Collection
  • Mage_Tax_Model_Mysql4_Report_Collection
  • Mage_Tax_Model_Mysql4_Report_Tax
  • Mage_Tax_Model_Mysql4_Report_Updatedat_Collection
  • Mage_Tax_Model_Mysql4_Sales_Order_Tax
  • Mage_Tax_Model_Mysql4_Sales_Order_Tax_Collection
  • Mage_Tax_Model_Mysql4_Setup
  • Mage_Tax_Model_Observer
  • Mage_Tax_Model_Resource_Calculation
  • Mage_Tax_Model_Resource_Calculation_Collection
  • Mage_Tax_Model_Resource_Calculation_Rate
  • Mage_Tax_Model_Resource_Calculation_Rate_Collection
  • Mage_Tax_Model_Resource_Calculation_Rate_Title
  • Mage_Tax_Model_Resource_Calculation_Rate_Title_Collection
  • Mage_Tax_Model_Resource_Calculation_Rule
  • Mage_Tax_Model_Resource_Calculation_Rule_Collection
  • Mage_Tax_Model_Resource_Class
  • Mage_Tax_Model_Resource_Class_Collection
  • Mage_Tax_Model_Resource_Report_Collection
  • Mage_Tax_Model_Resource_Report_Tax
  • Mage_Tax_Model_Resource_Report_Tax_Createdat
  • Mage_Tax_Model_Resource_Report_Tax_Updatedat
  • Mage_Tax_Model_Resource_Report_Updatedat_Collection
  • Mage_Tax_Model_Resource_Sales_Order_Tax
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Collection
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Item
  • Mage_Tax_Model_Resource_Sales_Order_Tax_Item_Collection
  • Mage_Tax_Model_Resource_Setup
  • Mage_Tax_Model_Sales_Order_Tax
  • Mage_Tax_Model_Sales_Order_Tax_Item
  • Mage_Tax_Model_Sales_Pdf_Grandtotal
  • Mage_Tax_Model_Sales_Pdf_Shipping
  • Mage_Tax_Model_Sales_Pdf_Subtotal
  • Mage_Tax_Model_Sales_Pdf_Tax
  • Mage_Tax_Model_Sales_Total_Quote_Discount
  • Mage_Tax_Model_Sales_Total_Quote_Nominal_Subtotal
  • Mage_Tax_Model_Sales_Total_Quote_Nominal_Tax
  • Mage_Tax_Model_Sales_Total_Quote_Shipping
  • Mage_Tax_Model_Sales_Total_Quote_Subtotal
  • Mage_Tax_Model_Sales_Total_Quote_Tax
  • Mage_Tax_Model_System_Config_Source_Algorithm
  • Mage_Tax_Model_System_Config_Source_Apply
  • Mage_Tax_Model_System_Config_Source_PriceType
  • Mage_Tax_Model_System_Config_Source_Tax_Country
  • Mage_Tax_Model_System_Config_Source_Tax_Display_Type
  • Mage_Tax_Model_System_Config_Source_Tax_Region

Exceptions

  • Mage_Tax_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Tax
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: class Mage_Tax_Model_Sales_Total_Quote_Shipping extends Mage_Sales_Model_Quote_Address_Total_Abstract
 29: {
 30:     /**
 31:      * Tax calculation model
 32:      *
 33:      * @var Mage_Tax_Model_Calculation
 34:      */
 35:     protected $_calculator = null;
 36: 
 37:     /**
 38:      * Tax configuration object
 39:      *
 40:      * @var Mage_Tax_Model_Config
 41:      */
 42:     protected $_config = null;
 43: 
 44:     /**
 45:      * Flag which is initialized when collect method is started and catalog prices include tax.
 46:      * It is used for checking if store tax and customer tax requests are similar
 47:      *
 48:      * @var bool
 49:      */
 50:     protected $_areTaxRequestsSimilar = false;
 51: 
 52:     /**
 53:      * Request which can be used for tax rate calculation
 54:      *
 55:      * @var Varien_Object
 56:      */
 57:     protected $_storeTaxRequest = null;
 58: 
 59:     /**
 60:      * Class constructor
 61:      */
 62:     public function __construct()
 63:     {
 64:         $this->setCode('shipping');
 65:         $this->_calculator  = Mage::getSingleton('tax/calculation');
 66:         $this->_config      = Mage::getSingleton('tax/config');
 67:     }
 68: 
 69:     /**
 70:      * Collect totals information about shipping
 71:      *
 72:      * @param   Mage_Sales_Model_Quote_Address $address
 73:      * @return  Mage_Sales_Model_Quote_Address_Total_Shipping
 74:      */
 75:     public function collect(Mage_Sales_Model_Quote_Address $address)
 76:     {
 77:         parent::collect($address);
 78:         $calc               = $this->_calculator;
 79:         $store              = $address->getQuote()->getStore();
 80:         $storeTaxRequest    = $calc->getRateOriginRequest($store);
 81:         $addressTaxRequest  = $calc->getRateRequest(
 82:             $address,
 83:             $address->getQuote()->getBillingAddress(),
 84:             $address->getQuote()->getCustomerTaxClassId(),
 85:             $store
 86:         );
 87: 
 88:         $shippingTaxClass = $this->_config->getShippingTaxClass($store);
 89:         $storeTaxRequest->setProductClassId($shippingTaxClass);
 90:         $addressTaxRequest->setProductClassId($shippingTaxClass);
 91: 
 92:         $priceIncludesTax = $this->_config->shippingPriceIncludesTax($store);
 93:         if ($priceIncludesTax) {
 94:             $this->_areTaxRequestsSimilar = $calc->compareRequests($addressTaxRequest, $storeTaxRequest);
 95:         }
 96: 
 97:         $shipping           = $taxShipping = $address->getShippingAmount();
 98:         $baseShipping       = $baseTaxShipping = $address->getBaseShippingAmount();
 99:         $rate               = $calc->getRate($addressTaxRequest);
100:         if ($priceIncludesTax) {
101:             if ($this->_areTaxRequestsSimilar) {
102:                 $tax            = $this->_round($calc->calcTaxAmount($shipping, $rate, true, false), $rate, true);
103:                 $baseTax        = $this->_round($calc->calcTaxAmount($baseShipping, $rate, true, false), $rate, true, 'base');
104:                 $taxShipping    = $shipping;
105:                 $baseTaxShipping= $baseShipping;
106:                 $shipping       = $shipping - $tax;
107:                 $baseShipping   = $baseShipping - $baseTax;
108:                 $taxable        = $taxShipping;
109:                 $baseTaxable    = $baseTaxShipping;
110:                 $isPriceInclTax = true;
111:             } else {
112:                 $storeRate      = $calc->getStoreRate($addressTaxRequest, $store);
113:                 $storeTax       = $calc->calcTaxAmount($shipping, $storeRate, true, false);
114:                 $baseStoreTax   = $calc->calcTaxAmount($baseShipping, $storeRate, true, false);
115:                 $shipping       = $calc->round($shipping - $storeTax);
116:                 $baseShipping   = $calc->round($baseShipping - $baseStoreTax);
117:                 $tax            = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false);
118:                 $baseTax        = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base');
119:                 $taxShipping    = $shipping + $tax;
120:                 $baseTaxShipping= $baseShipping + $baseTax;
121:                 $taxable        = $shipping;
122:                 $baseTaxable    = $baseShipping;
123:                 $isPriceInclTax = false;
124:             }
125:         } else {
126:             $tax            = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, false);
127:             $baseTax        = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, false, 'base');
128:             $taxShipping    = $shipping + $tax;
129:             $baseTaxShipping= $baseShipping + $baseTax;
130:             $taxable        = $shipping;
131:             $baseTaxable    = $baseShipping;
132:             $isPriceInclTax = false;
133:         }
134:         $address->setTotalAmount('shipping', $shipping);
135:         $address->setBaseTotalAmount('shipping', $baseShipping);
136:         $address->setShippingInclTax($taxShipping);
137:         $address->setBaseShippingInclTax($baseTaxShipping);
138:         $address->setShippingTaxable($taxable);
139:         $address->setBaseShippingTaxable($baseTaxable);
140:         $address->setIsShippingInclTax($isPriceInclTax);
141:         if ($this->_config->discountTax($store)) {
142:             $address->setShippingAmountForDiscount($taxShipping);
143:             $address->setBaseShippingAmountForDiscount($baseTaxShipping);
144:         }
145:         return $this;
146:     }
147: 
148:     /**
149:      * Round price based on tax rounding settings
150:      *
151:      * @param float $price
152:      * @param string $rate
153:      * @param bool $direction
154:      * @param string $type
155:      * @return float
156:      */
157:     protected function _round($price, $rate, $direction, $type = 'regular')
158:     {
159:         if (!$price) {
160:             return $this->_calculator->round($price);
161:         }
162: 
163:         $deltas = $this->_address->getRoundingDeltas();
164:         $key = $type.$direction;
165:         $rate = (string) $rate;
166:         $delta = isset($deltas[$key][$rate]) ? $deltas[$key][$rate] : 0;
167:         return $this->_calculator->round($price+$delta);
168:     }
169: 
170: 
171: 
172: 
173: 
174: 
175: 
176: 
177: 
178: 
179: 
180: 
181: 
182:     /**
183:      * Get request for fetching store tax rate
184:      *
185:      * @deprecated after 1.4.0.0
186:      * @param   Mage_Sales_Model_Quote_Address $address
187:      * @return  Varien_Object
188:      */
189:     protected function _getStoreTaxRequest($address)
190:     {
191:         if (is_null($this->_storeTaxRequest)) {
192:             $this->_storeTaxRequest = $this->_calculator->getRateOriginRequest($address->getQuote()->getStore());
193:         }
194:         return $this->_storeTaxRequest;
195:     }
196: 
197:     /**
198:      * Get request for fetching address tax rate
199:      *
200:      * @deprecated after 1.4.0.0
201:      * @param   Mage_Sales_Model_Quote_Address $address
202:      * @return  Varien_Object
203:      */
204:     protected function _getAddressTaxRequest($address)
205:     {
206:         $addressTaxRequest = $this->_calculator->getRateRequest(
207:             $address,
208:             $address->getQuote()->getBillingAddress(),
209:             $address->getQuote()->getCustomerTaxClassId(),
210:             $address->getQuote()->getStore()
211:         );
212:         return $addressTaxRequest;
213:     }
214: 
215:     /**
216:      * Check if we need subtract store tax amount from shipping
217:      *
218:      * @deprecated after 1.4.0.0
219:      * @param Mage_Sales_Model_Quote_Address $address
220:      * @return bool
221:      */
222:     protected function _needSubtractShippingTax($address)
223:     {
224:         $store = $address->getQuote()->getStore();
225:         if ($this->_config->shippingPriceIncludesTax($store) || $this->_config->getNeedUseShippingExcludeTax()) {
226:             return true;
227:         }
228:         return false;
229:     }
230: 
231:     /**
232:      * Calculate shipping price without store tax
233:      *
234:      * @deprecated after 1.4.0.0
235:      * @param   Mage_Sales_Model_Quote_Address $address
236:      * @return  Mage_Tax_Model_Sales_Total_Quote_Subtotal
237:      */
238:     protected function _processShippingAmount($address)
239:     {
240:     }
241: }
242: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0