ecshop区域连动

来源:互联网 发布:12306手机订票软件 编辑:程序博客网 时间:2024/06/10 06:36

ecshop中的三级地区下拉,已经封装的非常好用了。只需要在PHP文件中声明,然后在模板中调用就可以了。所以在使用ecshop处理区域的时候,相当的好用。

    下面将介绍,如何在注册页面处理三级地区下拉的问题。
    1:PHP中增加下面代码.
    include_once(ROOT_PATH .'includes/lib_transaction.php');
    include_once(ROOT_PATH .'languages/' .$_CFG['lang']. '/shopping_flow.php');
   $smarty->assign('lang', $_LANG);
   
   $smarty->assign('country_list',      get_regions());
   $smarty->assign('shop_province_list', get_regions(1,$_CFG['shop_country']));
  以上是包含了处理地区的ecshop函数get_regions()函数,传入参数,可以返回该级别地区的所有地方名称.
  2:ecshop的smarty模板中,加入以下代码.
   <selecttname="country" id="selCountries_{$sn}"onchange="region.changed(this, 1,'selProvinces_{$sn}')">
      <optionvalue="0">-国家-</option>
      <!-- {foreach from=$country_listitem=country} -->
      <optiontvalue="{$country.region_id}" {if $consignee.country eq$country.region_id}selected{/if}>{$country.region_name}</option>
      <!-- {/foreach}-->
  </selectt>
             
      <selectt name="province"id="selProvinces_{$sn}" onchange="region.changed(this, 2,'selCities_{$sn}')">
      <optionvalue="0">-省份-</optiont>
      <!-- {foreachfrom=$province_list.$sn item=province} -->
      <optionvalue="{$province.region_id}" {if $consignee.province eq$province.region_id}selected{/if}>{$province.region_name}</option>
      <!-- {/foreach}-->
      </selectt>
      <selectt name="city"id="selCities_{$sn}" onchange="region.changed(this, 3,'selDistricts_{$sn}')">
      <optiontvalue="0">-城市-</optiont>
      <!-- {foreach from=$city_list.$snitem=city} -->
      <optiont value="{$city.region_id}"{if $consignee.city eq$city.region_id}selected{/if}>{$city.region_name}</option>
      <!-- {/foreach}-->
      </selectt>
      <selectt name="district"id="selDistricts_{$sn}" {if!$district_list.$sn}style="display:none"{/if}>
      <optiontvalue="0">-地区-</option>
      <!-- {foreachfrom=$district_list.$sn item=district} -->
      <optionvalue="{$district.region_id}" {if $consignee.district eq$district.region_id}selected{/if}>{$district.region_name}</option>
      <!-- {/foreach}-->
      </selectt>
       这个是区域选择生成的下拉.
   3:加入需要的JS脚本,用来控制下拉.
    {insert_scriptsfiles='utils.js,transport.js,region.js,shopping_flow.js'}
   最后完成了ECSHOP三级地区下拉的使用。

原文链接:http://sir051223.blog.163.com/blog/static/127585407201284250571/

0 0