2011-03-29 13 views

Respuesta

24
$regionModel = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode); 
$regionId = $regionModel->getId(); 
1

Obtenga la colección de todos los estados/regiones relacionados con el país específico.

/** 
* Get region collection 
* @param string $countryCode 
* @return array 
*/ 
public function getRegionCollection($countryCode) 
{ 
    $regionCollection = Mage::getModel('directory/region_api')->items($countryCode); 
    return $regionCollection; 
} 

Rellene la lista de regiones con la colección de regiones. El código de país (por ejemplo, NL, NP, EN) se pasa como parámetro a la función getRegionCollection.

$regionCollection = $this->getRegionCollection($countryCode); 

<select name='customer[region]' id='customer:region' class="validate-select" > 
    <option>Please select region, state or province</option> 
    <?php 
     foreach($regionCollection as $region) { 
      ?> 
      <option value="<?php echo $region['name'] ?>" ><?php echo $region['name'] ?></option> 
      <?php 
     } 
    ?> 

</select> 
0

Esto se trabaja para mí.

<div class="field"> 
        <label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label> 
        <div class="input-box"> 
         <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select"> 
          <option value=""><?php echo $this->__('Please select region, state or province') ?></option> 
         <?php       
         $regions = Mage::getModel('directory/country')->load('US')->getRegions(); 
         foreach($regions as $region) 
         { 
          echo "<option value=$region[name]>".$region['name'] . "</option>"; 
         } 
         ?> 

        </select>      

        </div> 
       </div> 
Cuestiones relacionadas