Fork me on GitHub

ecshop设置一个子类对应多个父类并指定跳转url的修改方法

  这是一篇记录在日记里面的技术文档,其实是对ecshop的二次开发。主要作用是将一个子类对应多个父类,并指定条跳转url的功能。ecshop是一款在线购物网站,感兴趣的可以下载源码看看。我们看看具体是怎么修改的。

  1、数据库表“表前缀_category”添加如下字段

alter  TABLE `ga_category` add `assign_child` varchar(255) default NULL;
alter  TABLE `ga_category` add `jump_url` varchar(255) default NULL;

  2、includes/lib_goods.php

  get_categories_tree、get_child_tree函数中的

$cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

  改为

if(isset($row['jump_url']) != NULL && trim($row['jump_url']) != ''){
                    $cat_arr[$row['cat_id']]['url'] = $row['jump_url'];
                }else{
                    $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
                }

  将

$three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);

  改为

if(isset($row['assign_child']) != NULL && trim($row['assign_child']) != ''){
                        $three_arr[$row['cat_id']]['cat_id'] = get_assign_child_tree($row['assign_child']);
                    }else{
                           $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
                    }

  将将获取子类的sql

        $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .

                'FROM ' . $GLOBALS['ecs']->table('category') .

                "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

  改为(添加assign_child, jump_url两个字段用于查询用)

        $sql = 'SELECT cat_id,cat_name ,parent_id,is_show, template_file, assign_child, jump_url ' .

                'FROM ' . $GLOBALS['ecs']->table('category') .

                "WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

  并添加函数

function get_assign_child_tree($tree_id = '')

{

    $three_arr = array();
    if($tree_id == '') return $three_arr;

    $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show, assign_child, jump_url ' .

            'FROM ' . $GLOBALS['ecs']->table('category') .

            "WHERE cat_id in( $tree_id ) AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

    $res = $GLOBALS['db']->getAll($child_sql);

    foreach ($res AS $row)

    {

        if ($row['is_show'])



           $three_arr[$row['cat_id']]['id']   = $row['cat_id'];

           $three_arr[$row['cat_id']]['name'] = $row['cat_name'];

            if(isset($row['jump_url']) != NULL && trim($row['jump_url']) != ''){
                $three_arr[$row['cat_id']]['url'] = $row['jump_url'];
            }else{
                   $three_arr[$row['cat_id']]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
            }

           if (isset($row['cat_id']) != NULL)

               {
                    if(isset($row['assign_child']) != NULL && trim($row['assign_child']) != ''){
                        $three_arr[$row['cat_id']]['cat_id'] = get_assign_child_tree($row['assign_child']);
                    }else{
                           $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
                    }
        }

    }
    return $three_arr;

}

  3、admin/category.php中作如下修改

  在($_REQUEST['act'] == 'insert')、if ($_REQUEST['act'] == 'update')的条件中的

$cat['grade'] = !empty($_POST['grade']) ? intval($_POST['grade']) : 0;
$cat['filter_attr'] = !empty($_POST['filter_attr']) ? implode(',', array_unique(array_diff($_POST['filter_attr'],array(0)))) : 0;

  后面添加

    $cat['jump_url']     = !empty($_POST['jump_url'])     ? trim($_POST['jump_url'])      : '';

    $cat['assign_child'] = !empty($_POST['assign_child']) ? trim($_POST['assign_child']) : '';

  4、在admin/templates/category_info.htm的

      <tr id="assign_child">

        <td class="label">{$lang.assign_child}:</td>

        <td>

          <input type="text" name='assign_child' value='{$cat_info.assign_child}' size="32" />

        </td>

      </tr>

  中添加

      <tr id="jump_url">

        <td class="label">{$lang.jump_url}:</td>

        <td>

          <input type="text" name='jump_url' value='{$cat_info.jump_url}' size="32" />

        </td>

      </tr>

  5、languages/zh-cn/admin/category.php中添加如下语言描述

  $_LANG['jump_url']='跳转url(指定跳转至的url)';

  $_LANG['assign_child']='指定子类(将其id填写在输入框中即可,多个是用应为的“,”号隔开)';

 

posted @ 2015-07-03 10:25  秋楓  阅读(734)  评论(0编辑  收藏  举报