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_good衡痕贤伎s.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、教程结束,打开商品详情页刷新一下,看看点击数有没改变吧!