Current file: htdocs/app/code/core/Mage/Tax/Model/Mysql4/Setup.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 3 CRAP
0.00%0.00%
0.00% 0 / 66
 
Mage_Tax_Model_Mysql4_Setup
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 66
 convertOldTaxData()
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 17
Functions
  
   
0.00%0.00%
0.00% 0 / 2
100.00%100.00%
100.00% 0 / 0
 _loadTableData($table)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4
 _loadOldRates($oldRateTypes)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 8


       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) 2010 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 Setup Resource Model                                                                                          
      29                 :  *                                                                                                                   
      30                 :  * @category    Mage                                                                                                 
      31                 :  * @package     Mage_Tax                                                                                             
      32                 :  * @author      Magento Core Team <core@magentocommerce.com>                                                         
      33                 :  */                                                                                                                  
      34                 : class Mage_Tax_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup                                              
      35                 : {                                                                                                                    
      36                 :     /**                                                                                                              
      37                 :      * Convert old Tax data                                                                                          
      38                 :      *                                                                                                               
      39                 :      */                                                                                                              
      40                 :     public function convertOldTaxData()                                                                              
      41                 :     {                                                                                                                
      42               0 :         $oldRules = $this->_loadTableData('tax_rule');                                                               
      43                 :                                                                                                                      
      44               0 :         $oldRateTypes = $this->_loadTableData('tax_rate_type');                                                      
      45                 :                                                                                                                      
      46               0 :         $rateById = array();                                                                                         
      47               0 :         foreach ($oldRateTypes as $type) {                                                                           
      48               0 :             $rateById[$type['type_id']] = $type['type_name'];                                                        
      49               0 :         }                                                                                                            
      50                 :                                                                                                                      
      51               0 :         $oldRates = $this->_loadOldRates($oldRateTypes);                                                             
      52                 :                                                                                                                      
      53               0 :         $oldToNewRateIds = array();                                                                                  
      54                 :                                                                                                                      
      55               0 :         foreach ($oldRates as $rate) {                                                                               
      56               0 :             foreach ($oldRateTypes as $type) {                                                                       
      57               0 :                 if (isset($rate["data_{$type['type_id']}"])) {                                                       
      58               0 :                     $rateValue = $rate["data_{$type['type_id']}"];                                                   
      59               0 :                 } else {                                                                                             
      60               0 :                     continue;                                                                                        
      61                 :                 }                                                                                                    
      62                 :                                                                                                                      
      63               0 :                 $region     = Mage::getModel('directory/region')->load($rate['tax_region_id']);                      
      64               0 :                 $regionName = $region->getCode() ? $region->getCode() : '*';                                         
      65               0 :                 $code       = "{$rate['tax_country_id']}-{$regionName}-{$rate['tax_postcode']}-{$type['type_name']}";
      66                 :                                                                                                                      
      67               0 :                 if ($rateValue > 0) {                                                                                
      68                 :                     $insertData = array(                                                                             
      69               0 :                         'tax_country_id'    => $rate['tax_country_id'],                                              
      70               0 :                         'tax_region_id'     => $rate['tax_region_id'],                                               
      71               0 :                         'tax_postcode'      => $rate['tax_postcode'],                                                
      72               0 :                         'code'              => $code,                                                                
      73               0 :                         'rate'              => $rateValue,                                                           
      74               0 :                     );                                                                                               
      75                 :                                                                                                                      
      76               0 :                     $newRateModel = Mage::getModel('tax/calculation_rate');                                          
      77                 :                                                                                                                      
      78               0 :                     $newRateModel->setData($insertData)->save();                                                     
      79               0 :                     $oldToNewRateIds[$rate['tax_rate_id']] = $newRateModel->getId();                                 
      80               0 :                     $ratesByType[$type['type_id']][] = $newRateModel->getId();                                       
      81               0 :                 }                                                                                                    
      82               0 :             }                                                                                                        
      83               0 :         }                                                                                                            
      84                 :                                                                                                                      
      85               0 :         foreach ($oldRules as $rule) {                                                                               
      86               0 :             if (!isset($ratesByType[$rule['tax_rate_type_id']]) || !count($ratesByType[$rule['tax_rate_type_id']])) {
      87               0 :                 continue;                                                                                            
      88                 :             }                                                                                                        
      89                 :                                                                                                                      
      90               0 :             $customerTaxClasses = array($rule['tax_customer_class_id']);                                             
      91               0 :             $productTaxClasses = array($rule['tax_product_class_id']);                                               
      92                 :                                                                                                                      
      93               0 :             $ctc    = Mage::getModel('tax/class')->load($rule['tax_customer_class_id']);                             
      94               0 :             $ptc    = Mage::getModel('tax/class')->load($rule['tax_product_class_id']);                              
      95               0 :             $type   = $rateById[$rule['tax_rate_type_id']];                                                          
      96                 :                                                                                                                      
      97               0 :             $rates  = $ratesByType[$rule['tax_rate_type_id']];                                                       
      98               0 :             $code   = "{$ctc->getClassName()}-{$ptc->getClassName()}-{$type}";                                       
      99                 :                                                                                                                      
     100                 :             $ruleData = array(                                                                                       
     101               0 :                 'tax_rate'              => $rates,                                                                   
     102               0 :                 'tax_product_class'     => $productTaxClasses,                                                       
     103               0 :                 'tax_customer_class'    => $customerTaxClasses,                                                      
     104               0 :                 'code'                  => $code,                                                                    
     105               0 :                 'priority'              => 1,                                                                        
     106                 :                 'position'              => 1                                                                         
     107               0 :             );                                                                                                       
     108               0 :             Mage::getModel('tax/calculation_rule')->setData($ruleData)->save();                                      
     109               0 :         }                                                                                                            
     110               0 :     }                                                                                                                
     111                 :                                                                                                                      
     112                 :     /**                                                                                                              
     113                 :      * Load Tax Table Data                                                                                           
     114                 :      *                                                                                                               
     115                 :      * @return array                                                                                                 
     116                 :      */                                                                                                              
     117                 :     protected function _loadTableData($table)                                                                        
     118                 :     {                                                                                                                
     119               0 :         $table = $this->getTable($table);                                                                            
     120               0 :         $select = $this->_conn->select();                                                                            
     121               0 :         $select->from($table);                                                                                       
     122               0 :         return $this->_conn->fetchAll($select);                                                                      
     123                 :     }                                                                                                                
     124                 :                                                                                                                      
     125                 :     /**                                                                                                              
     126                 :      * Load Old Rate Data                                                                                            
     127                 :      *                                                                                                               
     128                 :      * @return array                                                                                                 
     129                 :      */                                                                                                              
     130                 :     protected function _loadOldRates($oldRateTypes)                                                                  
     131                 :     {                                                                                                                
     132               0 :         $table  = $this->getTable('tax_rate');                                                                       
     133               0 :         $select = $this->_conn->select()                                                                             
     134               0 :             ->from(array('main_table'=>$table));                                                                     
     135               0 :         foreach ($oldRateTypes as $type){                                                                            
     136               0 :             $id = $type['type_id'];                                                                                  
     137               0 :             $select->joinLeft(                                                                                       
     138               0 :                 array("data_{$id}"=>$this->getTable('tax_rate_data')),                                               
     139               0 :                 "data_{$id}.rate_type_id = {$id} AND data_{$id}.tax_rate_id = main_table.tax_rate_id",               
     140               0 :                 array("data_{$id}"=>'rate_value')                                                                    
     141               0 :             );                                                                                                       
     142               0 :         }                                                                                                            
     143               0 :         return $this->_conn->fetchAll($select);                                                                      
     144                 :     }                                                                                                                
     145                 : }                                                                                                                    

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.4 and PHPUnit 3.5.13 at Tue Jul 5 9:07:16 UTC 2011.