Home >php教程 >php手册 >Zencart country sorting and Chinese name expansion

Zencart country sorting and Chinese name expansion

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-09-11 11:19:37906browse

The final effect is as above

Specific steps:

1. Modify the data table manually or with SQL and add 2 fields

<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. Modify the admin/countries.php file and add the form insertion editing function. There are 7 places in total. The specific code is ignored here.

3. Later, we need to modify two functions for obtaining the country drop-down list (one for the front and backend respectively)

#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>

Final effect

If there is no special need, the background function does not need to be modified.

   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn