如何以編程方式從2個字符的狀態縮寫中獲取Magento中的region_id?如果這很重要,我使用Magento 1.4.2。獲取region_id來自州縮寫 - Magento 1.4.2
11
A
回答
24
$regionModel = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode);
$regionId = $regionModel->getId();
1
獲取與特定國家相關的所有州/地區的集合。
/**
* Get region collection
* @param string $countryCode
* @return array
*/
public function getRegionCollection($countryCode)
{
$regionCollection = Mage::getModel('directory/region_api')->items($countryCode);
return $regionCollection;
}
使用區域集合填充區域列表。國家代碼(例如NL,NP,EN)作爲參數傳遞給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
這是爲我工作。
<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>
相關問題
- 1. 州名縮寫爲R
- 2. Magento的1.4.2 - 在CMS
- 3. 來自Java 1.4.2的Http Post?
- 4. 德爾福 - 有沒有更好的方式來獲得州名縮寫
- 5. 州名到縮寫使用R
- 6. 獲取所有美國州下拉列表中的magento註冊
- 7. XSLT:獲取月份縮寫
- 8. 正在獲取Magento縮略圖
- 9. Magento獲取產品重寫URL
- 10. 獲取來自城市和州/省或郵政編碼的時區偏移量
- 11. 獲取來自json_decode
- 12. 獲取來自json_decode()
- 13. Magento從1.4.2更新到1.5.1錯誤
- 14. 的產品數量在Magento 1.4.2
- 15. Magento的1.4.2 - 註冊字段不要求
- 16. 取決於來自另一個州的數據的動作
- 17. magento使用來自aheadworks的博客
- 18. 如何獲取時區的縮寫?
- 19. iPhone - MKReverseGeocoder.adminstrativeArea - 獲取狀態縮寫
- 20. 獲取在Magento
- 21. 無壓縮捕獲UIImage(來自CMSampleBufferRef)?
- 22. 自動縮寫JLabel
- 23. 自動填寫在Magento
- 24. MKPlacemark:在AdministrativeArea中返回美國州名縮寫
- 25. 爲國家獲取重複的州名
- 26. 按州和名稱獲取作業?
- 27. 在.NET中獲取州和省
- 28. 獲取州/省和國家的時區?
- 29. 從geonames數據獲取州/省?
- 30. C#獲取來自網站