广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > 增加浏览过该商品的人还浏览了那些商品

二次开发Ecshop二次开发

二次开发Ecshop二次开发

增加浏览过该商品的人还浏览了那些商品

这个功能比较简单 但是需要增加一个数据库

ecs_history

CREATE TABLE `sc_history` (
`id` int(10) unsigned NOT NULL auto_increment,
`user_id` int(10) unsigned NOT NULL,
`goods_id` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

首先在goods.php中找到

/*更新浏览历史*/

$sql = “select count(*) from “.$GLOBALS['ecs']->table(‘history’).” where goods_id=’$goods_id’”;
$num = $GLOBALS['db']->getOne($sql);
if(empty($num)){
$user_id = !empty($_SESSION['user_id'])?intval($_SESSION['user_id']):0;
$sql = “insert into “.$GLOBALS['ecs']->table(‘history’).” (goods_id,user_id) values(‘$goods_id’,'$user_id’)”;
$GLOBALS['db']->query($sql);
}

将浏览的商品放入数据库。

在 lib_insert中增加一个函数

insert_db_history();

function insert_db_history()
{
$str = ”;
$res = array();
$sql = “select goods_id from “.$GLOBALS['ecs']->table(‘history’);
$res = $GLOBALS['db']->getAll($sql);
$ins = ”;
foreach($res as $key=>$val){
$ins .= $val['goods_id'].’,';
}

$ins = rtrim($ins,’,');
if (!empty($ins))
{
$where = db_create_in($ins, ‘goods_id’);
$sql = ‘SELECT goods_id, goods_name, goods_thumb, shop_price FROM ‘ . $GLOBALS['ecs']->table(‘goods’) .
” WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0″;
$query = $GLOBALS['db']->query($sql);
$res = array();
while ($row = $GLOBALS['db']->fetch_array($query))
{
$goods['goods_id'] = $row['goods_id'];
$goods['goods_name'] = $row['goods_name'];
$goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods['shop_price'] = price_format($row['shop_price']);
$goods['url'] = build_uri(‘goods’, array(‘gid’=>$row['goods_id']), $row['goods_name']);
$res[] = $goods;
}

}

$GLOBALS['smarty']->assign(‘db_history’,$res);//
$output = $GLOBALS['smarty']->fetch(‘library/db_history.lbi’);
return $output;
}

在增加一个db_history.lbi就完成了 所有功能了。

如果你想添加到任何页面的话 值需要将

{insert name=”db_history”}增加到你需要的位置就可以了。

但是这个功能会导致你的数据表一直增加,所以适用于商品不是太多的网站,如果商品多的话只要定时更新数据表即可。

关于如何制作可以自动删除过期的数据,以后我会专门在写个教程。