新聞中心
Ecshop如何添加商品倒計(jì)時(shí)功能
在這個(gè)經(jīng)濟(jì)飛速發(fā)展的時(shí)代,競(jìng)爭(zhēng)是必不可少的,所以我們走在大街上隨時(shí)都可以看見(jiàn)各種“揮淚大甩賣”,“限時(shí)搶購(gòu)”,“限量購(gòu)買”等等促銷手段。然而在我們的網(wǎng)絡(luò)虛擬社會(huì)中,也有類似的促銷手段,只是沒(méi)有大街上的那種喧鬧的聲音,而是用廣告的手段來(lái)表現(xiàn),對(duì)于好的促銷廣告,也是一種視覺(jué)上的享受,給受眾帶來(lái)視覺(jué)的沖擊力。 在虛擬主機(jī)中,經(jīng)常搭建使用的網(wǎng)店程序就是ECshop,今天小編就從ECshop最簡(jiǎn)單的促銷方法——限時(shí)搶購(gòu)說(shuō)起。限時(shí)搶購(gòu),很多朋友說(shuō)是搶購(gòu)最有吸引力,而小編認(rèn)為,這個(gè)促銷手段最精髓,最有價(jià)值,最具吸引力的地方就在于“限時(shí)”這兩個(gè)字。古人有云:“物以稀為貴”所以越是限時(shí),限量的東西,大家越是覺(jué)得珍貴。那要如何使得“限時(shí)”的重要性?如何體現(xiàn)出“限時(shí)”呢?很簡(jiǎn)單,限時(shí)就是限制時(shí)間,就一定有一個(gè)期限,只要添加一個(gè)醒目的倒計(jì)時(shí)就行了,這樣訪問(wèn)的時(shí)候看見(jiàn)時(shí)間在一秒一秒的溜走,在人們的潛在意識(shí)里面就是再不買就來(lái)不及了??吹竭@里,相信很多朋友都想知道如何在ECshop中添加倒計(jì)時(shí)功能吧。接下來(lái),小編就告訴大家如何通過(guò)修改代碼來(lái)實(shí)現(xiàn)ECshop添加限時(shí)搶購(gòu)倒計(jì)時(shí)功能! 代碼有點(diǎn)長(zhǎng),請(qǐng)站長(zhǎng)朋友們耐心的看下去! 第1步:在后臺(tái)admin / templates / goods_info.htm中找到大概164行至173行修改以下代碼 復(fù)制代碼代碼如下: <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} onclick="handlePromote(this.checked);" /> 是否參加促銷</label> <select name="is_promote" id="is_promote"> <option value="" >請(qǐng)選擇</option> <option value="1" {if $goods.is_promote eq 1}selected="selected"{/if}>{$lang.lab_promote_price}</option> <option value="2" {if $goods.is_promote eq 2}selected="selected"{/if}>限時(shí)價(jià):</option> <option value="3" {if $goods.is_promote eq 3}selected="selected"{/if}>秒殺價(jià):</option> </select> </td> <td id="promote_3"> <input type="text" id="promote_1" name="promote_price" value="{$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='{$goods.promote_start_date}' readonly="readonly" /><input name="selbtn1" type="button" id="selbtn1" onclick="return showCalendar('promote_start_date', '%Y-%m-%d %H:%M','24', false, 'selbtn1');" value="{$lang.btn_select}" class="button"/> - <input name="promote_end_date" type="text" id="promote_end_date" size="15" value='{$goods.promote_end_date}' readonly="readonly" /><input name="selbtn2" type="button" id="selbtn2" onclick="return showCalendar('promote_end_date', '%Y-%m-%d %H:%M','24', false, 'selbtn2');" value="{$lang.btn_select}" class="button"/> </td> </tr> 并找到下面js代碼中的onload = function()函數(shù)將里面的 復(fù)制代碼代碼如下: handlePromote(document.forms['theForm'].elements['is_promote'].checked); 改為 復(fù)制代碼代碼如下: handlePromote(document.forms['theForm'].elements['is_promote_switch'].checked); 第2步:把a(bǔ)dmin下的goods.php改一句話,注釋部分為原先部分 復(fù)制代碼代碼如下: //$is_promote = empty($promote_price) ? 0 : 1; $is_promote = empty($promote_price) ? 0 : $_POST['is_promote']; 第3步:找到admin / includes / lib_goods.php里的goods_list函數(shù),將switch條件里的 復(fù)制代碼代碼如下: case 'is_promote': $where .= " AND is_promote = 1 AND promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today'"; break; 改為 復(fù)制代碼代碼如下: case 'is_promote': $where .= " AND is_promote > 0 AND promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today'"; break; 否則在后臺(tái)商品列表頁(yè)搜索功能中的推薦的特價(jià)不能用 第4步:在includes / lib_goods.php中添加一個(gè)函數(shù)方法 復(fù)制代碼代碼如下: /** * 獲得限時(shí)商品 * * @access public * @return array */ function get_time_goods($cats = '') { $time = gmtime(); $order_type = $GLOBALS['_CFG']['recommend_order']; /* 取得限時(shí)lbi的數(shù)量限制 */ $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']); /* 限時(shí)時(shí)間倒計(jì)時(shí) */ $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中加一句 復(fù)制代碼代碼如下: $smarty->assign('time_goods', get_time_goods()); // 限時(shí)商品 第5步:在library中新建一個(gè)time_limit.lbi,代碼如下 復(fù)制代碼代碼如下: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- {if $time_goods} --> <script > var Tday = new Array(); var daysms = 24 * 60 * 60 * 1000 var hoursms = 60 * 60 * 1000 var Secondms = 60 * 1000 var microsecond = 1000 var DifferHour = -1 var DifferMinute = -1 var DifferSecond = -1 function clock(key) { var time = new Date() var hour = time.getHours() var minute = time.getMinutes() var second = time.getSeconds() var timevalue = ""+((hour > 12) ? hour-12:hour) timevalue +=((minute < 10) ? ":0":":")+minute timevalue +=((second < 10) ? ":0":":")+second timevalue +=((hour >12 ) ? " PM":" AM") var convertHour = DifferHour var convertMinute = DifferMinute var convertSecond = DifferSecond var Diffms = Tday[key].getTime() - time.getTime() DifferHour = Math.floor(Diffms / daysms) Diffms -= DifferHour * daysms DifferMinute = Math.floor(Diffms / hoursms) Diffms -= DifferMinute * hoursms DifferSecond = Math.floor(Diffms / Secondms) Diffms -= DifferSecond * Secondms var dSecs = Math.floor(Diffms / microsecond) if(convertHour != DifferHour) a="<font color=red>"+DifferHour+"</font>天"; if(convertMinute != DifferMinute) b="<font color=red>"+DifferMinute+"</font>時(shí)"; if(convertSecond != DifferSecond) c="<font color=red>"+DifferSecond+"</font>分" d="<font color=red>"+dSecs+"</font>秒" if (DifferHour>0) {a=a} else {a=''} document.getElementById("leftTime"+key).innerHTML = a + b + c + d; //顯示倒計(jì)時(shí)信息 } </script> <div id="time_limit"> <div id="time_top"> <div id="time_title"><a href="../search.php?intro=promotion" target="_blank">限時(shí)搶購(gòu)</a></div> <div id="time_btn"> <a class="prev" href="javascript:;"></a> <a class="active" href="javascript:;"></a> <!--{foreach from=$time_goods key=key item=goods name="promotion_foreach"}--> {if ($key+1)%5==0} {if count($time_goods)!=$key+1} <a class="index" href="javascript:;"></a> {/if} {/if} <!--{/foreach}--> <a class="next" href="javascript:;"></a> </div> </div> <div id="time_nr"> <ul> <li> <!--{foreach from=$time_goods key=key item=goods name="promotion_foreach"}--> <div class="xsqg"> <div class="xsqg_top"><a href="{$goods.url}" target="_blank"><img src="{$goods.thumb}" width="170" height="155" alt="{$goods.name|escape:html}"/></a></div> <div class="xsqg_cen"><a href="{$goods.url}" target="_blank" title="{$goods.name|escape:html}">{$goods.short_name|escape:html}</a></div> <div class="xsqg_bot"> <div class="te">{$goods.promote_price}</div> <div class="yuan">{$goods.market_price}</div> <div class="remain_time"><font style="color:#666;">剩余</font> <font id="leftTime{$key}">{$lang.please_waiting}</font></div> <script> Tday[{$key}] = new Date("{$goods.gmt_end_time}"); window.setInterval(function(){clock({$key});}, 1000); </script> </div> </div> <!--{/foreach}--> </li> </ul> </div> </div> <!-- {/if} -->
本文地址:http://www.gle-technology.com/ecshop/15257.html