ECShop商品分类上传,如果分类较多的话,ECShop默认的上传方式让我们觉得很繁琐。以下这个功能非常不错,简化了我们的上传方式,一次性导入更多的分类,分类之间使用半角逗号分隔。本功能基于2.7.3,其他版本的用户请参考代码研究。
效果演示:如下
首先,我们导入一级分类,也就是顶级分类:
然后对二级分类进行导入:
其他的分类类似方式导入。
注意:多个分类之间的逗号是英文符号。本功能基于2.7.3,其他版本的用户请参考代码研究。
修改方法:
第一步:编辑/admin/templates/category_info.htm
1
|
<p style= "text-indent: 2em;" ><span style= "font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 14px;" >查找:<br></span></p> |
1
|
<p style= "text-indent: 2em;" ><span style= "font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 14px;" >{ $lang .cat_name}: *<br></span></p> |
修改为:
1
|
<p style= "text-indent: 2em;" ><span style= "font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 14px;" > { $lang .cat_name}: { $cat_info .cat_name|escape:html} * { $lang .notice_cat_name}<br></span></p> |
第二步:编辑/admin/category.php
查找:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*------------------------------------------------------ */ //-- 商品分类添加时的处理 /*------------------------------------------------------ */ if ( $_REQUEST [ 'act' ] == 'insert' ) { /* 权限检查 */ admin_priv( 'cat_manage' ); /* 初始化变量 */ $cat [ 'cat_id' ] = ! empty ( $_POST [ 'cat_id' ]) ? intval ( $_POST [ 'cat_id' ]) : 0; $cat [ 'parent_id' ] = ! empty ( $_POST [ 'parent_id' ]) ? intval ( $_POST [ 'parent_id' ]) : 0; $cat [ 'sort_order' ] = ! empty ( $_POST [ 'sort_order' ]) ? intval ( $_POST [ 'sort_order' ]) : 0; $cat [ 'keywords' ] = ! empty ( $_POST [ 'keywords' ]) ? trim( $_POST [ 'keywords' ]) : '' ; $cat [ 'cat_desc' ] = ! empty ( $_POST [ 'cat_desc' ]) ? $_POST [ 'cat_desc' ] : '' ; $cat [ 'measure_unit' ] = ! empty ( $_POST [ 'measure_unit' ]) ? trim( $_POST [ 'measure_unit' ]) : '' ; $cat [ 'cat_name' ] = ! empty ( $_POST [ 'cat_name' ]) ? trim( $_POST [ 'cat_name' ]) : '' ; $cat [ 'show_in_nav' ] = ! empty ( $_POST [ 'show_in_nav' ]) ? intval ( $_POST [ 'show_in_nav' ]): 0; $cat [ 'style' ] = ! empty ( $_POST [ 'style' ]) ? trim( $_POST [ 'style' ]) : '' ; $cat [ 'is_show' ] = ! empty ( $_POST [ 'is_show' ]) ? intval ( $_POST [ 'is_show' ]) : 0; $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 [ 'cat_recommend' ] = ! empty ( $_POST [ 'cat_recommend' ]) ? $_POST [ 'cat_recommend' ] : array (); if (cat_exists( $cat [ 'cat_name' ], $cat [ 'parent_id' ])) { /* 同级别下不能有重复的分类名称 */ $link [] = array ( 'text' => $_LANG [ 'go_back' ], 'href' => 'javascript:history.back(-1)' ); sys_msg( $_LANG [ 'catname_exist' ], 0, $link ); } if ( $cat [ 'grade' ] > 10 || $cat [ 'grade' ] < 0) { /* 价格区间数超过范围 */ $link [] = array ( 'text' => $_LANG [ 'go_back' ], 'href' => 'javascript:history.back(-1)' ); sys_msg( $_LANG [ 'grade_error' ], 0, $link ); } /* 入库的操作 */ if ( $db ->autoExecute( $ecs ->table( 'category' ), $cat ) !== false) { $cat_id = $db ->insert_id(); if ( $cat [ 'show_in_nav' ] == 1) { $vieworder = $db ->getOne( "SELECT max(vieworder) FROM " . $ecs ->table( 'nav' ) . " WHERE type = 'middle'" ); $vieworder += 2; //显示在自定义导航栏中 $sql = "INSERT INTO " . $ecs ->table( 'nav' ) . " (name,ctype,cid,ifshow,vieworder,opennew,url,type)" . " VALUES('" . $cat ['cat_name '] . "' , 'c' , '".$db->insert_id()."' , '1' , '$vieworder' , '0' , '" . build_uri(' category ', array(' cid '=> $cat_id), $cat[' cat_name ']) . "' , 'middle' )"; $db ->query( $sql ); } insert_cat_recommend( $cat [ 'cat_recommend' ], $cat_id ); admin_log( $_POST [ 'cat_name' ], 'add' , 'category' ); // 记录管理员操作 clear_cache_files(); // 清除缓存 /*添加链接*/ $link [0][ 'text' ] = $_LANG [ 'continue_add' ]; $link [0][ 'href' ] = 'category.php?act=add' ; $link [1][ 'text' ] = $_LANG [ 'back_list' ]; $link [1][ 'href' ] = 'category.php?act=list' ; sys_msg( $_LANG [ 'catadd_succed' ], 0, $link ); } } |
替换为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*------------------------------------------------------ */ //-- 商品分类添加时的处理 /*------------------------------------------------------ */ if ( $_REQUEST [ 'act' ] == 'insert' ) { /* 权限检查 */ admin_priv( 'cat_manage' ); /* 初始化变量 */ $cat [ 'cat_id' ] = ! empty ( $_POST [ 'cat_id' ]) ? intval ( $_POST [ 'cat_id' ]) : 0; $cat [ 'parent_id' ] = ! empty ( $_POST [ 'parent_id' ]) ? intval ( $_POST [ 'parent_id' ]) : 0; $cat [ 'sort_order' ] = ! empty ( $_POST [ 'sort_order' ]) ? intval ( $_POST [ 'sort_order' ]) : 0; $cat [ 'keywords' ] = ! empty ( $_POST [ 'keywords' ]) ? trim( $_POST [ 'keywords' ]) : '' ; $cat [ 'cat_desc' ] = ! empty ( $_POST [ 'cat_desc' ]) ? $_POST [ 'cat_desc' ] : '' ; $cat [ 'measure_unit' ] = ! empty ( $_POST [ 'measure_unit' ]) ? trim( $_POST [ 'measure_unit' ]) : '' ; $cat [ 'show_in_nav' ] = ! empty ( $_POST [ 'show_in_nav' ]) ? intval ( $_POST [ 'show_in_nav' ]): 0; $cat [ 'style' ] = ! empty ( $_POST [ 'style' ]) ? trim( $_POST [ 'style' ]) : '' ; $cat [ 'is_show' ] = ! empty ( $_POST [ 'is_show' ]) ? intval ( $_POST [ 'is_show' ]) : 0; $cat [ 'grade' ] = ! empty ( $_POST [ 'grade' ]) ? intval ( $_POST [ 'grade' ]) : 0; $cat [ 'cat_recommend' ] = ! empty ( $_POST [ 'cat_recommend' ]) ? $_POST [ 'cat_recommend' ] : array (); $cat [ 'filter_attr' ] = ! empty ( $_POST [ 'filter_attr' ]) ? implode( ',' , array_unique ( array_diff ( $_POST [ 'filter_attr' ], array (0)))) : 0; $cat [ 'cat_name' ] = ! empty ( $_POST [ 'cat_name' ]) ? trim( $_POST [ 'cat_name' ]) : '' ; $arrCatName = explode ( "," , $cat [ 'cat_name' ]); foreach ( $arrCatName as $arrCatNameValue ) { $cat [ 'cat_name' ] = $arrCatNameValue ; if (cat_exists( $cat [ 'cat_name' ], $cat [ 'parent_id' ])) { /* 同级别下不能有重复的分类名称 */ $link [] = array ( 'text' => $_LANG [ 'go_back' ], 'href' => 'javascript:history.back(-1)' ); sys_msg( $_LANG [ 'catname_exist' ], 0, $link ); } if ( $cat [ 'grade' ] > 10 || $cat [ 'grade' ] < 0) { /* 价格区间数超过范围 */ $link [] = array ( 'text' => $_LANG [ 'go_back' ], 'href' => 'javascript:history.back(-1)' ); sys_msg( $_LANG [ 'grade_error' ], 0, $link ); } /* 入库的操作 */ if ( $db ->autoExecute( $ecs ->table( 'category' ), $cat ) !== false) { $cat_id = $db ->insert_id(); if ( $cat [ 'show_in_nav' ] == 1) { $vieworder = $db ->getOne( "SELECT max(vieworder) FROM " . $ecs ->table( 'nav' ) . " WHERE type = 'middle'" ); $vieworder += 2; //显示在自定义导航栏中 $sql = "INSERT INTO " . $ecs ->table( 'nav' ) . " (name,ctype,cid,ifshow,vieworder,opennew,url,type)" . " VALUES('" . $cat ['cat_name '] . "' , 'c' , '".$db->insert_id()."' , '1' , '$vieworder' , '0' , '" . build_uri(' category ', array(' cid '=> $cat_id), $cat[' cat_name ']) . "' , 'middle' )"; $db ->query( $sql ); } insert_cat_recommend( $cat [ 'cat_recommend' ], $cat_id ); } } admin_log( $_POST [ 'cat_name' ], 'add' , 'category' ); // 记录管理员操作 clear_cache_files(); // 清除缓存 /*添加链接*/ $link [0][ 'text' ] = $_LANG [ 'continue_add' ]; $link [0][ 'href' ] = 'category.php?act=add' ; $link [1][ 'text' ] = $_LANG [ 'back_list' ]; $link [1][ 'href' ] = 'category.php?act=list' ; sys_msg( $_LANG [ 'catadd_succed' ], 0, $link ); } |
第三步:编辑/languages/zh_cn/admin/category.php
任意位置添加以下代码
1
|
<p style= "text-indent: 2em;" ><span style= "font-family: 微软雅黑, 'Microsoft YaHei'; font-size: 14px;" > $_LANG [ 'notice_cat_name' ] = '如果您需要添加多个分类,请在分类之间使用半角逗号分隔。' ;<br></span></p> |
后台清楚缓存即可