博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ecshop首页调用指定分类下商品
阅读量:5978 次
发布时间:2019-06-20

本文共 3490 字,大约阅读时间需要 11 分钟。

ECSHOP默认只能在后台模板设置中设置首页调用分类下商品,比较死板。

为了更好的设计调用分类商品,可使用以下方法自定义调用:

第一步:

找到打开 /includes/lib_goods.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
function
get_cat_id_goods_index_list(
$cat_id
=
''
,
$num
=
''
  
//申明$cat_id,$num函数
{
$sql
=
'Select g.goods_id, g.cat_id,c.parent_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, '
.
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, "
.
"promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, "
.
"g.is_best, g.is_new, g.is_hot, g.is_promote "
.
'FROM '
.
$GLOBALS
[
'ecs'
]->table(
'goods'
) .
' AS g '
.
'LEFT JOIN '
.
$GLOBALS
[
'ecs'
]->table(
'category'
) .
' AS c ON c.cat_id = g.cat_id '
.
"LEFT JOIN "
.
$GLOBALS
[
'ecs'
]->table(
'member_price'
) .
" AS mp "
.
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' "
.
"Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 "
.
$sql
.=
" AND (c.parent_id ="
.
$cat_id
.
" OR g.cat_id = "
.
$cat_id
.
" OR g.cat_id "
. db_create_in(
array_unique
(
array_merge
(
array
(
$cat_id
),
array_keys
(cat_list(
$cat_id
, 0, false))))) .
")"
.
"order by g.cat_id desc"
;  
   
//cat_id降序排列
$sql
.=
" LIMIT $num"
;
$res
=
$GLOBALS
[
'db'
]->getAll(
$sql
);
$goods
=
array
();
foreach
(
$res
AS
$idx
=>
$row
)
{
$goods
[
$idx
][
'id'
] =
$row
[
'article_id'
];
$goods
[
$idx
][
'id'
] =
$row
[
'goods_id'
];
$goods
[
$idx
][
'name'
] =
$row
[
'goods_name'
];
$goods
[
$idx
][
'brief'
] =
$row
[
'goods_brief'
];
$goods
[
$idx
][
'brand_name'
] =
$row
[
'brand_name'
];
$goods
[
$idx
][
'goods_style_name'
] = add_style(
$row
[
'goods_name'
],
$row
[
'goods_name_style'
]);
$goods
[
$idx
][
'short_name'
] =
$GLOBALS
[
'_CFG'
][
'goods_name_length'
] > 0 ?
sub_str(
$row
[
'goods_name'
],
$GLOBALS
[
'_CFG'
][
'goods_name_length'
]) :
$row
[
'goods_name'
];
$goods
[
$idx
][
'short_style_name'
] = add_style(
$goods
[
$idx
][
'short_name'
],
$row
[
'goods_name_style'
]);
$goods
[
$idx
][
'market_price'
] = price_format(
$row
[
'market_price'
]);
$goods
[
$idx
][
'shop_price'
] = price_format(
$row
[
'shop_price'
]);
$goods
[
$idx
][
'thumb'
] =
empty
(
$row
[
'goods_thumb'
]) ?
$GLOBALS
[
'_CFG'
][
'no_picture'
] :
$row
[
'goods_thumb'
];
$goods
[
$idx
][
'goods_img'
] =
empty
(
$row
[
'goods_img'
]) ?
$GLOBALS
[
'_CFG'
][
'no_picture'
] :
$row
[
'goods_img'
];
$goods
[
$idx
][
'url'
] = build_uri(
'goods'
,
array
(
'gid'
=>
$row
[
'goods_id'
]),
$row
[
'goods_name'
]);
}
return
$goods
;
}
第二步:

打开根目录下的 index.php

查找:

1
$smarty
->assign(
'shop_notice'
,    
$_CFG
[
'shop_notice'
]);      
// 商店公告

在这段代码后面,也就是下一行添加以下代码:

1
$smarty
->assign(
'cat_id1_index_goods'
, get_cat_id_goods_index_list(1,8));    
//首页调用分类1下的8个商品
第三步:

打开/themes/default/index.dwt

在需要的地方添加以下代码:

1
2
3
4
5
6
7
8
<!--{
foreach
from=
$cat_id1_index_goods
item=goods}-->
<a 
class
=
"first"
href=
"{$goods.url}"
target=
"_blank"
>
<img title=
"{$goods.name|escape:html}"
alt=
"{$goods.name|escape:html}"
width=
"220"
height=
"220"
src=
"{$goods.goods_img}"
/>
<p
class
=
"title"
title=
"{$goods.name|escape:html}"
> {
$goods
.name|escape:html} </p>
<p
class
=
"price"
> <span
class
=
"label"
>原价:</span><del>{
$goods
.market_price}</del></p>
<p
class
=
"price qz-price"
><span
class
=
"label"
>现价:</span><em>{
$goods
.shop_price}</em></p>
</a>
<!-- { /
foreach
}-->

如果首页需要重复多次调用,只需重复第二步代码即可。

转载于:https://www.cnblogs.com/wpindesign/p/3654905.html

你可能感兴趣的文章
sqlplus中使用oradebug定位 alter session 10046事件产生的trace文件
查看>>
(五)flask扩展
查看>>
bash的算术运算和条件测试语句
查看>>
使用工具检测你的app:模拟器和真机测试 之一
查看>>
EhCache使用
查看>>
web网站如何后台启动GUI程序
查看>>
使用字符代替圆角尖角研究(转)
查看>>
tomcat
查看>>
java通过JDBC连接mysql数据库
查看>>
Windows详细配置Memcache
查看>>
关于linux下的inotify
查看>>
mysql通过命令行查询数据库编码信息
查看>>
×××S 2012 建立图表 -- 双轴混合图表
查看>>
MongoDB Database Profiling
查看>>
WITH (UPDLOCK,HOLDLOCK)提示与不同表类型
查看>>
关于C++中typedef的用法定义函数指针
查看>>
Mysql性能优化建议
查看>>
ClassNotFound异常
查看>>
分布式文件系统之在域命名空间中新建文件夹
查看>>
关于 ps -aux 的错误用法
查看>>