-
-
Save fritids/5604293 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Created on Sep 28, 2009 | |
* @author Neill Russell <[email protected]> | |
*/ | |
if($argc < 2) die(sprintf("Usage: %s <MAGENTO_ROOT>\n", $_SERVER['SCRIPT_FILENAME'])); | |
define('MAGENTO_DIR', realpath($argv[1])); | |
$app_dir = MAGENTO_DIR . '/app'; | |
if ( ! file_exists($app_dir) ) { die("Can't find Magento\n"); } | |
require_once($app_dir . '/Mage.php'); | |
umask(0); | |
Mage::app('admin'); | |
//error_reporting(0); | |
$locale = Mage::getModel('core/locale'); | |
$eu = array( | |
'Austria', | |
'Belgium', | |
'Bulgaria', | |
'Cyprus', | |
'Czech Republic', | |
'Denmark', | |
'Estonia', | |
'Finland', | |
'France', | |
'Germany', | |
'Greece', | |
'Hungary', | |
'Ireland', | |
'Italy', | |
'Latvia', | |
'Lithuania', | |
'Luxembourg', | |
'Malta', | |
'Netherlands', | |
'Poland', | |
'Portugal', | |
'Romania', | |
'Slovakia', | |
'Slovenia', | |
'Spain', | |
'Sweden', | |
'United Kingdom', | |
); | |
$non_eu = array( | |
'Albania', | |
'Andorra', | |
'Armenia', | |
'Azerbaijan', | |
'Belarus', | |
'Bosnia and Herzegovina', | |
'Georgia', | |
'Iceland', | |
'Liechtenstein', | |
'Moldova', | |
'Monaco', | |
'Montenegro', | |
'Norway', | |
'Russia', | |
'San Marino', | |
'Serbia', | |
'Switzerland', | |
'Ukraine', | |
'Vatican', //'Vatican City State', | |
); | |
// get Magento Country Directory | |
$countryCodesToIds = $countryCodesIso2 = array(); | |
$countryCollection = Mage::getResourceModel('directory/country_collection')/*->addCountryCodeFilter($countryCodes)*/->load(); | |
foreach ($countryCollection->getItems() as $country) { | |
$countryCodesToIds[$country->getData('iso3_code')] = $country->getData('country_id'); | |
$countryCodesToIds[$country->getData('iso2_code')] = $country->getData('country_id'); | |
$countryCodesIso2[] = $country->getData('iso2_code'); | |
} | |
// COUNTRIES | |
$translationList = $locale->getCountryTranslationList(); | |
$countries = array(); | |
foreach ($translationList as $code=>$name) { | |
// skip countries not in Magento Directory | |
if(!in_array($code, $countryCodesIso2)) continue; | |
// add to countries array | |
if($code == 'GB') $countries['UK'][$code] = $name; | |
elseif(in_array($name, $eu)) $countries['EU'][$code] = $name; | |
elseif(in_array($name, $non_eu)) $countries['NON-EU'][$code] = $name; | |
elseif($code == 'US') $countries['US'][$code] = $name; | |
else $countries['ROW'][$code] = $name; | |
} | |
$prices=array(); | |
$prices['NON-EU']=array( | |
// weight => price | |
'0'=>0, | |
'0.1'=>1.50, | |
'0.2'=>2.00, | |
'0.3'=>2.50, | |
'0.4'=>3.00, | |
'0.5'=>3.60, | |
'0.6'=>4.20, | |
'0.7'=>4.80, | |
'0.8'=>5.40, | |
'0.9'=>6.00, | |
'1'=>6.60, | |
'1.1'=>7.20, | |
'1.2'=>7.80, | |
'1.3'=>8.40, | |
'1.4'=>9.00, | |
'1.5'=>9.60, | |
'1.6'=>10.20, | |
'1.7'=>10.80, | |
'1.8'=>11.60, | |
'1.9'=>12.20, | |
'2'=>12.80, | |
'2.1'=>30.00, | |
); | |
$prices['EU']=array( | |
// weight => price | |
'0'=>0, | |
'0.1'=>1.50, | |
'0.2'=>2.00, | |
'0.3'=>2.50, | |
'0.4'=>3.00, | |
'0.5'=>3.60, | |
'0.6'=>4.20, | |
'0.7'=>4.80, | |
'0.8'=>5.40, | |
'0.9'=>5.90, | |
'1'=>6.60, | |
'1.1'=>7.20, | |
'1.2'=>7.80, | |
'1.3'=>8.40, | |
'1.4'=>9.00, | |
'1.5'=>9.60, | |
'1.6'=>10.20, | |
'1.7'=>10.80, | |
'1.8'=>11.40, | |
'1.9'=>12.00, | |
'2'=>12.60, | |
'2.1'=>25.50, | |
); | |
$prices['US']=array( | |
// weight => price | |
'0'=>0, | |
'0.1'=>2.00, | |
'0.2'=>3.00, | |
'0.3'=>4.00, | |
'0.4'=>5.00, | |
'0.5'=>6.00, | |
'0.6'=>7.00, | |
'0.7'=>8.00, | |
'0.8'=>9.00, | |
'0.9'=>10.00, | |
'1'=>11.00, | |
'1.1'=>12.10, | |
'1.2'=>13.20, | |
'1.3'=>14.40, | |
'1.4'=>15.50, | |
'1.5'=>16.60, | |
'1.6'=>17.70, | |
'1.7'=>18.80, | |
'1.8'=>19.90, | |
'1.9'=>21.00, | |
'2'=>22.10, | |
'2.1'=>32.00, | |
); | |
$prices['ROW']=array( | |
// weight => price | |
'0'=>0, | |
'0.1'=>2.00, | |
'0.2'=>3.00, | |
'0.3'=>4.10, | |
'0.4'=>5.30, | |
'0.5'=>6.50, | |
'0.6'=>7.60, | |
'0.7'=>8.80, | |
'0.8'=>10.00, | |
'0.9'=>11.20, | |
'1'=>12.30, | |
'1.1'=>13.40, | |
'1.2'=>14.50, | |
'1.3'=>15.60, | |
'1.4'=>16.70, | |
'1.5'=>17.70, | |
'1.6'=>18.80, | |
'1.7'=>19.90, | |
'1.8'=>21.00, | |
'1.9'=>22.10, | |
'2'=>23.20, | |
'2.1'=>38.00, | |
); | |
$prices['UK']=array( | |
// weight => price | |
'0'=>0, | |
'0.06'=>1.50, | |
'0.1'=>1.50, | |
'0.15'=>2.00, | |
'0.2'=>2.00, | |
'0.2'=>6.95, | |
'0.25'=>2.50, | |
'0.3'=>2.50, | |
'0.35'=>2.50, | |
'0.4'=>6.95, | |
'0.4'=>2.50, | |
'0.45'=>2.75, | |
'0.5'=>2.75, | |
'0.6'=>6.95, | |
'0.6'=>2.75, | |
'0.7'=>3.00, | |
'0.75'=>3.25, | |
'0.8'=>6.95, | |
'0.8'=>3.50, | |
'0.9'=>3.50, | |
'1'=>6.95, | |
'1'=>4.95, | |
'1.25'=>5.95, | |
'1.5'=>6.95, | |
'2'=>7.95, | |
); | |
$prices['UK-HIGHLANDS-ISLANDS']=array( | |
// weight => price | |
'0'=>0, | |
'0.06'=>1.50, | |
'0.1'=>1.50, | |
'0.15'=>2.00, | |
'0.2'=>2.00, | |
'0.25'=>2.50, | |
'0.3'=>2.50, | |
'0.35'=>2.50, | |
'0.4'=>6.95, | |
'0.4'=>2.50, | |
'0.45'=>2.75, | |
'0.5'=>2.75, | |
'0.6'=>2.75, | |
'0.7'=>3.00, | |
'0.75'=>3.25, | |
'0.8'=>3.50, | |
'0.9'=>3.50, | |
'1'=>4.95, | |
'10'=>3.00, | |
'20'=>3.00, | |
'30'=>4.00, | |
'40'=>5.00, | |
'50'=>6.00, | |
'60'=>7.00, | |
'70'=>8.00, | |
); | |
/* | |
$prices['UK-NEXTDAY'] = array( | |
'0'=>0, | |
'0.2'=>6.95, | |
'0.4'=>6.95, | |
'0.6'=>6.95, | |
'0.8'=>6.95, | |
'1'=>6.95, | |
'1.5'=>6.95, | |
'2'=>7.95, | |
); | |
*/ | |
echo "Country, Region/State, Zip/Postal Code, Weight (and above), Shipping Price\r\n"; | |
foreach($countries as $region => $_countries) { | |
foreach($_countries as $code => $country) { | |
foreach($prices[$region] as $threshold => $price) { | |
//printf("%s, *, *, %s, %s, %s, %s\n", $code, $threshold, $price, $country, $region); | |
printf("%s, *, *, %s, %s\n", $code, $threshold, $price); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment