您的位置:首页 > 运维架构

为ECSHOP增加一个浏览排行

2013-07-09 10:25 218 查看
因为公司一个电子商城用的是ECSHOP,为了对其2次开发,利用空余时间学习了有关知识。项目中经常会对客户产生的某个动作,我们根据这一动作进行排序。今天根据用户的浏览商品的次数,来为商城首页增加一个浏览排行。

第一步:增加一个浏览排行的页面,在themes/default/library下增加top10_click.lbi

内容如下:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div class="box">
<div class="box_2">
<!--<div class="top10Tit"></div>-->
<h3><span>浏览排行</span></h3>
<div class="top10List clearfix">
<!-- {foreach name=top_goods from=$top_goods_click item=goods}-->
<ul class="clearfix">
<img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />
<!-- {if $smarty.foreach.top_goods.iteration<4}-->
<li class="topimg">
<a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="samllimg" /></a>
</li>
<!-- {/if} -->
<li {if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}>
<a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_name}</a><br />
{$lang.shop_price}<font class="f1">{$goods.price}</font><br />
</li>
</ul>
<!-- {/foreach} -->
</div>
</div>
</div>
<div class="blank5"></div>

显示模板:在themes/default/index.dwt中增加

<!-- #BeginLibraryItem "/library/top10_click.lbi" --><!-- #EndLibraryItem -->

第二步:读取用户浏览商品次数前10在includes/lib_goods.php增加get_top10_click()函数

function get_top10_click()
{
$sql = "SELECT goods_id,goods_name,shop_price,goods_thumb FROM".$GLOBALS['ecs'] -> table('goods')."
where is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 ORDER by click_count desc LIMIT 10";
$arr = $GLOBALS['db'] -> getAll($sql);

for($i = 0,$count = count($arr);$i < $count;$i++){
$arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0?sub_str($arr[$i]['goods_name'],$GLOBALS['_CFG']['goods_name_length'])
:$arr[$i]['goods_name'];
$arr[$i]['url']= build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);
$arr[$i]['thumb'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['goods_thumb'],true);
$arr[$i]['price'] = price_format($arr[$i]['shop_price']);
}
return $arr;
}


为了使其lbi文件能够正常加载数据,在首页index.php文件中增加:

$smarty->assign('top_goods_click',get_top10_click());//浏览排行


第三步:前端正常显示了,为了方便以后操作,在后端模板增加浏览排行,在admin/includes/lib_template.php中'index' => array()数组下增加

'/library/top10_click.lbi' => 0,

在语言包文件(languages/zh_ch/admin/template.php)中增加

$_LANG['template_libs']['top10_click'] = '浏览排行';

在themes/default/libs.xml下<file name="index.dwt"></file>之间增加

<lib>top10_click</lib>

大功告成,清空缓存,后台模块设置中有浏览排行这个模块了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: