如何以編程方式從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. 從region_id獲取狀態名稱Magento 1.6.2
- 2. 州名縮寫爲R
- 3. Magento的1.4.2 - 在CMS
- 4. 來自Java 1.4.2的Http Post?
- 5. Geonames自動完成城市/州,返回完整的州名不是縮寫
- 6. Magento從1.4.2更新到1.7
- 7. 獲取與Magento的版本當前類別1.4.2
- 8. 德爾福 - 有沒有更好的方式來獲得州名縮寫
- 9. 州名到縮寫使用R
- 10. 得到2個字母州/省縮寫
- 11. 獲取所有美國州下拉列表中的magento註冊
- 12. XSLT:獲取月份縮寫
- 13. NSTimezone從timezoneId獲取縮寫
- 14. 正在獲取Magento縮略圖
- 15. URL重寫 - 不是來自.htaccess - Magento
- 16. Magento 1.4.2在CentOS上上傳HTTP錯誤
- 17. Magento獲取產品重寫URL
- 18. 獲取來自城市和州/省或郵政編碼的時區偏移量
- 19. 在Magento 1.4.2中添加自定義客戶屬性
- 20. Magento的1.4.2 - 註冊字段不要求
- 21. Magento從1.4.2更新到1.5.1錯誤
- 22. 的產品數量在Magento 1.4.2
- 23. 的Magento從1.4.2升級問題1.6
- 24. 獲取來自json_decode
- 25. 獲取來自json_decode()
- 26. 取決於來自另一個州的數據的動作
- 27. Magento子html - 獲取父母來電
- 28. 根據所選國家獲取州的州名單
- 29. SUBSTR在angularJS獲取全名的縮寫
- 30. 如何從Time.now獲取時區縮寫?