doupai5450 2016-11-25 13:55
浏览 47
已采纳

如何在admin for Opencart中添加Customer Region / State列?

I'm struggling with OC 2.0.1.1, adding to admin side just a single Region / State column. I found a free vqmod module for customer cities. It's working perfectly using the City data. I even tried to modify for Region-State but could'nt make it. In my country, we use regions more than cities and I'm stuck here. Any help would be a gold. Here is the vqmod module what I'm trying to modify :

    <?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>
  • 写回答

1条回答 默认 最新

  • drt3751 2016-11-26 17:27
    关注

    You can get zones for each customer and then echo it in tpl file:

    $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,
    

    I've create a vqmod file:

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32c8t6工程,使用hal库
  • ¥100 有偿求易语言word文档取doc和docx页数方法或模块
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低
  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决