I am new to magento and I am not able to make out how one can remove the unwanted states from dropdown list in magento. I tried to edit my below function as per this link http://doejo.com/blog/magento-how-to-remove-certain-states-from-state-region-list-at-checkout-or-registration/ but it did not work. Below i sthe code for removing unwanted states but when I add to my class in local folder, not getting any results.
$excludeRegions = array('AE','AA'); foreach ($collection as $region) { if (!$region->getRegionId()) { continue; } ***//Here is the code from the link given //BOF Custom Logic Here*** $regionCode = $region->getCode(); $this->_select->from(array('region'=>$this->_regionTable), array('region_id'=>'region_id', 'country_id'=>'country_id', 'code'=>'code', 'default_name'=>'default_name') )->where('code NOT IN (?)', $exclude_regions);
_getRegions
function edited as per above code and link respectively.
protected function _getRegions($storeId) { $countryIds = array(); $countryCollection = $this->getCountryCollection()->loadByStore($storeId); foreach ($countryCollection as $country) { $countryIds[] = $country->getCountryId(); } /** @var $regionModel Mage_Directory_Model_Region */ $regionModel = $this->_factory->getModel('directory/region'); /** @var $collection Mage_Directory_Model_Resource_Region_Collection */ $collection = $regionModel->getResourceCollection() ->addCountryFilter($countryIds) ->load(); $regions = array( 'config' => array( 'show_all_regions' => $this->getShowNonRequiredState(), 'regions_required' => $this->getCountriesWithStatesRequired() ) ); $excludeRegions = array('AE','AA'); foreach ($collection as $region) { if (!$region->getRegionId()) { continue; } ***//Here is the code from the link given //BOF Custom Logic Here*** $regionCode = $region->getCode(); $this->_select->from(array('region'=>$this->_regionTable), array('region_id'=>'region_id', 'country_id'=>'country_id', 'code'=>'code', 'default_name'=>'default_name') )->where('code NOT IN (?)', $exclude_regions); //EOF Custom Logic Here $regions[$region->getCountryId()][$region->getRegionId()] = array( 'code' => $region->getCode(), 'name' => $this->__($region->getName()) ); } return $regions; }
After making the above changes, I tried below steps as my code is in /app/code/core/Mage/Directory/Helper/Data.php
Vids_Directory
in pool local
like app/code/local/Vids/Directory
app/etc/modules/Vids_Directory.xml
app/code/local/Vids/Directory/etc/config.xml
app/code/local/Vids/Helper/Data.php
答案 0 :(得分:1)
从Region下拉列表中删除不需要的状态的一种更简单但不推荐的方法是转到“directory_country_region”表并删除要删除的所有States ID。更好的方法是进行以下更改。
所以最终的代码是
$excludeRegions = array('AK','AS','AF','AA','AC','AE','AM','AP','DC','FM','GU','HI','MH','MP','PW','PR','VI');
foreach ($collection as $region) {
if (!$region->getRegionId()) {
continue;
}
//BOF Custom Logic Here
$regionCode = $region->getCode();
if (in_array($regionCode, $excludeRegions)) {
continue;
}
//EOF Custom Logic Here
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
'name' => $this->__($region->getName())
);
}
来源: http://www.demagento.com/magento-how-to-remove-unwanted-states-from-stateregion-list-at-checkout/