ecshop中如何添加限时抢购功能可以看到一个倒计时

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

复制代码代码如下:
<tr>
<td class="label"><label for="is_promote">
<input type="checkbox" id="is_promote_switch" name="is_promote_switch" {if $goods.is_promote}checked="checked"{/if} /> 是否参加促销</label>
<select name="is_promote" id="is_promote">
<option value="" >请选择</option>
<option value="http://www.cppcns.com/cms/ecshop/1" {if $goods.is_promote eq 1}selected="selected"{/if}>{$lang.lab_promote_price}</option>
<option value="http://www.cppcns.com/cms/ecshop/2" {if $goods.is_promote eq 2}selected="selected"{/if}>限时价:</option>
<option value="http://www.cppcns.com/cms/ecshop/3" {if $goods.is_promote eq 3}selected="selected"{/if}>秒杀价:</option>
</select>
</td>
<td id="promote_3">
<input type="text" id="promote_1" name="promote_price" value="http://www.cppcns.com/cms/ecshop/{$goods.promote_price}" size="20" />
</td>
</tr>
<tr id="promote_4">
<td class="label" id="promote_5">{$lang.lab_promote_date}</td>
<td id="promote_6">
<input name="promote_start_date" type="text" id="promote_start_date" size="15" value='http://www.cppcns.com/cms/ecshop/{$goods.promote_start_date}' readonly="readonly" /><input name="selbtn1" type="button" id="selbtn1" value="http://www.cppcns.com/cms/ecshop/{$lang.btn_select}" class="button"/> - <input name="promote_end_date" type="text" id="promote_end_date" size="15" value='http://www.cppcns.com/cms/ecshop/{$goods.promote_end_date}' readonly="readonly" /><input name="selbtn2" type="button" id="selbtn2" value="http://www.cppcns.com/cms/ecshop/{$lang.btn_select}" class="button"/>
</td>
</tr>

并找到下面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>复制代码代码如下:
$smarty->assign('time_goods', get_time_goods()); // 限时商品

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

复制代码代码如下:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- {if $time_goods} -->

ecshop中如何添加限时抢购功能可以看到一个倒计时

扫一扫手机访问