Magento Questions Answered By Magento Experts

 

Welcome Guest. Sign in or Signup

4 Answers

How do I remove certain States from state/region list at Checkout or registration in magento 1.6

Asked by: 1431 views , ,
Questions

In Magento 1.5 I was using a local modified version of Collection.php to exclude certain states from the drop down list to determine the shipping state as well as the state drop down to add new addresses.  The file was located in Mage > Directory > Model > Mysql4 > Region.

Now in Magento 1.6 this is broken. Is there now a more straight forward way to exclude states? Or is there a different file that I need to copy to my local folder and modify now? Any help would be greatly appreciated.

Thank You.

4 Answers



  1. Magento Developers on Sep 08, 2011 Reply

    Hi Jay,
    We provide Magento 1.6 Upgrade Services. we can certainly help you out in upgrading your store to 1.6 version.

    Visit Us:
    http://www.expertmagentodevelopers.com

    or email us at
    sales@expertmagentodevelopers.com

    -3 Votes Thumb up 1 Votes Thumb down 4 Votes

  2. Best Answer


    ArtP on Jan 27, 2012 Reply

    In Magento 1.5
    #1 copy app/code/core/Mage/Directory/Helper to local folder
    l/app/code/local/Mage/Directory/

    #2 in Data.php

    replace getRegionJson with code below

    public function getRegionJson()
    {
    $exclude_regions = array (‘AL’,'NJ’,'NY’,'CT’,'AS’,'AK’,'AA’,'AC’,'AE’,'AK’,'AM’,'AP’,'FM’,'GU’,'HI’,'MH’,'MP’,'PW’,'PR’,'VI’,'AF’);

    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;
    }

    +5 Votes Thumb up 5 Votes Thumb down 0 Votes



  3. ArtP on Jan 27, 2012 Reply

    This code is for 1.6 not for 1.5

    Arthur

    +2 Votes Thumb up 2 Votes Thumb down 0 Votes



  4. OneMouseRevolt on Feb 01, 2013 Reply

    Thanks ArtP! That worked like a charm!

    0 Votes Thumb up 0 Votes Thumb down 0 Votes


Answer Question