0

我希望你们一切都好

我在 magento 1.6.0.1 中工作。我当前的站点仅适用于美国,因此在注册页面中不需要国家下拉列表,并且必须在州下拉列表中显示所有美国州。

现在我在隐藏字段中设置国家值“美国”。

那么我怎样才能在州下拉列表中获得所有美国州

4

3 回答 3

2

在 register.phtml 中添加它以显示美国的所有州:

                <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
                    $this->setData('country_id','US'); // or 'FR'..., default is 'US'
                    $regions     =   $this->getRegionCollection();
                    foreach($regions as $region)
                    {
                        echo "<option value=$region[name]>".$region['name'] . "</option>";
                    }
                    ?>

                        </select>
                        <script type="text/javascript">
                        //<![CDATA[
                            $('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
                        //]]>
                        </script>

                        <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('region') ?>" style="display:none;"   />
                    </div>
                </div>
            </li>
            <li class="fields">
                  <div class="field">
                    <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
                    <div class="input-box">
                        <?php echo $this->getCountryHtmlSelect() ?>
                    </div>
                </div>

并将底部javascript替换为:

  <script type="text/javascript">
        var dataForm = new VarienForm('form-validate', true);
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    </script>

希望它会有所帮助

于 2013-04-12T07:50:30.277 回答
0

来自Magento 的国家和地区

 <script type="text/javascript">
        var dataForm = new VarienForm('form-validate', true);
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
    </script>
于 2014-06-24T11:42:20.440 回答
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>
于 2015-05-26T06:21:51.900 回答