ecshop中如何添加限时抢购功能可以看到一个倒计时
来源: 阅读:1157 次 日期:2016-06-18 09:38:17
温馨提示: 小编为您整理了“ecshop中如何添加限时抢购功能可以看到一个倒计时”,方便广大网友查阅!

这篇文章主要介绍了ecshop中如何添加限时抢购功能,在页面中可以看到一个倒计时,下面是详细的实现步骤,适合所有新手朋友们。

第1步:在后台admin / templates / goods_info.htm中找到大概164行至173行修改以下代码

代码如下:

是否参加促销

{$lang.lab_promote_date}

-

并找到下面js代码中的onload = function()函数将里面的

代码如下:

handlepromote(document.forms['theform'].elements['is_promote'].checked);

改为

代码如下:

handlepromote(document.forms['theform'].elements['is_promote_switch'].checked);

第2步:把admin下的goods.php改一句话,注释部分为原先部分

代码如下:

//$is_promote = empty($promote_price) ? 0 : 1;

$is_promote = empty($promote_price) ? 0 : $_post['is_promote'];

第3步:找到admin / includes / lib_goods.php里的goods_list函数,将switch条件里的

代码如下:

case 'is_promote':

$where .= and is_promote = 1 and promote_price > 0 and promote_start_date <= '$today' and promote_end_date >= '$today';

break;

改为

代码如下:

case 'is_promote':

$where .= and is_promote > 0 and promote_price > 0 and promote_start_date <= '$today' and promote_end_date >= '$today';

break;

否则在后台商品列表页搜索功能中的推荐的特价不能用

第4步:在includes / lib_goods.php中添加一个函数方法

代码如下:

/**

* 获得限时商品

*

* @access public

* @return array

*/

function get_time_goods($cats = '')

{

$time = gmtime();

$order_type = $globals['_cfg']['recommend_order'];

/* 取得限时lbi的数量限制 */

$num = get_library_number(recommend_promotion);

$sql = 'select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price as org_price, g.promote_price, ' .

ifnull(mp.user_price, g.shop_price * '$_session[discount]') as shop_price, .

promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, .

g.is_best, g.is_new, g.is_hot, g.is_promote, rand() as rnd .

'from ' . $globals['ecs']->table('goods') . ' as g ' .

'left join ' . $globals['ecs']->table('brand') . ' as b on b.brand_id = g.brand_id ' .

left join . $globals['ecs']->table('member_price') . as mp .

on mp.goods_id = g.goods_id and mp.user_rank = '$_session[user_rank]' .

'where g.is_on_sale = 1 and g.is_alone_sale = 1 and g.is_delete = 0 ' .

and g.is_promote = 2 and promote_start_date <= '$time' and promote_end_date >= '$time' ;

$sql .= $order_type == 0 ? ' order by g.sort_order, g.last_update desc' : ' order by rnd';

$sql .= limit $num ;

$result = $globals['db']->getall($sql);

$goods = array();

foreach ($result as $idx => $row)

{

if ($row['promote_price'] > 0)

{

$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);

$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';

}

else

{

$goods[$idx]['promote_price'] = '';

}

$goods[$idx]['id'] = $row['goods_id'];

$goods[$idx]['name'] = $row['goods_name'];

$goods[$idx]['brief'] = $row['goods_brief'];

$goods[$idx]['brand_name'] = $row['brand_name'];

$goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);

$goods[$idx]['short_name'] = $globals['_cfg']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $globals['_cfg']['goods_name_length']) : $row['goods_name'];

$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);

$goods[$idx]['market_price'] = price_format($row['market_price']);

$goods[$idx]['shop_price'] = price_format($row['shop_price']);

$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);

$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);

$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);

/* 限时时间倒计时 */

$time = gmtime();

if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date'])

{

$goods[$idx]['gmt_end_time'] = local_date('m d, y h:i:s',$row['promote_end_date']);

}

else

{

$goods[$idx]['gmt_end_time'] = 0;

}

}

return $goods;

}

在index.php中加一句

代码如下:

$smarty->assign('time_goods', get_time_goods()); // 限时商品

第5步:在library中新建一个time_limit.lbi,代码如下

代码如下:

{if ($key+1)%5==0}

{if count($time_goods)!=$key+1}

{/if}

{/if}

  • {$goods.name|escape:html}/

    {$goods.promote_price}

    {$goods.market_price}

    剩余 {$lang.please_waiting}

更多信息请查看 CMS教程
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
相关阅读 CMS教程

2026上岸·考公考编培训报班

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们| 联系我们| 人才招聘| 网站声明| 网站帮助| 非正式的简要咨询| 简要咨询须知| 新媒体/短视频平台| 手机站点| 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65099533/13759567129 获取招聘考试信息及咨询关注公众号:
咨询QQ:1093837350(9:00—18:00) 版权所有:
云南网警报警专用图标
Baidu
map