Mage_Tax_Model_Mysql4_Setup Class Reference

Inheritance diagram for Mage_Tax_Model_Mysql4_Setup:

Mage_Core_Model_Resource_Setup

List of all members.

Public Member Functions

 convertOldTaxData ()

Protected Member Functions

 _loadTableData ($table)
 _loadOldRates ($oldRateTypes)


Detailed Description

Tax Setup Model

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

Definition at line 32 of file Setup.php.


Member Function Documentation

_loadOldRates ( oldRateTypes  )  [protected]

Definition at line 114 of file Setup.php.

00115     {
00116 
00117         $table = $this->getTable('tax_rate');
00118         $select = $this->_conn->select();
00119         $select->from(array('main_table'=>$table));
00120         foreach ($oldRateTypes as $type){
00121             $id = $type['type_id'];
00122             $select->joinLeft(
00123                         array("data_{$id}"=>$this->getTable('tax_rate_data')),
00124                         "data_{$id}.rate_type_id = {$id} AND data_{$id}.tax_rate_id = main_table.tax_rate_id",
00125                         array("data_{$id}"=>'rate_value')
00126                         );
00127         }
00128         return $this->_conn->fetchAll($select);
00129     }

_loadTableData ( table  )  [protected]

Definition at line 106 of file Setup.php.

00107     {
00108         $table = $this->getTable($table);
00109         $select = $this->_conn->select();
00110         $select->from($table);
00111         return $this->_conn->fetchAll($select);
00112     }

convertOldTaxData (  ) 

Definition at line 34 of file Setup.php.

00035     {
00036         $oldRules = $this->_loadTableData('tax_rule');
00037 
00038         $oldRateTypes = $this->_loadTableData('tax_rate_type');
00039 
00040         $rateById = array();
00041         foreach ($oldRateTypes as $type) {
00042             $rateById[$type['type_id']] = $type['type_name'];
00043         }
00044 
00045         $oldRates = $this->_loadOldRates($oldRateTypes);
00046 
00047         $oldToNewRateIds = array();
00048 
00049         foreach ($oldRates as $rate) {
00050             foreach ($oldRateTypes as $type) {
00051                 if (isset($rate["data_{$type['type_id']}"])) {
00052                     $rateValue = $rate["data_{$type['type_id']}"];
00053                 } else {
00054                     continue;
00055                 }
00056 
00057                 $region = Mage::getModel('directory/region')->load($rate['tax_region_id']);
00058                 $regionName = $region->getCode() ? $region->getCode() : '*';
00059                 $code = "{$rate['tax_country_id']}-{$regionName}-{$rate['tax_postcode']}-{$type['type_name']}";
00060 
00061                 if ($rateValue > 0) {
00062                     $insertData = array(
00063                                         'tax_country_id'=>$rate['tax_country_id'],
00064                                         'tax_region_id'=>$rate['tax_region_id'],
00065                                         'tax_postcode'=>$rate['tax_postcode'],
00066                                         'code'=>$code,
00067                                         'rate'=>$rateValue,
00068                                         );
00069 
00070                     $newRateModel = Mage::getModel('tax/calculation_rate');
00071 
00072                     $newRateModel->setData($insertData)->save();
00073                     $oldToNewRateIds[$rate['tax_rate_id']] = $newRateModel->getId();
00074                     $ratesByType[$type['type_id']][] = $newRateModel->getId();
00075                 }
00076             }
00077         }
00078 
00079         foreach ($oldRules as $rule) {
00080             if (!isset($ratesByType[$rule['tax_rate_type_id']]) || !count($ratesByType[$rule['tax_rate_type_id']])){
00081                 continue;
00082             }
00083 
00084             $customerTaxClasses = array($rule['tax_customer_class_id']);
00085             $productTaxClasses = array($rule['tax_product_class_id']);
00086 
00087             $ctc = Mage::getModel('tax/class')->load($rule['tax_customer_class_id']);
00088             $ptc = Mage::getModel('tax/class')->load($rule['tax_product_class_id']);
00089             $type = $rateById[$rule['tax_rate_type_id']];
00090 
00091             $rates = $ratesByType[$rule['tax_rate_type_id']];
00092             $code = "{$ctc->getClassName()}-{$ptc->getClassName()}-{$type}";
00093 
00094             $ruleData = array(
00095                             'tax_rate'=>$rates,
00096                             'tax_product_class'=>$productTaxClasses,
00097                             'tax_customer_class'=>$customerTaxClasses,
00098                             'code'=>$code,
00099                             'priority'=>1,
00100                             'position'=>1
00101                             );
00102             Mage::getModel('tax/calculation_rule')->setData($ruleData)->save();
00103         }
00104     }


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