转载自:ecmall挂件 商品分类 + 分类下品牌 gcategory_brand_list
在gcategory_list挂件基础上修改的一个挂件,增加了展示分类下品牌,品牌显示个数可配置
widget.info.php
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php return array ( 'name' => 'gcategory_brand_list' , 'display_name' => '商品分类 + 分类下品牌' , 'author' => 'Heui' , 'version' => '1.0' , 'desc' => '展示第一第二级商品分类和一级分类下品牌,适合放在比较宽的区域' , 'configurable' => true, ); ?> |
main.widget.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<?php /** * 商品分类挂件 * * @return array $category_brand_list */ class Gcategory_brand_listWidget extends BaseWidget { var $_name = 'gcategory_brand_list' ; var $_ttl = 86400; function _get_data() { $this ->options[ 'amount_cate' ] = intval ( $this ->options[ 'amount_cate' ]); $this ->options[ 'amount_brand' ] = intval ( $this ->options[ 'amount_brand' ]); $cache_server =& cache_server(); $key = $this ->_get_cache_id(); $data = $cache_server ->get( $key ); if ( $data === false) { $gcategory_mod =& bm( 'gcategory' , array ( '_store_id' => 0)); $gcategories = array (); if ( empty ( $this ->options[ 'amount_cate' ])) { $gcategories = $gcategory_mod ->get_list(-1, true); } else { $gcategory = $gcategory_mod ->get_list(0, true); $gcategories = $gcategory ; foreach ( $gcategory as $val ) { $result = $gcategory_mod ->get_list( $val [ 'cate_id' ], true); $result = array_slice ( $result , 0, $this ->options[ 'amount_cate' ]); $gcategories = array_merge ( $gcategories , $result ); } } import( 'tree.lib' ); $tree = new Tree(); $tree ->setTree( $gcategories , 'cate_id' , 'parent_id' , 'cate_name' ); $data = $tree ->getArrayList(0); $cache_server ->set( $key , $data , $this ->_ttl); } /////////////新增加的品牌分类// //echo $this->options['amount_brand'];exit; $good_mod =& m( 'goods' ); foreach ( $data as $key => & $val ){ $result = $good_mod ->get_list( array ( 'conditions' => "cate_id_1 = " . $val [ 'id' ], )); foreach ( $result as $key => $value ) { if (! empty ( $value [ 'brand' ])){ $val [ 'brand' ][ $key ] = $value [ 'brand' ]; } } if (! is_null ( $val [ 'brand' ])){ $val [ 'brand' ] = array_unique ( $val [ 'brand' ]); if (! empty ( $this ->options[ 'amount_brand' ])) { $val [ 'brand' ] = array_slice ( $val [ 'brand' ], 0, $this ->options[ 'amount_brand' ]);; } } else { $val [ 'brand' ] = null; } } ///////////////// return $data ; } function parse_config( $input ) { $result = array (); $result [ 'amount_cate' ] = $input [ 'amount_cate' ]; $result [ 'amount_brand' ] = $input [ 'amount_brand' ]; return $result ; } } ?> |
ecmall挂件下载:
gcategory_brand_list