添加国家&在magento的时事通讯中的州/省领域

时间:2013-01-07 06:38:19

标签: magento-1.7

我想展示国家和地区时事通讯中的州领域。 对于国家,我使用了这个编码: -

<?php $_countries = Mage::getResourceModel('directory/country_collection')
                                ->loadData()
                                ->toOptionArray(false) ?>
 <?php if (count($_countries) > 0): ?>
                       <label for="country"><?php echo $this->__('Country') ?></label>
                           <select name="country" id="newsletter">
                                <option value="">-- Please Select --</option>
                                 <?php foreach($_countries as $_country): ?>
                                    <option value="<?php echo $_country['value'] ?>">
                                                    <?php echo $_country['label'] ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                 <?php endif; ?>

显示国家/地区列表但我还想显示基于所选国家/地区的状态下拉列表。如果未定义state,则它将显示默认magento功能的文本框。 我试试这段代码: -

<div class="input-box">
                            <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                            </select>
                            <script type="text/javascript">
                            //<![CDATA[
                                $('region_id').setAttribute('defaultValue', "<?php echo $this->getAddress()->getRegionId() ?>");
                            //]]>
                            </script>
                            <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getAddress()->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;" />
                        </div>

但它显示错误。 任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:1)

我得到了解决方案: - 国家下拉应该是: -

 <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>

和州应该是这样的: -

 <label for="state"><em>*</em><?php echo $this->__('State/Province') ?></label>
                         <select style="" title="State/Province" name="region_id" id="region_id" defaultvalue="" class="required-entry validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                         </select>
                   <script type="text/javascript">
                   //<![CDATA[
                       $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                   //]]>
                   </script>
                   <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />

脚本是: -

 <script type="text/javascript">
    //<![CDATA[
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    //]]>
    </script>
相关问题