首页 > php教程 > php手册 > 正文

Zencart 国家排序及中文名称的扩展

WBOY
发布: 2016-09-11 11:19:37
原创
872 人浏览过

最终实现效果如上

具体步骤:

1. 手动或SQL修改数据表,增加2个字段

<span style="color: #0000ff;">ALTER</span> <span style="color: #0000ff;">TABLE</span> countries <span style="color: #0000ff;">ADD</span> `countries_name_cn` <span style="color: #0000ff;">VARCHAR</span>( <span style="color: #800000; font-weight: bold;">64</span> ) <span style="color: #0000ff;">NULL</span> <span style="color: #0000ff;">DEFAULT</span> <span style="color: #ff0000;">''</span>, <span style="color: #0000ff;">ADD</span> `order_by` <span style="color: #0000ff;">int</span>(<span style="color: #800000; font-weight: bold;">11</span>) <span style="color: #808080;">NOT</span> <span style="color: #0000ff;">NULL</span> <span style="color: #0000ff;">DEFAULT</span> <span style="color: #ff0000;">'</span><span style="color: #ff0000;">0</span><span style="color: #ff0000;">'</span>;
登录后复制

2. 修改admin/countries.php文件,增加表单插入编辑功能, 共计7处,此处忽略具体代码。

3. 之后还要修改两个获取国家下拉列表的函数(前台后台分别对应一个)

#includes/functions/functions_lookups.php

  <span style="color: #0000ff;">function</span> zen_get_countries(<span style="color: #800080;">$countries_id</span> = '', <span style="color: #800080;">$with_iso_codes</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">) {
    </span><span style="color: #0000ff;">global</span> <span style="color: #800080;">$db</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$countries_array</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
    </span><span style="color: #0000ff;">if</span> (zen_not_null(<span style="color: #800080;">$countries_id</span><span style="color: #000000;">)) {
</span>~
~<span style="color: #000000;">
    } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
      </span><span style="color: #800080;">$countries</span> = "<span style="color: #000000;">select countries_id, countries_name, countries_name_cn
                    from </span>" . TABLE_COUNTRIES . "<span style="color: #000000;">
                    order by order_by, countries_name</span>"<span style="color: #000000;">;

      </span><span style="color: #800080;">$countries_values</span> = <span style="color: #800080;">$db</span>->Execute(<span style="color: #800080;">$countries</span><span style="color: #000000;">);

      </span><span style="color: #0000ff;">while</span> (!<span style="color: #800080;">$countries_values</span>-><span style="color: #000000;">EOF) {
        </span><span style="color: #800080;">$countries_array</span>[] = <span style="color: #0000ff;">array</span>('countries_id' => <span style="color: #800080;">$countries_values</span>->fields['countries_id'],
                                   'countries_name' => <span style="color: #800080;">$countries_values</span>->fields['countries_name']." - ".<span style="color: #800080;">$countries_values</span>->fields['countries_name_cn'<span style="color: #000000;">]);

        </span><span style="color: #800080;">$countries_values</span>-><span style="color: #000000;">MoveNext();
      }
    }

    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$countries_array</span><span style="color: #000000;">;
  }</span>
登录后复制

#admin/includes/functions/general.php

  <span style="color: #0000ff;">function</span> zen_get_countries(<span style="color: #800080;">$default</span> = ''<span style="color: #000000;">) {
    </span><span style="color: #0000ff;">global</span> <span style="color: #800080;">$db</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$countries_array</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
    </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$default</span><span style="color: #000000;">) {
      </span><span style="color: #800080;">$countries_array</span>[] = <span style="color: #0000ff;">array</span>('id' => '',
                                 'text' => <span style="color: #800080;">$default</span><span style="color: #000000;">);
    }
    </span><span style="color: #800080;">$countries</span> = <span style="color: #800080;">$db</span>->Execute("<span style="color: #000000;">select countries_id, countries_name,countries_name_cn
                               from </span>" . TABLE_COUNTRIES . "<span style="color: #000000;">
                               order by order_by, countries_name</span>"<span style="color: #000000;">);

    </span><span style="color: #0000ff;">while</span> (!<span style="color: #800080;">$countries</span>-><span style="color: #000000;">EOF) {
      </span><span style="color: #800080;">$countries_array</span>[] = <span style="color: #0000ff;">array</span>('id' => <span style="color: #800080;">$countries</span>->fields['countries_id'],
                                 'text' => <span style="color: #800080;">$countries</span>->fields['countries_name']." - ".<span style="color: #800080;">$countries</span>->fields['countries_name_cn'<span style="color: #000000;">]);
      </span><span style="color: #800080;">$countries</span>-><span style="color: #000000;">MoveNext();
    }

    </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$countries_array</span><span style="color: #000000;">;
  }</span>
登录后复制

最终效果

如果不是特别需要,后台函数也可不修改。

   
登录后复制

 

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板