ECSHOP 点击量不能实时更新
1、简述不能实时更新的原因:为了加快网站的打开速度,ECShop使用了缓存技术,所以导致部分网页变量不能实时更新,如点击数就是。但是也是有部分变量是设置了不缓存,必须每次刷新或者点击之后就要更新改变量,如库存,购物车等,这些变量的设置都放在 includes\lib_insert.php 文件里面。
2、打开 themes\default\goods.dwt
搜索{$goods.click_count}
把它修改为
{insert name='click_count' goods_id=$id} 次
上面修改的是详情页的页面,代码是获取点击数字;次字可以去掉,保留的话如下图2


3、打开 includes\lib_insert.php 在后面添加一个方法(要在?>前面)
/**
* 获取点击数
*/
function insert_click_count($arr){
//获取当前的是否缓存 和 是否强迫编译
$need_cache = $GLOBALS['smarty']->caching;
$need_compile = $GLOBALS['smarty']->force_compile;
//不缓存和强制编译
$GLOBALS['smarty']->caching = false;
$GLOBALS['smarty']->force_compile = true;
//调用lib_goods.php的方法
$click_count = get_goods_click_count($arr['goods_id']);
$GLOBALS['smarty']->caching = $need_cache;
$GLOBALS['smarty']->force_compile = $need_compile;
return $click_count;
}

4、打开 includes\lib_goods.php 在后面添加方法
//从数据库中获取点击数的方法
function get_goods_click_count($goods_id){
global $db, $ecs;
$sql = "SELECT CLICK_COUNT FROM ".$ecs->table('goods').' where goods_id='.$goods_id;
$click_count= $db->getOne($sql);
return $click_count;
}
5、教程结束,打开商品详情页刷新一下,看看点击数有没改变吧!