ecshop商品詳細頁顯示已售商品數量和評論數量php
ecshop增長已售數量和評論數量很簡單,步驟以下,原創文章轉載請指明同盟者網絡<http://blog.sina.com.cn/tomener> 1.在ecshop程序goods.php頁面最下面加入這兩個函數 function get_buy_sum($goods_id) { $sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . " AND g.goods_id = '$goods_id'"; return $GLOBALS['db']->getOne($sql); } function get_comment_num($goods_id) { $sql= "select count(*) from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."' AND status = 1"; return $GLOBALS['db']->getOne($sql); } 2.在ecshop程序goods.php中加入 $smarty->assign('buy_num',get_buy_sum($goods_id)); $smarty->assign('comment_num',get_comment_num($goods_id)); 在$smarty->display('goods.dwt', $cache_id);以前哈! 3.ecshop中goods.dwt模板中加這個,大概在221行 <!-- {if $buy_num} 已出售量--> <li class="clearfix"> <dd> <strong>累計售出:</strong>{$buy_num} </dd> </li> <!--{/if}--> <!-- {if $comment_num} 評論數量--> <li class="clearfix"> <dd> <strong>評論數量:</strong><a href="#comment">{$comment_num}</a> </dd> </li> <!--{/if}-->
調用商品購買記錄html
1.在lib_insert.php文件中加入如下函數 /** * 調用商品購買記錄 * * @access public * @return string */ function insert_bought_count($arr) { $sql = 'SELECT count(*) ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . 'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $arr['id']; $count = $GLOBALS['db']->getOne($sql); return $count; } 2.模板中調用 {insert name=bought_count type=$type id=$goods.goods_id}
ecshop生成純靜態頁面web
ecshop生成純靜態頁面淺見 純靜態頁面具備佔用資源小,速度快的特色。一直廣受廣大站長的喜歡。目前的ecshop只有僞靜態,是否能夠爲ecshop增長僞靜態呢? 建議配上ec僞靜態使用,這樣只要客戶點擊一次系統就自動生成一個靜態頁面,不須要後臺批量生成了。 一、includes 目錄cls_template.php.增長 /*生成純靜態*/ ?[Copy to clipboard]View Code PHP1 2 3 4 5 6 7 8 function make_html($filename, $cache_id = '') { ob_start(); $this->display($filename,$cache_id); $out = ob_get_contents(); ob_end_clean(); return $out; } 2.複製首頁index.php爲index_html.php,由於ECSHOP是使用SMARTY模板引擎的,因此咱們可使用SMARTY生成文件函數,把模板的靜態網頁輸出。 在首頁中,$smarty->display(‘index.dwt’, $cache_id);有這一句,說明是把網頁顯示出來,如今咱們把它改爲以下代碼(參看註釋) $file = ‘index.html’;//靜態網頁文件名 $content = $GLOBALS['smarty']->make_html(‘index.dwt’);//根據index.dwt模板生成網頁內容 $filename = ROOT_PATH . $file;//靜態網頁路徑 file_put_contents($filename, $content);//生成文件 其餘也沒相似,但願你們能夠觸類旁通。 以上幾條簡單的語句,咱們就能夠生成首頁的靜態網頁。同理,咱們能夠生成產品類別和產品的靜態網頁,整個系統的靜態化就完成了。
讓ECSHOP生成靜態頁面的方法!ajax
僞靜態已經基本上能夠知足大部分人的需求,若是不知足的還能夠根據前面的一篇文章對重寫規則進行修改,以知足本身的需求。可是本文所要描述的是,根據ECSHOP內在的一些代碼,咱們生成純靜態的網頁,使系統更好的優化。在這裏,咱們先對首頁進行純靜態生成。 1.複製首頁index.php爲index_html.php,由於ECSHOP是使用SMARTY模板引擎的,因此咱們可使用SMARTY生成文件函數,把模板 的靜態網頁輸出。 在首頁中,$smarty->display('index.dwt', $cache_id);有這一句,說明是把網頁顯示出來,如今咱們把它改爲以下代碼(參看註釋) $file = 'index.html';//靜態網頁文件名 $content = $GLOBALS['smarty']->make_html('index.dwt');//根據index.dwt模板生成網頁內容 $filename = ROOT_PATH . $file;//靜態網頁路徑 file_put_contents($filename, $content);//生成文件 以上幾條簡單的語句,咱們就能夠生成首頁的靜態網頁。同理,咱們能夠生成產品類別和產品的靜態網頁,整個系統的靜態化就完成了。 首頁靜態頁面生成後,咱們接下來要生成的是產品類別的靜態頁面,個人想法是把產品類別頁面保存在跟目錄下,這樣雖然會比較亂, 可是比較適合優化,由於通常搜索引擎抓取的時候只抓取二到三層。把產品類別放在根目錄,體現產品類別的重要性,易於搜索引擎的 內容來自LZ工做室 抓取,另一方面,咱們能夠把產品放在下個目錄中。 相似代碼: $filename = build_uri('category', array('cid' => $catinfo['cat_id']));//構造路徑,這個能夠選擇本身喜歡的構造方法 $content = $GLOBALS['smarty']->make_html('category.dwt');//產生靜態頁面內容 $filename = ROOT_PATH . $filename;//生成文件路徑,在根目錄下 file_put_contents($filename, $content);//輸出 產品的靜態頁面代碼: $goodinfo = get_all_goodsinfo($goods_id); $cat_name = $goodinfo['cat_name']; $goodsfile = build_uri('goods', array('gid' => $goods_id)); $content = $GLOBALS['smarty']->make_html('goods.dwt'); $html_tempdir = (ROOT_PATH.$cat_name.'/'); if (!is_dir($html_tempdir))//生成產品目錄 { mkdir($html_tempdir); } $htmlfilename = ROOT_PATH . $goodsfile; file_put_contents($htmlfilename,$content); 個人是使用類別名稱加下劃線: function build_uri(........) ................ case 'category': $cat_name = $GLOBALS['db']->getOne('SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cid'"); $uri = $cat_name . '-' . $cid; if (!empty($page)) { $uri .= '-' . $page; } ........ case 'goods': $goods_info = $GLOBALS['db']->getRow('SELECT g.goods_name, c.cat_name FROM ' . $GLOBALS['ecs']->table('goods') . " as g left join " . $GLOBALS['ecs']->table('category') . " as c on c.cat_id = g.cat_id WHERE g.goods_id = '$gid'"); $goods_name = $goods_info['goods_name']; $cat_name = $cat_name; $uri = $cat_name . '/' . $goods_name . '-' . $gid ; 有人問 make_html 這個函數在那裏: 我如今補充以下: 在 includes 下的 cls_template.php 加上 function make_html($filename, $cache_id = '') { ob_start(); $this->display($filename,$cache_id); $out = ob_get_contents(); ob_end_clean(); return $out; }
ECSHOP模板製做中常見循環的操做方法sql
ECSHOP一直用的FCK,這個不解釋,太多杯具太多糾結。 --------------------- KindEdito主要特色 快速:體積小,加載速度快 開源:開放源代碼,高水平,高品質 底層:內置自定義 DOM 類庫,精確操做 DOM 擴展:基於插件的設計,全部功能都是插件,可根據需求增減功能 風格:修改編輯器風格很是容易,只需修改一個 CSS 文件 兼容:支持大部分主流瀏覽器,好比 IE、Firefox、Safari、Chrome、Opera --------------------- 官方下載最新版,解壓直接扔在根目錄算了,如今拿編輯產品信息開刀,模板頁面?這個不用說了吧(admin/templates/goods_info.html). 1.在head部分添加: <script charset=」utf-8″ src=」../kindeditor/kindeditor.js」></script> <script> KE.show({ id : ‘editor_id’, allowFileManager : true }); </script> 2.修改產品描述所調用的FCK編輯器 {$FCKeditor} 爲 <textarea id=」editor_id」 name=」goods_desc」 style=」width:90%;height:300px;」> {$goods.goods_desc} </textarea> OK,至此結束,看看效果吧!
Ecshop在模板中判斷用戶是否登錄,獲取用戶等級信息數組
Ecshop在模板中判斷用戶是否登錄,獲取用戶等級信息 ecshop模板中smarty怎樣判斷用戶等級、用戶id、用戶暱稱用戶名,請看如下方法,使用全局變量 <!-- {if $smarty.session.user_rank gt 1}-->gt大於 lt小於 1:ecshop模板中調用session的值 {$smarty.session.user_id} 用戶ID {$smarty.session.user_rank} 用戶等級 2:ecshop模板中調用cookie的值 {$smarty.cookie.user_id} 3:ecshop模板中調用當前時間 {$smarty.now} 4:ecshop模板中調用調用$_GET裏面的數據 {$smarty.get} 5:調用模板中調用調用$_POST裏面的數據 {$smarty.post} 6:在ecshop模板中調用cookie {$smarty.cookie.name} 7:在ecshop的smarty中調用$_SERVER的值 {$smarty.server} 8:在ecshop中進行一些foreach的取值和判斷 {$smarty.foreach.iteration.first}判斷是否第一條數據 {$smarty.foreach.iteration.last} 最後一條數據 9:在ecshop模板中取得$_REQUEST的值 {$smarty.request.name}
ecshop標籤大全瀏覽器
先從index.php主頁開始 頁面關鍵字 {$keywords } 頁面標題 {$page_title} 產品分類 父分類列表 {foreach from$categories item=cat } 父分類超連接 [url==」{$cat.url}」>{$cat.name|escape:html}</a> 相對應子分類 {foreach from=$cat.children item=child} 子分類超連接 [url==」{$child.url}」>{$child.name|escape:html}</a> 促銷產品 {if $promotion_info} 檢驗是否存在促銷產品,不存在就不顯示相關信息 促銷產品列表 {foreach from=$promotion_info item=item key=key} 裏面還有不少標籤,沒弄明白,之後在添加,修改 訂單查詢 {if empty($order_query)} 同上看下就知道了 訂單用戶ID {if $order_query.user_id} 訂單數量 {$lang.order_number} 訂單編號 {$order_query.order_sn} 裏面還有不少標籤,沒弄明白,之後在添加,修改 發貨查詢 {if $invoice_list} 當有完成的訂單測顯示 發貨列表 {foreach from=$invoice_list item=invoice} 訂單號名稱 {$lang.order_number} 訂單號 {$invoice.order_sn} 發貨單名稱 {$lang.consignment} 發貨單號 {$invoice.invoice_no} 銷售排行 {if $top_goods} 看看就知道 銷售列表 {foreach name=top_goods from=$top_goods item=goods} 產品短名稱 {$goods.short_name} 看例子: <!- {foreach name=top_goods from=$top_goods item=goods}-> <li class=」top10-li-{$smarty.foreach.top_goods.iteration}」> [url==」{$goods.url}」 title=」{$goods.name|escape:html}」>{$goods.short_name}</a></li> <!-{/foreach}-> 精品推薦 {if $best_goods} 看看就知道 精品推薦列表 {foreach from=$best_goods item=goods} 市場價名稱 {$lang.market_price} 市場價價格 {$goods.market_price} 促銷價名稱 {$lang.promote_price} 促銷價價格 {$goods.promote_price} 商店價名稱 {$lang.shop_price} 商店價價格 {$goods.shop_price} 你們看到了嗎??{$lang.xxxx_xxxx}以lang開頭的爲相對應的名稱 {$goods.xxxx_xxxx}以goods開頭的爲價格 {$page_title} 網站標題 {$keywords} 網站關鍵字標籤 {$description} 網站描述標籤 {$shop_notice} 商店公告 $new_articles 新文章{$article.short_title} 調用文章標題 {foreach from=$new_articles item=article} 循環的開始, {/foreach} 循環的結束 item --> 具體意義和用法? 表格一行一行的循環 <table> {foreach from=$new_articles item=article} <tr><td> {$article.short_title} </td></td> {/foreach} </table> from=$best_goods 表示循環的內容來自$best_goods $best_goods 精品商品推薦的標籤 {$goods.short_style_name} 表示goods 這個對象的商品名稱 $new_goods 新品上市 $hot_goods 熱賣商品 $categories 分類的標籤 $goods_list 商品標籤 商品圖片: <img src= {$goods.goods_img} /> 商品名稱:{$goods.goods_style_name} 商品貨號:{$goods.goods_sn}<br> 商品品牌: {$goods.goods_brand} 商品數量:{$goods.goods_number} 單位:{$goods.measure_unit} 添加時間:{$goods.add_time} 市場價格:{$goods.market_price} 本店價格:{$goods.shop_price_formated} 註冊用戶價格:{$rank_price.price} 註冊用戶價格:{$rank_price.price} 註冊用戶價格:{$rank_price.price} 商品id爲1的商品 <http://localhost/ecshop/goods.php?id=1> 郵件模板管理 商城在進行某些操做時能夠向用戶發送郵件提示。在本頁你能夠定製本身個性化的郵件的模板。郵件主題爲發送郵件的標題。郵件模板中有能夠替換的內容都用{$_var}方式表示。如下將解釋全部變量含義。 公共變量 {$shop_name} 網店名稱 {$sent_date} 郵件發送時間 發送密碼模板變量 {$user_name} 註冊賬號名 {$password} 網店爲用戶生成的新密碼 訂單確認模板變量 {$order.consignee} 訂單收貨人姓名 {$order.order_time} 訂單生成時間 {$order.order_sn} 訂單序號 發貨通知模板變量 {$order.consignee} 收貨人姓名 {$order.shipping_time} 發貨時間 {$confirm_url} 確認收貨的連接地址 訂單取消模板變量 {$order.consignee} 收貨人姓名 {$order.order_sn} 訂單序號 訂單無效模板變量 {$order.consignee} 收貨人姓名 {$order.order_sn} 訂單序號 發送紅包模板變量 {$user_name} 用戶註冊名 {$count} 紅包個數 {$money} 紅包個數金額 商品關鍵字 {$keyword} 商品描述 {$description} 商店標題 {$page_title} 商店公告 {$shop_notice} 文章列表 <ul> {foreach from=$new_articles item=article} <li>{$article.short_title}//文章標題</li> {/foreach} </ul> 精品推薦商品列表 <ul> {foreach from=$best_goods item=goods} <li><a href="{$goods.url}//商品url">{$goods.short_name}//商品名稱</a></li> {/foreach} </ul> 熱銷商品 <ul> {foreach from=$hot_goods item=hot} <li><a href="{$hot.url}//商品url"><img src="{$hot.thumb}//商品縮略圖"><br />{$hot.short_style_name}//商品名稱</a></li> {/foreach} </ul> 商品上市 <ul> {foreach from=$new_goods item=new} <li><a href="{$new.url}//商品url"><img src="{$new.thumb}//商品縮略圖"><br />{$new.short_style_name//商品名稱}</a></li> {/foreach} </ul> 分類列表/全部分類 {foreach from=$categories item=cat} <dl> <dt><a href="{$cat.url}//分類url">{$cat.name|escape:html}//分類名稱</a></dt> {foreach from=$cat.cat_id item=child} <dd> <a href="{$child.url}//子分類url">{$child.name|escape:html}//子分類名稱</a> <ul> {foreach from=$child.cat_id item=childer} <li><a href="{$childer.url}//子子分類url">{$childer.name|escape:html}//子子分類名稱</a></li> {/foreach} </ul> </dd> {/foreach} </dl> {/foreach} 調用includes/lib_insert.php文件中的insert_cart_info函數,獲取購物後結算信息 {insert name='cart_info'} 銷售排行 {foreach name=top_goods from=$top_goods item=top} <ul> <img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration"> //iteration:smarty自帶的循環次數 表示方法:$smarty.foreach.name.iteration {if $smarty.foreach.top_goods.iteration<4} <li class="topimg"><a href="{$top.url}//商品url"><img src="{$top.thumb}//商品縮略圖" alt="{$top.name|escape:html}//商品名稱"></a></li> {/if} <li {if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}> <a href="{$top.url}//商品url"><img src="{$top.thumb}//商品縮略圖" title="{$top.name|escape:html}//商品名稱">{$top.short_name}//商品名稱</a> {$lang.shop_rice}{$top.price}//商品價格 </li> </ul> {/foreach} 促銷活動/優惠活動 {if $promotion_info} <h3>{$lang.promotion_info}</h3> {foreach from=$promotion_info item=item key=key} {if $item.type eq "snatch"}//若是爲奪寶奇兵 <a href="snatch.php" title="{$lang.$item.type}//活動類型">{$lang.snatch_promotion}</a> {elseif $item.type eq "group_buy"}//若是爲團購 <a href="group_buy.php" title="{$lang.$item.type}//活動類型">{$lang.group_promotion}</a> {elseif $item.type eq "auction"} //若是爲拍賣 <a href="auction.php" title="{$lang.$item.type}//活動類型">{$lang.auction}</a> {elseif $item.type eq "favourable"} //若是爲優惠活動 <a href="favourable.php" title="{$lang.$item.type}//活動類型">{$lang.favourable}</a> {elseif $item.type eq "package"} //若是爲禮包 <a href="package.php" title="{$lang.$item.type}//活動類型">{$lang.package}</a> {/if} <a href="{$item.url}//活動url" title="{$lang.$item.type}{$item.act_name}{$item.time}//活動名稱及活動時間">{$item.act_name}//活動名稱</a> {/foreach} {/if}
ECSHOP,獲取當前分類下的品牌,大多數網站都有這功能,好比天貓緩存
今天研究了下,不知道這種方法可行不,反正目前效果是對的。 直接在原函數上改的,若是須要的話,能夠本身從新個函數 在lib_common.php裏找到function get_brands 在sql語句里加個參數$sql = "SELECT b.brand_id,變成這樣 $sql = "SELECT g.cat_id,b.brand_id, 而後完事.在頁面的時候,是在分類下嵌套的brand_list 如下代碼要放到分類foreach裏。就是判斷獲得的品牌中的商品的分類的ID和當前分類的ID是否一致,一致就顯示。 <!-- {if $brand_list} --> <!-- {foreach from=$brand_list item=brand} --> <!-- {if $brand.cat_id == $cat.id} --> <a href="{$brand.url}">{$brand.brand_name|escape:html} {if $brand.goods_num}({$brand.goods_num}){/if}</a> <!-- {/if} --> <!-- {/foreach} --> <!-- {/if} --> 但願大神看下有沒有BUG
ecshop首頁獲取分類下的品牌列表服務器
<?php /** * 得到某個分類下的品牌 列表 * * @access public * @param int $cat * @return array */ function get_cat_brands($cat = 0, $app = 'category') { $children = ($cat > 0) ? ' AND ' . get_children($cat) : ''; $sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, COUNT(g.goods_id) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag ". "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, ". $GLOBALS['ecs']->table('goods') . " AS g ". "WHERE g.brand_id = b.brand_id $children " . "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC"; $row = $GLOBALS['db']->getAll($sql); foreach ($row AS $key => $val) { $row[$key]['url'] = build_uri($app, array('cid' => $cat, 'bid' => $val['brand_id']), $val['brand_name']); } return $row; } ?>
ECSHOP商品頁調用該商品評論數量方法cookie
熟悉ECSHOP的都知道,ECSHOP使用了緩存機制,因此爲了能即時的反映最新的評論數,本方法使用的是 insert 函數形式,這樣作的好處是能自動顯示最新的評論數,而不須要常常去清除緩存。 下面是具體方法: 首先打開 includes/lib_insert.php 文件,在最下面增長一個函數(注意別加在 「?>」外面 ) /** * *調用用戶評論 * */ function insert_comments_count($arr) { /*取得評論條數*/ $count=$GLOBALS['db']->getOne('select count(*) from'. $GLOBALS['ecs']->table('comment'). "where id_value='$arr[id]' AND comment_type='$arr[type]'AND status=1 and parent_id=0"); return $count; } 而後再修改商品詳情模板文件 themes/default/goods.dwt 在你想顯示評論數量的地方加入下面代碼 評論數量:{insert name=comments_count type=$type id=$id} 或者{insert name=comments_count type=$type id=$goods.id} 至此,大功告成
ecshop 評價仿京東仿淘寶 中評率 好評率 差評率
1.在goods.php中添加 //中差評 $sql="select * from ".$ecs->table('comment')." where comment_type=0 and status=1 and comment_rank!=0 and id_value=$goods_id"; $comments=$db->getall($sql); $count=count($comments); $zhonghao=''; $zhonghaoimg=''; $hao=0; $zhong=0; $cha=0; $haol=''; $zhongl=''; $chal=''; foreach($comments as $value){ if($value['comment_rank'] == 1){ $cha=$cha+1; } if($value['comment_rank'] == 2 or $value['comment_rank'] == 3 or $value['comment_rank'] == 4){ $zhong=$zhong+1; } if($value['comment_rank'] == 5){ $hao=$hao+1; } } $smarty->assign('zhonghao', round($hao/$count*100,0)); $smarty->assign('count', $count); $smarty->assign('zhong', round($zhong/$count*100,0)); $smarty->assign('cha', round($cha/$count*100,0)); $smarty->assign('haol', round($hao/$count*100/100*143,0)); $smarty->assign('zhongl', round($zhong/$count*100/100*143,0)); $smarty->assign('chal', round($cha/$count*100/100*143,0)); $smarty->assign('zhonghaoimg', round($hao*5/$count,0)); 接下來就是在模板中調用 這些就能夠了 $smarty->assign('haol', round($hao/$count*100/100*143,0)); 這裏面的 143 是那個評價進度條的總長度 ecshop二次開發 聯繫QQ 1595192997
ecshop首頁顯示的價格,改成登陸查看
在index.dwt中找到<!-- {if $goods.promote_price neq ""} --> {$lang.market_price} <span class="market-price">{$goods.market_price}</span><br /> {$lang.promote_price} <span class="goods-price">{$goods.promote_price}</span><br /> <!--{else}--> {$lang.market_price} <span class="market-price">{$goods.market_price}</span><br /> {$lang.shop_price} <span class="goods-price">{$goods.shop_price}</span> <!--{/if}--> ad:ecshop模板改成: <!--若是會員登錄了{if $smarty.session.user_name}--> <!-- {if $goods.promote_price neq ""} --> {$lang.market_price} <span class="market-price">{$goods.market_price}</span><br /> {$lang.promote_price} <span class="goods-price">{$goods.promote_price}</span><br /> <!--{else}--> {$lang.market_price} <span class="market-price">{$goods.market_price}</span><br /> {$lang.shop_price} <span class="goods-price">{$goods.shop_price}</span> <!--{/if}--> <!--若是沒登錄{else}--> 商品價格:<span class="goods-price">請登錄後查看</span> <!--{/if}-->
獲取商品好評率
1.在lib_insert.php裏面增長如下函數 /** * *獲取好評率 * */ function insert_comments_rank($arr) { /*取得評論條數*/ $count=$GLOBALS['db']->getOne('select count(*) from'. $GLOBALS['ecs']->table('comment'). "where id_value='$arr[id]' AND comment_type='$arr[type]'AND status=1 and parent_id=0"); /*取得評論條數*/ $count_rank=$GLOBALS['db']->getOne('select count(*) from'. $GLOBALS['ecs']->table('comment'). "where id_value='$arr[id]' AND comment_type='$arr[type]'AND status=1 and parent_id=0 and comment_rank=5"); if($count==0) $comments_rank=0; else $comments_rank=round($count_rank/$count,3)*100; return $comments_rank; } 2.模板調用 {insert name=comments_rank type=$type id=$goods.id}% 或者 {insert name=comments_rank type=$type id=$id}%
首頁調用商品好評率
1.在lib_insert.php中加入以下函數 /** * *獲取好評率 * */ function insert_comments_rank($arr) { /*取得評論條數*/ $count=$GLOBALS['db']->getOne('select count(*) from'. $GLOBALS['ecs']->table('comment'). "where id_value='$arr[id]' AND comment_type='$arr[type]'AND status=1 and parent_id=0"); /*取得評論條數*/ $count_rank=$GLOBALS['db']->getOne('select count(*) from'. $GLOBALS['ecs']->table('comment'). "where id_value='$arr[id]' AND comment_type='$arr[type]'AND status=1 and parent_id=0 and comment_rank=5"); if($count==0) $comments_rank=100; else $comments_rank=round($count_rank/$count,3)*100; return $comments_rank; } 2.在模板中加入 {insert name=comments_rank type=$type id=$goods.goods_id}或 {insert name=comments_rank type=$type id=$goods.id}
首頁獲取好評
在首頁調用用戶好評 /** * 得到最新的評論列表。 * * @access private * @return array */ function get_mycomments($num) { $sql = 'SELECT id_value, user_name, content, add_time, comment_rank FROM ' . $GLOBALS['ecs']->table('comment') . ' WHERE comment_rank = 5 AND status = 1 ORDER BY comment_id DESC LIMIT 5'; if ($num > 0) $res = $GLOBALS['db']->getAll($sql); $comments = array(); foreach ($res AS $idx => $row) { $comments[$idx]['user_name'] = $row['user_name']; $comments[$idx]['content'] = $row['content']; $comments[$idx]['id_value'] = $row['id_value']; $comments[$idx]['add_time'] = date('Y年m月d日', $row['add_time']); $comments[$idx]['comment_rank'] = $row['comment_rank']; } return $comments; } 這樣是調出 5 星的 那麼我想再調用綜合評分 得怎麼改呢? 我貼出來的就能夠在首頁顯示了 加在INDEX.PHP裏 <!--{foreach from=$my_comments item=comments}--> <li>{$comments.add_time} <a href="goods.php?id={$comments.id_value}&lmtrk=ad%3D991">{$comments.content|truncate:25:""}</a></li> 這個是調用 $smarty->assign('my_comments', get_mycomments(5)); // ‘5’表明首頁顯示5條評論 加在129行上面
首頁獲取評論列表
1.在index.php中找到 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告 下添加 $smarty->assign('my_comments', get_comments(10)); //評論添加 2.在index.php最後添加 function get_comments($num) { $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('comment') . ' WHERE status = 1 AND parent_id = 0 and comment_type=0 '. ' ORDER BY add_time DESC'; if ($num > 0) { $sql .= ' LIMIT ' . $num; } //echo $sql; $res = $GLOBALS['db']->getAll($sql); $comments = array(); foreach ($res AS $idx => $row) { $comments[$idx]['add_time'] = $comments[$idx]['add_time'] = local_date ($GLOBALS['_CFG']['time_format'], $row['add_time']); $comments[$idx]['user_name'] = $row['user_name']; $comments[$idx]['content'] = $row['content']; $comments[$idx]['id_value'] = $row['id_value']; } return $comments; } 3.模板調用 <!--{foreach from=$my_comments item=comments}--> <li class=""><em>1</em> <a href="goods.php?id={$comments.id_value}" target="_blank">{$comments.content|truncate:15:""}</a> {$comments.add_time} </li> <!--{/foreach}-->
ECSHOP的lbi庫文件中添加廣告位的方法
通常的廣告位是寫在dwt文件裏的。 也有人但願能直接寫在lbi文件裏。其實也很簡單,看一下操做方法: 先進入ECSHOP後臺,在後臺發佈好廣告位和廣告,記住這個廣告位的ID,這裏暫時假設該ID爲2 而後修改 lbi 文件 在想顯示廣告位的地方加入下面代碼便可, {insert name='ads' id=2 num=1} 注意:代碼裏面的id必定要是相對應的廣告的ID
ecshop 如何調整商品屬性篩選項的顯示順序
ecshop 如何調整商品屬性篩選項的顯示順序? 如何調整商品屬性篩選項的顯示順序? 也就是這個問題 http://bbs.ecshop.com/thread-99839-1-1.html 如何調整商品屬性篩選項的顯示順序? 好比說屬性篩選顯示爲: 品牌 價格 重量:9KG ,6KG, 8KG, 18KG 如何調整爲 重量:6KG ,8KG, 9KG, 18KG 解決方案:在網上找了幾天,沒發現有啥好方法。我最後使用了一招,能夠輕鬆搞定,只是之後維護起來比較麻煩點。 思路:在頁面上寫死了屬性各個值的順序,添加連接便可。 操做:在原來的頁面右擊查看源代碼,你能夠看到源代碼,將須要的代碼複製,而後修改category.dwt. 代碼以下: View Code <!--{foreach from=$filter_attr_list item=filter_attr}--> <!-- {if $filter_attr.filter_attr_name=='攝像頭像素'} --> <!--start:攝像頭像素--> <dl class="cls"> <dt>攝像頭像素:</dt> <dd> <ul class="cls"> <li><a href="#">所有</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.6316.0">130萬如下</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.7402.0">130萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.1020.0">200萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.410.0">300萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.1101.0">320萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.391.0">500萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.452.0">800萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.0">900萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10862.0">1000萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.478.0">1200萬</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.5355.0">1300萬</a></li> </ul> </dd> </dl> <!--end:攝像頭像素--> <!-- {elseif $filter_attr.filter_attr_name=='價格區間'} --> <dl class="cls"> <dt>價格區間:</dt> <dd> <ul class="cls"> <li><a href="#">所有</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6293">0-500</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6294">500-1000</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6394">1000-1500</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6252">1500-2000</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6118">2000-3000</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.7546">3000-4000</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6120">4000-5000</a></li> <li> <a href="category.php?id=1&price_min=0&price_max=0&filter_attr=0.0.10851.6119">5000以上</a></li> </ul> </dd> </dl> <!-- {else} --> <dl class="cls">
ECSHOP 首頁顯示某些分類的推薦商品
ECSHOP 首頁顯示某些分類的推薦商品 若是要在首頁顯示「指定分類下的商品」能夠經過後臺的「設置模板 」->「[+] 分類下的商品」進行設置, 但要在首頁顯示「指定分類下的精品」的話,簡單修改模板或者後臺設置是實現不了的。 「設置模板 」->「[+] 分類下的商品」的實現是經過function assign_cat_goods($cat_id, $num = 0, $from = 'web')實現的 ecshop中首頁顯示的商品是「精品/新品/熱銷/促銷」四類,也能夠經過tag方式顯示指定分類下的推薦商品,可是在點擊tag後經過ajax讀取的,不能直接顯示。 若是要在首頁上直接顯示, 方案一:修改模板--在頁面onload後,經過ajax讀取,若是網絡或服務器慢,一開始會顯示空白,用戶體驗較差 方案二:修改index.php,第一次加載就把特定目錄的推薦商品smarty->assign到指定變量中。版本升級的時候要注意。 方案二實現: 步驟一: 在index.php中找到: assign_dynamic('index'); } $smarty->assign('show_marketprice', $_CFG['show_marketprice']); $smarty->display('index.dwt', $cache_id); 在其前面加上對應代碼,成爲: /*二次開發,添加三個推薦專區*/ $my_cat_rec_goods=array(); $my_cat_rec_goods[2]=get_category_recommend_goods('best', get_children(2)); $my_cat_rec_goods[253]=get_category_recommend_goods('best',get_children(253)); $my_cat_rec_goods[5]=get_category_recommend_goods('best', get_children(5)); $smarty->assign('my_cat_rec_goods', $my_cat_rec_goods); assign_dynamic('index'); } $smarty->assign('show_marketprice', $_CFG['show_marketprice']); $smarty->display('index.dwt', $cache_id); 步驟二: 在模板相應位置加上: <!-- {if $my_cat_rec_goods[2]} --> <!--{foreach from=$my_cat_rec_goods[2] item=goods}--> abc <!--{/foreach}--> <!-- {/if} --> 若是其餘頁面須要這個功能,只要該頁面包含lib_common.php 和lib_goods.php便可使用,由於 這用到兩個函數get_children和get_category_recommend_goods ECSHOP首頁調用某個分類下的商品 2011-01-30 15:33:47| 分類: ECSHOP | 標籤:調用 goods 分類 商品 ecshop |字號大 中 小 訂閱 調用某個分類下的商品,方法有不少種的,不過都須要先在後臺設置模板那裏設置顯示和顯示條數, 而後在須要調用的模板裏放上相應的代碼便可: 一、好比: <?php $this->assign(’cat_goods’,$this->_var['cat_goods_15']); ?> <?php $this->assign(’goods_cat’,$this->_var['goods_cat_15']); ?> <?php echo $this->fetch(’library/cat_goods.lbi’); ?> 上面的15就是某個要調用的欄目ID值.把它改爲其餘你要調用的分類ID值便可. 2、這是第二種: <!-{foreach from=$cat_goods_14 item=goods}-> <div class=」xgoods」> <div class=」img」><a href=」{$goods.url}」 target=」_blank」><img src=」{$goods.thumb}」 alt=」{$goods.name|escape:html}」 width=」67″ height=」56″ border=」0″ class=」imgb」/></a></div> <div class=」name」><a href=」{$goods.url}」 target=」_blank」>{$goods.short_name|escape:html|truncate:10}</a><br /> <span class=」fontr fontb fontbig」>{$goods.shop_price}</span></div> </div> <!-{/foreach}-> 說明:上面的$cat_goods_14 ,其中14就是你想要調用的欄目ID值,把它改爲你要調用的欄目ID值便可。 3、第三種:先在要調用的模板裏設置區域,好比: <!- TemplateBeginEditable name=」某分類區域」 -><!- TemplateEndEditable -> 而後在後臺設置模板那裏增長分類顯示時選此區域便可。
ecshop商品分類頁、商品內容頁顯示全部商品分類
方法很簡單: category.php 裏找到 get_categories_tree($cat_id)) 改爲 get_categories_tree(0)) 約322行 goods.php 裏找到 get_categories_tree($goods['cat_id'])) 改爲 get_categories_tree(0)) 約180行 這樣不管在哪一級目錄都會完整顯示全部分類
在ECSHOP首頁顯示積分商城裏的商品
今日看到論壇裏有些朋友在討論「如何在首頁調用積分商城裏的商品」, 也有一些朋友已經寫出了大部分代碼,可是因爲個別錯誤,未能實現。 下面就以ECSHOP2.7.2官方默認模板爲基礎,給你們提供一個完整的解決方案。 (本教程由ECSHOP120(www.ecshop120.com)提供,如要轉載,請註明出處) 1)、 首先打開 index.php 文件 在最末尾增長下面函數,注意千萬不要寫到 「?>」 的外面去,要加在「?>」的前面。 /** * 得到積分商城熱門商品 * * @param int $limit 列出條數 * @param int $ishot 是否只顯示熱銷 * @return array */ function index_get_exchange($limit=3,$ishot=0) { /* 得到熱門積分商品列表 */ $sql_ishot=$ishot ? " AND eg.is_hot=1 " : ""; $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' . ' g.goods_type,g.goods_brief, g.goods_thumb, g.goods_img, eg.is_hot ' . ' FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = eg.goods_id ' . ' WHERE eg.is_exchange = 1 AND g.is_delete = 0 '. $sql_ishot .' limit '.$limit; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach($res AS $idx => $row) { $arr[$idx]['name'] = $row['goods_name']; $arr[$idx]['goods_brief'] = $row['goods_brief']; $arr[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']); $arr[$idx]['exchange_integral'] = $row['exchange_integral']; $arr[$idx]['type'] = $row['goods_type']; $arr[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$idx]['url'] = build_uri('exchange_goods', array('gid'=>$row['goods_id']), $row['goods_name']); } return $arr; } 而後繼續在 index.php 文件中 找到 $smarty->assign('shop_notice', $_CFG['shop_notice']); // 商店公告 在它下邊另起一行增長以下代碼 $smarty->assign('goods_exchange_list',index_get_exchange(6,0)); //積分商城 若是你想只顯示熱銷的積分商品,只需將上面代碼稍做修改便可 $smarty->assign('goods_exchange_list',index_get_exchange(6,1)); //積分商城 2)、下面繼續修改模板文件 themes/default/index.dwt 在你想顯示積分商城商品的地方,加入下面代碼段 <!--積分商城列表--> <div class="box"> <div class="box_1"> <h3><span><a href="/exchange.php" class="f6">積分商城</a></span></h3> <div class="centerPadd"> <div class="clearfix goodsBox" style="border:none;"> <!--{foreach name=goods_exchange_list from=$goods_exchange_list item=exchange_goods}--> <div class="goodsItem"> <a href="{$exchange_goods.url}" target="_blank"><img src="{$exchange_goods.goods_thumb}" alt="{$exchange_goods.goods_name}" class="goodsimg" /></a><br /> <p><a href="{$exchange_goods.url}" target="_blank"> <!-- {if $exchange_goods.goods_style_name} --> <font class="f3">{$exchange_goods.goods_style_name}</font><br /> <!-- {else} --> <font class="f3">{$exchange_goods.goods_name}</font><br /> <!-- {/if} --> </a> </p> {$lang.exchange_integral}<font class="price">{$exchange_goods.exchange_integral}</font> </div> <!--{/foreach}--> <div class="more"><a href="/exchange.php"><img src="images/more.gif" /></a></div> </div> </div> </div> </div> <div class="blank5"></div> 3)、到後臺清除下緩存,而後刷新首頁就能看到效果了,效果圖以下
ECSHOP怎樣調用指定分類的文章
1、要求: echop技術 在ECSHOP商城首頁的「站內快訊」裏只顯示某個特定分類下的文章, 例如只顯示 類別ID爲 5 的文章。 2、修改方法: 使用editplus 或者 dreamweaver 打開 index.php文件(若是你的是UTF-8編碼,儘可能不要使用記事本), 找到 index_get_new_articles() 函數部分 將 ' WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' . 修改成 ' WHERE a.is_open = 1 AND a.cat_id=5 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' .
ecshop調用指定分類的文章_百度文庫
舉例如首頁調用方法: 一、先打開index.php文件找到如下代碼: $smarty->assign('new_articles', index_get_new_articles()); // 最新文章 在它下面增長如下: //調用方法 $smarty->assign('class_articles_4', index_get_class_articles(4,6)); // 分類調用文章 //調用多個就修改傳進去的參數,以及模板接收的變量,其中上面的4就是文章分類ID,其中6是調用數量 $smarty->assign('class_articles_5', index_get_class_articles(5,6)); // 分類調用文章 $smarty->assign('class_articles_6', index_get_class_articles(6,6)); // 分類調用文章 $smarty->assign('class_articles_7', index_get_class_articles(7,6)); // 分類調用文章 $smarty->assign('class_articles_8', index_get_class_articles(8,6)); // 分類調用文章 //在最後?>這個以前增長如下函數 /** * 得到指定欄目最新的文章列表。 * * @access private * @return array */ function index_get_class_articles($cat_aid, $cat_num) { $sql = "SELECT article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " WHERE cat_id = ".$cat_aid." and is_open = 1 LIMIT " . $cat_num; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($res AS $idx => $row) { $arr[$idx]['id'] = $row['article_id']; $arr[$idx]['title'] = $row['title']; $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$idx]['cat_name'] = $row['cat_name']; $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $arr[$idx]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id'])); } return $arr; } 二、第二步是在index.dwt模板想調用的地方增長如下代碼,(注:如下調上面設置裏的分類ID爲8的文章列表): <!--{foreach from=$class_articles_8 item=article}--> <li><a href="{$article.url}" title="{$article.title|escape:html}"><!--{$article.short_title|truncate:15:true}--></a></li> <!--{/foreach}--> ECSHOP得到指定欄目最新的商品列表2010-08-29 12:19ECSHOP得到指定欄目最新的商品列表 舉例如首頁調用方法: 一、先打開index.php文件找到如下代碼: $smarty->assign('new_articles', index_get_new_articles()); // 最新文章 在它下面增長如下: //調用方法 $smarty->assign('class_articles_4', index_get_class_articles(4,6)); // 分類調用文章 //調用多個就修改傳進去的參數,以及模板接收的變量,其中上面的4就是文章分類ID,其中6是調用數量 $smarty->assign('class_articles_5', index_get_class_articles(5,6)); // 分類調用文章 $smarty->assign('class_articles_6', index_get_class_articles(6,6)); // 分類調用文章 $smarty->assign('class_articles_7', index_get_class_articles(7,6)); // 分類調用文章 $smarty->assign('class_articles_8', index_get_class_articles(8,6)); // 分類調用文章 二、在lib_goods.php增長如下函數 /** * 得到指定欄目最新的文章列表。 * * @access private * @return array */ function index_get_class_articles($cat_aid, $cat_num) { $sql = "SELECT article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " WHERE cat_id = ".$cat_aid." and is_open = 1 LIMIT " . $cat_num; $res = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($res AS $idx => $row) { $arr[$idx]['id'] = $row['article_id']; $arr[$idx]['title'] = $row['title']; $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$idx]['cat_name'] = $row['cat_name']; $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $arr[$idx]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id'])); } return $arr; } 三、第二步是在index.dwt模板想調用的地方增長如下代碼,(注:如下調上面設置裏的分類ID爲8的文章列表): <!--{foreach from=$class_articles_8 item=article}--> <li><a href="{$article.url}" title="{$article.title|escape:html}"><!--{$article.short_title|truncate:15:true}--></a></li> <!--{/foreach}-->
ecshop首頁調取指定分類文章的辦法
此方法不必定可以獲取到指定數量的文章 ecshop目前是國內最熱門流行的開源電子商務系統,爲了達到不一樣的需求,每每須要通過不斷的二次開發。今天就遇到一個問題,須要給一個網站首頁同時調用多個不一樣分類下的文章,每一個分類下顯示對應的文章,所用的版本是2.7.2的,ecshop更新時間緩慢,這點從另外一方面講也是好事。 偷懶上網搜索,方法挺多的,有人說能夠調用ecshop自帶函數get_cat_articles,有人說修改自帶的index_get_new_articles() 函數的SQL語句,指定一個分類id,還有人說調用自創的分類文章函數index_get_class_articles,研究了一下,最後這些所有推翻,用了一個並不複雜的辦法。 給首頁顯示最新文章的模板部分加一個判斷函數,根據分類ID判斷就能夠。 方法以下: 打開根目錄下的index.php文件,搜索如下代碼: $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']); 在下面加一行代碼 $arr[$idx]['cat_id'] = $row['cat_id']; 這樣就能夠獲取到各文章分類的ID了。 接下來咱們在首頁調用文章的地方加一句判斷分類ID的過濾。舉例: <!--{foreach from=$new_articles item=article}--> <!--{if $article.cat_id == 6}--> <li><a title="{$article.title|escape:html}" href="{$article.url}">{$article.cat_id}:{$article.short_title|truncate:10:"...":true}</a></li> <!--{/if}--> <!--{/foreach}--> 這段代碼的意思是調取分類ID爲6的最新文章,具體使用的時候請參考酌情修改。 說到這裏,還有一種方法不用修改index.php文件,就可調取指定分類文章。原理就是過濾文章分類名,不過感受執行效率上稍微差一點。 舉例: <!--{foreach from=$new_articles item=article}--> <!--{if $article.cat_name eq '網站公告'}--> <li><a title="{$article.title|escape:html}" href="{$article.url}">{$article.cat_id}:{$article.short_title|truncate:10:"...":true}</a></li> <!--{/if}--> <!--{/foreach}--> 這段代碼能夠解釋爲調取分類名爲「網站公告」的最新文章。
ECSHOP文章列表改成顯示內容提要方法
能夠提取詳細內容的固定字符寬度 修改:includes\lib_article.php 找到 function get_cat_articles($cat_id, $page = 1, $size = 20) 函數 在 $sql = 'SELECT article_id, title,content, author, add_time, file_url, open_type' . ' FROM ' .$GLOBALS['ecs']->table('article') . " WHERE is_open = 1 AND " . $cat_str . ' ORDER BY article_type DESC, article_id DESC'; 增長 content 字段 在 $arr[$article_id]['add_time'] = date($GLOBALS['_CFG']['date_format'], $row['add_time']); 下面 增長 $arr[$article_id]['content'] = $row['content']; article_cat.dwt 調用 例子 {$article.content|strip_tags|truncate:20:"..."} 顯示前20字符 多餘的 使用 ...代替 ecshop首頁顯示的價格,改成登陸查看
ecshop獲取指定類型下的文章
ECSHOP得到指定商品分類下全部的商品關聯文章 ECSHOP得到指定商品分類下全部的商品關聯文章 /** * 得到指定分類下全部商品的關聯文章 * sun04zh3-20130321 * @access public * @param integer $cat_id * @return array */ function get_category_linked_articles($cat_id) { $sql = 'SELECT a.article_id, a.title, a.file_url, a.open_type, a.add_time ' . 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' AS ga, ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . $GLOBALS['ecs']->table('goods').' AS g '. "WHERE ga.article_id = a.article_id AND ".get_children($cat_id)." AND a.is_open = 1 and ga.goods_id = g.goods_id " . 'ORDER BY a.add_time DESC'; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $row['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid'=>$row['article_id']), $row['title']) : trim($row['file_url']); $row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $row['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[] = $row; } return $arr; } category.dwt模版頁調用: <!--{foreach from=$article_list_jnc item=jnclist}--> <li><a href="{$jnclist.url}" title="{$jnclist.title}">{$jnclist.title}</a></li> <!--{/foreach}--> category.php對應程序頁調用: $smarty->assign('article_list', get_category_linked_articles(8)); 分類: php
文章列表顯示縮略圖
1.打開includes/lib_article.php 找到 $arr[$article_id]['content'] = $row['content']; 下面添加 $arr[$article_id]['file_url'] = $row['file_url'];//文章附件地址 preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $row['content'],$matches);//帶引號 //preg_match_all("/<img([^>]*)\ssrc=([^\s>]+)/",$string,$matches);//不帶引號 $new_arr=array_unique($matches[0]);//去除數組中重複的值 //foreach($new_arr as $key){ // echo $key."</br>"; //} $arr[$article_id]['pic_url'] =reset($new_arr);//返回數組中第一個 模板中引用 <!--{if $article.pic_url}--> {$article.pic_url} <img src="{$article.pic_url}" width="175" height="145" border="0" style="border:1px solid #cccccc; padding:1px;"> </td> <!--{/if}-->
ECSHOP二次開發-首頁在每一個商品下顯示已銷售量
ECSHOP二次開發-首頁在每一個商品下顯示已銷售量 最近有些客戶問如何才能讓首頁每一個商品顯示已銷售量, 其實很簡單,首先打開 includes/lib_goods.php 在最下面添加 function get_buy_sum($goods_id) { $sql = "select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = " . $goods_id . " and o.order_status=1 " ; return $GLOBALS['db']->getOne($sql); } 而後找到 $goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : ''; 在它下面添加 $goods[$idx]['buy_num']= get_buy_sum($row['goods_id']); 而後經過模板文件調用,好比新品,就在recommend_new.lbi文件中, 在你想要添加的位置 添加 {if $goods.buy_num} {$goods.buy_num} {else} 0 {/if} 這樣就能夠了。
ECSHOP首頁商品累計銷售量顯示
在商品詳情頁顯示累計售出量 1、 對於交易量很大的網站,每一個商品的「累計售出」個數可能隨時都在變化, 因此本方法使用了 insert 函數來實現,以達到能體現實時最新的銷售量(也就是銷售量不會被緩存) 二、修改 includes/lib_insert.php 文件 在最下面增長一個函數 /** * 調用某商品的累積售出 */ function insert_goods_sells($arr) { $sql = 'SELECT SUM(goods_number) AS number ' . ' FROM ' . $GLOBALS['ecs']->table('order_goods') ." AS og , " . $GLOBALS['ecs']->table('order_info') ." AS o ". " WHERE og.order_id = o.order_id and og.goods_id=".$arr['goods_id']; $row = $GLOBALS['db']->GetRow($sql); if ($row) { $number = intval($row['number']); } else { $number = 0; } return $number; } 三、修改 模板文件夾下 goods.dwt 文件 在 <strong>{$lang.goods_click_count}:</strong>{$goods.click_count} 下面增長一行代碼 <strong>累計售出:</strong>{insert name='goods_sells' goods_id=$id}{$goods.measure_unit}
ECSHOP首頁銷量和ECSHOP分類頁銷量的修改方法
首頁: 這個須要修改一個程序文件 lib_goods.php 實如今文件末尾添加一個函數 function get_buy_sum($goods_id) { $sql = "select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = " . $goods_id . " and o.order_status=1 " ;//o.order_status=1 表示確認了的訂單纔算 return $GLOBALS['db']->getOne($sql); } 而後找到 在get_recommend_goods函數中 大體325行 $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); 其後添加 $goods[$idx]['buy_num'] = get_buy_sum($row['goods_id']); 剩下的就是經過在模板中用 {if $goods.buy_num} {$goods.buy_num} {else} 0 {/if} 調用了 分類頁 修改 category.php 文件 在 $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; 下增長 $sql="select NULLum(goods_number),0) from ". $GLOBALS['ecs']->table('order_goods') . " AS og , ". $GLOBALS['ecs']->table('order_info') ." AS o where o.order_id =og.order_id and o.order_status >0 and og.goods_id=".$row['goods_id']; $arr[$row['goods_id']]['count_sell']=$GLOBALS['db']->getOne($sql); 而後修改 library/goods_list.lbi 在你想顯示購買數量的地方加入下面代碼: 銷售數量:{$goods.count_sell}
ecshop各個頁面調用商品銷售量方法
首頁的推薦商品包括熱銷推薦和促銷三個文件 只對熱銷商品爲例 第一步:打開根目錄/includes/lib_goods.php文件。在文件末尾添加方法 function selled_count($goods_id){$sql= "select sum(goods_number) as count from ".$GLOBALS['ecs']->table('order_goods')."where goods_id ='".$goods_id."'";$res = $GLOBALS['db']->getOne($sql);if($res>0){return $res;}else{return('0');}} 第二步:搜索get_recommend_goods方法 在這個方法中找到這句話 $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); 在這句話下添加$goods[$idx]['count'] = selled_count($row['goods_id']); 第三步:在模版的library/recommend_hot.lbi中在須要的地方添加 <div class="index_hotbg">售出 <strong>{$goods.count}</strong> 瓶</div> 首頁分類下的商品,實現「已售出」。 第一步:分類下商品也須要修改lib_goods.php。找到分類下的商品 assign_cat_goods方法。在 $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);句話下添加 $goods[$idx]['count'] = selled_count($row['goods_id']); 第二步:須要修改模版文件/library/cat_goods.lbi。在須要的地方添加 銷售量:{$goods.count} 在商品分類頁面調用已售出 第一步:修改根目錄下category.php找到category_get_goods方法函數中foreach循環添加$arr[$row['goods_id']]['count'] = selled_count($row['goods_id']);第二步:文件的最後部分添加函數function selled_count($goods_id){$sql= "select sum(goods_number) as count from ".$GLOBALS['ecs']->table('order_goods')."where goods_id ='".$goods_id."'";$res = $GLOBALS['db']->getOne($sql);if($res>0){return $res;}else{return('0');}}第三步:在模版文件goods_list.lbi中須要的地方添加銷售量:{$goods.count} 說明:搜索頁面須要修改search.php 在搜索頁面調用已售出多少件 第一步:打開根目錄/search.php 在最後加上 function selled_count($goods_id){$sql= "select sum(goods_number) as count from ".$GLOBALS['ecs']->table('order_goods')."where goods_id ='".$goods_id."'";$res = $GLOBALS['db']->getOne($sql);if($res>0){return $res;}else{return('0');}}方法 第二步:在頁面搜索 $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); 在下面添加 $arr[$row['goods_id']]['count'] = selled_count($row['goods_id']);第三步:打開模版文件/search.dwt在須要的地方調用。銷售量:{$goods.count}
獲取指定類別下的全部商品
1.獲取指定類別的文章
2.獲取指定類別下的全部商品
http://blog.sina.com.cn/s/blog_75ad10100100vamj.html
http://blog.sina.com.cn/s/blog_75ad10100100vamj.html
http://blog.sina.com.cn/s/blog_75ad10100100y9up.html
Ecshop模板
http://down.admin5.com/moban/ECShop/