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:  * Tax Event Observer
 29:  *
 30:  * @author Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Tax_Model_Observer
 33: {
 34:     /**
 35:      * Put quote address tax information into order
 36:      *
 37:      * @param Varien_Event_Observer $observer
 38:      */
 39:     public function salesEventConvertQuoteAddressToOrder(Varien_Event_Observer $observer)
 40:     {
 41:         $address = $observer->getEvent()->getAddress();
 42:         $order = $observer->getEvent()->getOrder();
 43: 
 44:         $taxes = $address->getAppliedTaxes();
 45:         if (is_array($taxes)) {
 46:             if (is_array($order->getAppliedTaxes())) {
 47:                 $taxes = array_merge($order->getAppliedTaxes(), $taxes);
 48:             }
 49:             $order->setAppliedTaxes($taxes);
 50:             $order->setConvertingFromQuote(true);
 51:         }
 52:     }
 53: 
 54:     /**
 55:      * Save order tax information
 56:      *
 57:      * @param Varien_Event_Observer $observer
 58:      */
 59:     public function salesEventOrderAfterSave(Varien_Event_Observer $observer)
 60:     {
 61:         $order = $observer->getEvent()->getOrder();
 62: 
 63:         if (!$order->getConvertingFromQuote() || $order->getAppliedTaxIsSaved()) {
 64:             return;
 65:         }
 66: 
 67:         $getTaxesForItems   = $order->getQuote()->getTaxesForItems();
 68:         $taxes              = $order->getAppliedTaxes();
 69: 
 70:         $ratesIdQuoteItemId = array();
 71:         if (!is_array($getTaxesForItems)) {
 72:             $getTaxesForItems = array();
 73:         }
 74:         foreach ($getTaxesForItems as $quoteItemId => $taxesArray) {
 75:             foreach ($taxesArray as $rates) {
 76:                 if (count($rates['rates']) == 1) {
 77:                     $ratesIdQuoteItemId[$rates['id']][] = array(
 78:                         'id'        => $quoteItemId,
 79:                         'percent'   => $rates['percent'],
 80:                         'code'      => $rates['rates'][0]['code']
 81:                     );
 82:                 } else {
 83:                     $percentDelta   = $rates['percent'];
 84:                     $percentSum     = 0;
 85:                     foreach ($rates['rates'] as $rate) {
 86:                         $ratesIdQuoteItemId[$rates['id']][] = array(
 87:                             'id'        => $quoteItemId,
 88:                             'percent'   => $rate['percent'],
 89:                             'code'      => $rate['code']
 90:                         );
 91:                         $percentSum += $rate['percent'];
 92:                     }
 93: 
 94:                     if ($percentDelta != $percentSum) {
 95:                         $delta = $percentDelta - $percentSum;
 96:                         foreach ($ratesIdQuoteItemId[$rates['id']] as &$rateTax) {
 97:                             if ($rateTax['id'] == $quoteItemId) {
 98:                                 $rateTax['percent'] = (($rateTax['percent'] / $percentSum) * $delta)
 99:                                         + $rateTax['percent'];
100:                             }
101:                         }
102:                     }
103:                 }
104:             }
105:         }
106: 
107:         foreach ($taxes as $id => $row) {
108:             foreach ($row['rates'] as $tax) {
109:                 if (is_null($row['percent'])) {
110:                     $baseRealAmount = $row['base_amount'];
111:                 } else {
112:                     if ($row['percent'] == 0 || $tax['percent'] == 0) {
113:                         continue;
114:                     }
115:                     $baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
116:                 }
117:                 $hidden = (isset($row['hidden']) ? $row['hidden'] : 0);
118:                 $data = array(
119:                     'order_id'          => $order->getId(),
120:                     'code'              => $tax['code'],
121:                     'title'             => $tax['title'],
122:                     'hidden'            => $hidden,
123:                     'percent'           => $tax['percent'],
124:                     'priority'          => $tax['priority'],
125:                     'position'          => $tax['position'],
126:                     'amount'            => $row['amount'],
127:                     'base_amount'       => $row['base_amount'],
128:                     'process'           => $row['process'],
129:                     'base_real_amount'  => $baseRealAmount,
130:                 );
131: 
132:                 $result = Mage::getModel('tax/sales_order_tax')->setData($data)->save();
133: 
134:                 if (isset($ratesIdQuoteItemId[$id])) {
135:                     foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
136:                         if ($quoteItemId['code'] == $tax['code']) {
137:                             $item = $order->getItemByQuoteItemId($quoteItemId['id']);
138:                             if ($item) {
139:                                 $data = array(
140:                                     'item_id'       => $item->getId(),
141:                                     'tax_id'        => $result->getTaxId(),
142:                                     'tax_percent'   => $quoteItemId['percent']
143:                                 );
144:                                 Mage::getModel('tax/sales_order_tax_item')->setData($data)->save();
145:                             }
146:                         }
147:                     }
148:                 }
149:             }
150:         }
151: 
152:         $order->setAppliedTaxIsSaved(true);
153:     }
154: 
155:     /**
156:      * Prepare select which is using to select index data for layered navigation
157:      *
158:      * @param   Varien_Event_Observer $observer
159:      * @return  Mage_Tax_Model_Observer
160:      */
161:     public function prepareCatalogIndexPriceSelect(Varien_Event_Observer $observer)
162:     {
163:         $table = $observer->getEvent()->getTable();
164:         $response = $observer->getEvent()->getResponseObject();
165:         $select = $observer->getEvent()->getSelect();
166:         $storeId = $observer->getEvent()->getStoreId();
167: 
168:         $additionalCalculations = $response->getAdditionalCalculations();
169:         $calculation = Mage::helper('tax')->getPriceTaxSql(
170:             $table . '.min_price', $table.'.tax_class_id'
171:         );
172: 
173:         if (!empty($calculation)) {
174:             $additionalCalculations[] = $calculation;
175:             $response->setAdditionalCalculations($additionalCalculations);
176:             /**
177:              * Tax class presented in price index table
178:              */
179:             //Mage::helper('tax')->joinTaxClass($select, $storeId, $table);
180:         }
181: 
182:         return $this;
183:     }
184: 
185:     /**
186:      * Add tax percent values to product collection items
187:      *
188:      * @param   Varien_Event_Observer $observer
189:      * @return  Mage_Tax_Model_Observer
190:      */
191:     public function addTaxPercentToProductCollection($observer)
192:     {
193:         $helper = Mage::helper('tax');
194:         $collection = $observer->getEvent()->getCollection();
195:         $store = $collection->getStoreId();
196:         if (!$helper->needPriceConversion($store)) {
197:             return $this;
198:         }
199: 
200:         if ($collection->requireTaxPercent()) {
201:             $request = Mage::getSingleton('tax/calculation')->getRateRequest();
202:             foreach ($collection as $item) {
203:                 if (null === $item->getTaxClassId()) {
204:                     $item->setTaxClassId($item->getMinimalTaxClassId());
205:                 }
206:                 if (!isset($classToRate[$item->getTaxClassId()])) {
207:                     $request->setProductClassId($item->getTaxClassId());
208:                     $classToRate[$item->getTaxClassId()] = Mage::getSingleton('tax/calculation')->getRate($request);
209:                 }
210:                 $item->setTaxPercent($classToRate[$item->getTaxClassId()]);
211:             }
212: 
213:         }
214:         return $this;
215:     }
216: 
217:     /**
218:      * Refresh sales tax report statistics for last day
219:      *
220:      * @param Mage_Cron_Model_Schedule $schedule
221:      * @return Mage_Tax_Model_Observer
222:      */
223:     public function aggregateSalesReportTaxData($schedule)
224:     {
225:         Mage::app()->getLocale()->emulate(0);
226:         $currentDate = Mage::app()->getLocale()->date();
227:         $date = $currentDate->subHour(25);
228:         Mage::getResourceModel('tax/report_tax')->aggregate($date);
229:         Mage::app()->getLocale()->revert();
230:         return $this;
231:     }
232: 
233:     /**
234:      * Reset extra tax amounts on quote addresses before recollecting totals
235:      *
236:      * @param Varien_Event_Observer $observer
237:      * @return Mage_Tax_Model_Observer
238:      */
239:     public function quoteCollectTotalsBefore(Varien_Event_Observer $observer)
240:     {
241:         /* @var $quote Mage_Sales_Model_Quote */
242:         $quote = $observer->getEvent()->getQuote();
243:         foreach ($quote->getAllAddresses() as $address) {
244:             $address->setExtraTaxAmount(0);
245:             $address->setBaseExtraTaxAmount(0);
246:         }
247:         return $this;
248:     }
249: }
250: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0