Mage_Tax_Model_Observer Class Reference

List of all members.

Public Member Functions

 salesEventConvertQuoteAddressToOrder (Varien_Event_Observer $observer)
 salesEventOrderAfterSave (Varien_Event_Observer $observer)
 prepareCatalogIndexPriceSelect (Varien_Event_Observer $observer)
 addTaxPercentToProductCollection ($observer)


Detailed Description

Tax Event Observer

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

Definition at line 32 of file Observer.php.


Member Function Documentation

addTaxPercentToProductCollection ( observer  ) 

Add tax percent values to product collection items

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Tax_Model_Observer

Definition at line 130 of file Observer.php.

00131     {
00132         $helper = Mage::helper('tax');
00133         $collection = $observer->getEvent()->getCollection();
00134         $store = $collection->getStoreId();
00135         if (!$helper->needPriceConversion($store)) {
00136             return $this;
00137         }
00138 
00139         if ($collection->requireTaxPercent()) {
00140             $request = Mage::getSingleton('tax/calculation')->getRateRequest();
00141             foreach ($collection as $item) {
00142                 if (null === $item->getTaxClassId()) {
00143                     $item->setTaxClassId($item->getMinimalTaxClassId());
00144                 }
00145                 if (!isset($classToRate[$item->getTaxClassId()])) {
00146                     $request->setProductClassId($item->getTaxClassId());
00147                     $classToRate[$item->getTaxClassId()] = Mage::getSingleton('tax/calculation')->getRate($request);
00148                 }
00149                 $item->setTaxPercent($classToRate[$item->getTaxClassId()]);
00150             }
00151 
00152         }
00153         return $this;
00154     }

prepareCatalogIndexPriceSelect ( Varien_Event_Observer observer  ) 

Prepare select which is using to select index data for layered navigation

Parameters:
Varien_Event_Observer $observer
Returns:
Mage_Tax_Model_Observer

Definition at line 103 of file Observer.php.

00104     {
00105         $table = $observer->getEvent()->getTable();
00106         $response = $observer->getEvent()->getResponseObject();
00107         $select = $observer->getEvent()->getSelect();
00108         $storeId = $observer->getEvent()->getStoreId();
00109 
00110         $additionalCalculations = $response->getAdditionalCalculations();
00111         $calculation = Mage::helper('tax')->getPriceTaxSql(
00112             $table . '.value', 'IFNULL(tax_class_c.value, tax_class_d.value)'
00113         );
00114 
00115         if (!empty($calculation)) {
00116             $additionalCalculations[] = $calculation;
00117             $response->setAdditionalCalculations($additionalCalculations);
00118             Mage::helper('tax')->joinTaxClass($select, $storeId, $table);
00119         }
00120 
00121         return $this;
00122     }

salesEventConvertQuoteAddressToOrder ( Varien_Event_Observer observer  ) 

Put quote address tax information into order

Parameters:
Varien_Event_Observer $observer

Definition at line 39 of file Observer.php.

00040     {
00041         $address = $observer->getEvent()->getAddress();
00042         $order = $observer->getEvent()->getOrder();
00043 
00044         $taxes = $address->getAppliedTaxes();
00045         if (is_array($taxes)) {
00046             if (is_array($order->getAppliedTaxes())) {
00047                 $taxes = array_merge($order->getAppliedTaxes(), $taxes);
00048             }
00049             $order->setAppliedTaxes($taxes);
00050             $order->setConvertingFromQuote(true);
00051         }
00052     }

salesEventOrderAfterSave ( Varien_Event_Observer observer  ) 

Save order tax information

Parameters:
Varien_Event_Observer $observer

Definition at line 59 of file Observer.php.

00060     {
00061         $order = $observer->getEvent()->getOrder();
00062         if (!$order->getConvertingFromQuote()) {
00063             return;
00064         }
00065 
00066         $taxes = $order->getAppliedTaxes();
00067         foreach ($taxes as $row) {
00068             foreach ($row['rates'] as $tax) {
00069                 if (is_null($row['percent'])) {
00070                     $baseRealAmount = $row['base_amount'];
00071                 } else {
00072                     if ($row['percent'] == 0 || $tax['percent'] == 0) {
00073                         continue;
00074                     }
00075                     $baseRealAmount = $row['base_amount']/$row['percent']*$tax['percent'];
00076                 }
00077                 $hidden = (isset($row['hidden']) ? $row['hidden'] : 0);
00078                 $data = array(
00079                             'order_id'=>$order->getId(),
00080                             'code'=>$tax['code'],
00081                             'title'=>$tax['title'],
00082                             'hidden'=>$hidden,
00083                             'percent'=>$tax['percent'],
00084                             'priority'=>$tax['priority'],
00085                             'position'=>$tax['position'],
00086                             'amount'=>$row['amount'],
00087                             'base_amount'=>$row['base_amount'],
00088                             'process'=>$row['process'],
00089                             'base_real_amount'=>$baseRealAmount,
00090                             );
00091 
00092                 Mage::getModel('sales/order_tax')->setData($data)->save();
00093             }
00094         }
00095     }


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

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