Wednesday 7 August 2013

How to exclude/Remove state from shipping in magento


Go to /app/code/core/Mage/Directory/Helper/data.php
Overwrite the default function with this

public function getRegionJson()
{
$exclude_regions = array ('AL','NJ','NY','CT','AS','AK','AA'); //this is the code of excluded state

Varien_Profiler::start('TEST: '.__METHOD__);
if (!$this->_regionJson) {
$cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId();
if (Mage::app()->useCache('config')) {
$json = Mage::app()->loadCache($cacheKey);
}
if (empty($json)) {
$countryIds = array();
foreach ($this->getCountryCollection() as $country) {
$countryIds[] = $country->getCountryId();
}
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->load();
$regions = array();
foreach ($collection as $region) {

$rg = $region->getCode();

//if ($rg!=’AL’){
if(!in_array($rg, $exclude_regions)) {

if (!$region->getRegionId()) {
continue;
}
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
//’name’ => $region->getName()
'name' => $this->__($region->getName())
);
}

}
$json = Mage::helper('core')->jsonEncode($regions);

if (Mage::app()->useCache('config')) {
Mage::app()->saveCache($json, $cacheKey, array('config'));
}
}
$this->_regionJson = $json;
}

Varien_Profiler::stop('TEST: '.__METHOD__);
return $this->_regionJson;
}

No comments:

Post a Comment