Current file: htdocs/app/code/community/Chapagain/AutoCurrency/Model/Store.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 / 2 CRAP
0.00%0.00%
0.00% 0 / 13
 
Chapagain_AutoCurrency_Model_Store
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 2
0.00%0.00%
0.00% 0 / 13
 getDefaultCurrencyCode()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getCurrencyCodeByIp($result = '')
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 11


       1                 : <?php                                                                                         
       2                 : /**                                                                                           
       3                 :  * Rewrites Mage_Core_Model_Store                                                             
       4                 :  * Returns currency code based on visitor's IP Address                                        
       5                 :  *                                                                                            
       6                 :  * @category   Chapagain                                                                      
       7                 :  * @package    Chapagain_AutoCurrency                                                         
       8                 :  * @version    0.1.0                                                                          
       9                 :  * @author     Mukesh Chapagain <mukesh.chapagain@gmail.com>                                  
      10                 :  * @link        http://blog.chapagain.com.np/category/magento/                                
      11                 :  */                                                                                           
      12                 :                                                                                               
      13                 : class Chapagain_AutoCurrency_Model_Store extends Mage_Core_Model_Store                        
      14                 : {                                                                                             
      15                 :     /**                                                                                       
      16                 :      * Update default store currency code                                                     
      17                 :      *                                                                                        
      18                 :      * @return string                                                                         
      19                 :      */                                                                                       
      20                 :     public function getDefaultCurrencyCode()                                                  
      21                 :     {                                                                                         
      22               0 :         $result = $this->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT); 
      23                 :                                                                                               
      24               0 :         return $this->getCurrencyCodeByIp($result);                                           
      25                 :     }                                                                                         
      26                 :                                                                                               
      27                 :     /**                                                                                       
      28                 :      * Get Currency code by IP Address                                                        
      29                 :      *                                                                                        
      30                 :      * @return string                                                                         
      31                 :      */                                                                                       
      32                 :     public function getCurrencyCodeByIp($result = '')                                         
      33                 :     {                                                                                         
      34                 :         // load GeoIP binary data file                                                        
      35               0 :         $geoIp = Mage::helper('autocurrency')->loadGeoIp();                                   
      36                 :                                                                                               
      37               0 :         $ipAddress = Mage::helper('autocurrency')->getIpAddress();                            
      38                 :                                                                                               
      39                 :         // get country code from ip address                                                   
      40               0 :         $countryCode = geoip_country_code_by_addr($geoIp, $ipAddress);                        
      41                 :                                                                                               
      42               0 :         if($countryCode == '') {                                                              
      43               0 :             return $result;                                                                   
      44                 :         }                                                                                     
      45                 :                                                                                               
      46                 :         // get currency code from country code                                                
      47               0 :         $currencyCode = geoip_currency_code_by_country_code($geoIp, $countryCode);            
      48                 :                                                                                               
      49                 :         // close the geo database                                                             
      50               0 :         geoip_close($geoIp);                                                                  
      51                 :                                                                                               
      52                 :         // if currencyCode is not present in allowedCurrencies                                
      53                 :         // then return the default currency code                                              
      54               0 :         $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
      55               0 :         if(!in_array($currencyCode, $allowedCurrencies)) {                                    
      56               0 :             return $result;                                                                   
      57                 :         }                                                                                     
      58                 :                                                                                               
      59               0 :         return $currencyCode;                                                                 
      60                 :     }                                                                                         
      61                 : }                                                                                             

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.