2013-01-07 73 views
0

我想在通訊中顯示國家&州領域。 對於國家,我用這個作弄: -在magento的新聞通訊中添加國家和州/省領域

<?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; ?> 

這表明國家的名單,但我也想根據所選國家&下顯示,如果沒有定義狀態,那麼它會顯示類似默認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

我得到了解決: - 降全國上下應爲: -

<?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> 
相關問題