如何在 Opencart 的管理员中添加客户区域/州列?

How to add Customer Region / State column in admin for Opencart?

我正在为 OC 2.0.1.1 苦苦挣扎,只在管理端添加了一个区域/州列。我为客户城市找到了一个免费的 vqmod 模块。它使用城市数据完美运行。我什至尝试为 Region-State 进行修改,但无法成功。 在我的国家,我们更多地使用区域而不是城市,而我被困在这里。任何帮助都是金子。 这是我要修改的 vqmod 模块:

    <?xml version="1.0" encoding="UTF-8"?>
<modification>
   <id><![CDATA[<font color="#000000"><b>Customer Cities in Admin</b></font>]]></id>
   <version><![CDATA[1.0<br><b>OC:2.0.3.1</b>]]></version>
   <vqmver><![CDATA[2.5.1]]></vqmver>
   <author><![CDATA[<font color="#0C9603"><b>aljawaid</font><br><font color="#0C9603"><a href="mailto:aljawaid@hotmail.co.uk">aljawaid@hotmail.co.uk</a></font>]]></author>
   <comment><![CDATA[ THIS FILE IS PROVIDED AS-IS WITHOUT ANY WARRANTY OR SUPPORT ]]></comment>

   <!-- THIS EXTENSION WILL SHOW THE CUSTOMER'S SAVED CITIES IN THE CUSTOMER LIST - USEFUL IF ONLY DELIVERING TO ONE COUNTRY -->
   <!-- THIS EXTENSION IS INSPIRED BY: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=21191 -->

<file name="admin/controller/sale/customer.php">

    <operation info="ADD TO CONTROLLER" error="log">
      <search position="before"><![CDATA[
        'ip'             => $result['ip'],
      ]]></search>
      <add><![CDATA[
        'city'        => $result['city'],
      ]]></add>
    </operation>

</file>

<file name="admin/model/sale/customer.php">

    <operation info="ADD TO MODEL" error="log">
        <search position="replace"><![CDATA[
            $sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (c.customer_group_id = cgd.customer_group_id) WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
        ]]></search>
        <add><![CDATA[
            $sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group ,
                (
                    SELECT GROUP_CONCAT(ctty.city,'=',ctty.city)
                    FROM " . DB_PREFIX . "address addr 
                    LEFT JOIN " . DB_PREFIX . "address ctty 
                    ON (addr.city = ctty.city) 
                    WHERE addr.customer_id = c.customer_id
                ) as city
                    FROM " . DB_PREFIX . "customer c 
                    LEFT JOIN " . DB_PREFIX . "customer_group_description cgd 
                    ON (c.customer_group_id = cgd.customer_group_id)
                    WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
        ]]></add>
    </operation>

</file>

<file name="admin/view/template/sale/customer_list.tpl">
    <operation info="ADD COLUMN TITLE" error="log">
        <search position="before"><![CDATA[
            <td class="text-left"><?php if ($sort == 'customer_group') { ?>
        ]]></search>
        <add><![CDATA[
            <td style="font-weight:normal;" class="text-left">Location(s)</td>
        ]]></add>
    </operation>

<!-- IF CUSTOMER HAS MULTIPLE LOCATIONS SAVED IN THEIR ADDRESS BOOK, THEN ALL CITIES WILL BE SHOWN -->
<!-- IF CUSTOMER HAS NO ADDRESS THEN "NO ADDRESS" WILL BE SHOWN -->
    <operation info="ADD SAVED CITY FOR EACH CUSTOMER" error="log">
        <search position="before"><![CDATA[
            <td class="text-left"><?php echo $customer['customer_group']; ?></td>
        ]]></search>
        <add><![CDATA[          
            <td style="text-align: left;">
            <?php 
                $get_city = explode(',',$customer['city']);
                foreach($get_city as $i =>$key) {
                    //echo $i.' '.$key .'</br>';
                    $separate = explode('=',$key);
                    $city_name = $separate[0];
            ?>

                <span><?php if ($city_name) { ?> <i class="fa fa-map-marker" data-toggle="tooltip" data-placement="left" title="Saved in customer's address book"></i>
                <?php } 
                else { ?><span style="font-style:italic; color:red;" data-toggle="tooltip" data-placement="right" title="This customer has not saved any addresses yet">No address</span>
                <?php } ?>
                <?php echo $city_name; ?></span><br>                
            <?php } ?>
            </td>           
        ]]></add>
    </operation>
</file>     

</modification>

您可以为每个客户获取区域,然后 echotpl 文件中:

$zones = $this->db->query("SELECT zone_id FROM " . DB_PREFIX . "address WHERE customer_id = '" . $result['customer_id'] . "'" );
$zone_info = array();
foreach($zones->rows as $zone){
    $zone_info[] = $this->model_localisation_zone->getZone($zone['zone_id'])['name'];
}
$data['customers'][] = array(
    'zone'        => $zone_info,

我已经创建了一个 vqmod 文件:

<?xml version="1.0" encoding="UTF-8"?>
<modification>
   <id>Display customer zone in admin customer list</id>
   <version>1</version>
   <vqmver>2.x</vqmver>
   <author>Mojtaba Sabeti</author>

<file name="admin/controller/sale/customer.php">
    <operation error="log">
      <search position="after"><![CDATA[$results = $this->model_sale_customer->getCustomers($filter_data);]]></search>
      <add><![CDATA[
        $this->load->model('localisation/zone');
      ]]></add>
    </operation>
    <operation error="log">
      <search position="replace"><![CDATA[$data['customers'][] = array(]]></search>
      <add><![CDATA[
            $zones = $this->db->query("SELECT zone_id FROM " . DB_PREFIX . "address WHERE customer_id = '" . $result['customer_id'] . "'" );
            $zone_info = array();
            foreach($zones->rows as $zone){
                $zone_info[] = $this->model_localisation_zone->getZone($zone['zone_id'])['name'];
            }
            $data['customers'][] = array(
                'zone'        => $zone_info,
      ]]></add>
    </operation>
</file>

<file name="admin/view/template/sale/customer_list.tpl">
    <operation error="log">
        <search position="before"><![CDATA[
            <td class="text-left"><?php if ($sort == 'customer_group') { ?>
        ]]></search>
        <add><![CDATA[
            <td style="font-weight:normal;" class="text-left">Zones</td>
        ]]></add>
    </operation>

    <operation error="log">
        <search position="before"><![CDATA[
            <td class="text-left"><?php echo $customer['customer_group']; ?></td>
        ]]></search>
        <add><![CDATA[          
            <td style="text-align: left;">
            <?php
                foreach($customer['zone'] as $zone){
                    echo "<div>$zone</div>";
                }
            ?>
            </td>
        ]]></add>
    </operation>
</file>     

</modification>