网站增加购买过该商品的用户还购买了那些商品

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



网站增加购买过该商品的用户还购买了那些商品

回答:
看EC的商品页面代码。默认就有了

默认的那个 是哪个 啊

找默认模板

默认的就有 bought_goods.lbi 就是

这个在ecshop中其实自带这个功能,但是ecshop中的这个功能是根据订单商品order_goods 表来获取的数据,实际上只是获得了 购买这个商品的订单中的其他的商品 ,而不是购买这个商品的人还购买了哪些商品,对此我做了一些改进。
先看函数
在goods.php中添加function get_have_buys($goods_id);
/*
购买过该商品的人还购买了
*/
function get_have_buys($goods_id){
$sql = “select distinct(o.user_id) from “.$GLOBALS['ecs']->table(“order_goods”).” as og “.
“left join “.$GLOBALS['ecs']->table(“order_info”).” as o on og.order_id=o.order_id “.
” where og.goods_id=’$goods_id’ and (o.order_status=1 or o.order_status=5)and o.user_id!=0″;
//获得购买过该商品的人 ,这些用户不包括那些没有注册的人,否则得话就会有许多不真实的商品出现
$users = $GLOBALS['db']->getAll($sql);
$ins = ”;
foreach($users as $key=>$val){
$ins .= $val['user_id'].”,”;
}
$ins = rtrim($ins,’,');
if(empty($ins)){
return array();
}
//这些人都购买了哪些东西
$sql = “select distinct(og.goods_id) from “.$GLOBALS['ecs']->table(“order_goods”).” as og “.
“left join “.$GLOBALS['ecs']->table(“order_info”).” as o on og.order_id=o.order_id “.
” where o.user_id in ($ins) and (o.order_status=1 or o.order_status=5)”;
$goods = $GLOBALS['db']->getAll($sql);
$ins = ”;
foreach($goods as $keys=>$val){
$ins.=$val['goods_id'].”,”;
}
$ins = rtrim($ins,’,');
if(empty($ins)){
return array();
}
$sql = “select * from “.$GLOBALS['ecs']->table(“goods”).” where goods_id in ($ins) and is_on_sale = 1 AND is_alone_sale = 1 and is_delete=0 limit 10″;
$res = $GLOBALS['db']->query($sql);
$arr = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
}
else
{
$promote_price = 0;
}
/* 处理商品水印图片 */
$watermark_img = ”;
if ($promote_price != 0)
{
$watermark_img = “watermark_promote_small”;
}
elseif ($row['is_new'] != 0)
{
$watermark_img = “watermark_new_small”;
}
elseif ($row['is_best'] != 0)
{
$watermark_img = “watermark_best_small”;
}
elseif ($row['is_hot'] != 0)
{
$watermark_img = ‘watermark_hot_small’;
}
if ($watermark_img != ”)
{
$arr[$row['goods_id']]['watermark_img'] = $watermark_img;
}
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == ‘grid’)
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['type'] = $row['goods_type'];
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ”;
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri(‘goods’, array(‘gid’=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}

直接复制出来,多好。作者为一楼的,我只是复制出来了。。。。。。。

把我的复制出来干啥 还想推广下网站呢