ecshop 的一些常用操作

ecshop商品详细页显示已售商品数量和评论数量

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}-->
View Code

调用商品购买记录

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}
View Code

ecshop生成纯静态页面

ecshop生成纯静态页面浅见

纯静态页面具有占用资源小,速度快的特点。一直广受广大站长的喜欢。目前的ecshop只有伪静态,是否可以为ecshop增加伪静态呢?


建议配上ec伪静态使用,这样只要客户点击一次系统就自动生成一个静态页面,不需要后台批量生成了。

1、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-&gt;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']-&gt;make_html(‘index.dwt’);//根据index.dwt模板生成网页内容
 $filename = ROOT_PATH . $file;//静态网页路径
 file_put_contents($filename, $content);//生成文件 




其他也没类似,希望大家可以举一反三。

以上几条简单的语句,我们就可以生成首页的静态网页。同理,我们可以生成产品类别和产品的静态网页,整个系统的静态化就完成了。
View Code

让ECSHOP生成静态页面的方法!

伪静态已经基本上可以满足大部分人的需求,如果不满足的还可以根据前面的一篇文章对重写规则进行修改,以满足自己的需求。但是本文所要描述的是,根据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;  

   }
View Code

ECSHOP模板制作中常见循环的操作方法

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,至此结束,看看效果吧!
View Code

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}
View Code

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}
View Code

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
View Code

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;

}
?>
View Code

ECSHOP商品页调用该商品评论数量方法

熟悉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}

至此,大功告成
View Code

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
View Code

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}-->
View Code

获取商品好评率

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}%
View Code

首页调用商品好评率

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}
View Code

首页获取好评

在首页调用用户好评
/**
* 获得最新的评论列表。
*
* @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行上面
View Code

首页获取评论列表

 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}-->
View Code

ECSHOP的lbi库文件中添加广告位的方法

一般的广告位是写在dwt文件里的。

也有人希望能直接写在lbi文件里。其实也很简单,看一下操作方法:


先进入ECSHOP后台,在后台发布好广告位和广告,记住这个广告位的ID,这里暂时假设该ID为2


然后修改 lbi 文件

在想显示广告位的地方加入下面代码即可,

{insert name='ads' id=2 num=1}

注意:代码里面的id一定要是相对应的广告的ID
View Code

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">
View Code

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   |字号大
中
小 订阅 
调用某个分类下的商品,方法有很多种的,不过都需要先在后台设置模板那里设置显示和显示条数,
然后在需要调用的模板里放上相应的代码即可:
1、比如:
<?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 ->
然后在后台设置模板那里增加分类显示时选此区域即可。
View Code

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行

这样无论在哪一级目录都会完整显示所有分类
View Code

在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)、到后台清除下缓存,然后刷新首页就能看到效果了,效果图如下
View Code

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' .
View Code

ecshop调用指定分类的文章_百度文库

举例如首页调用方法:
1、先打开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;
}

2、第二步是在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获得指定栏目最新的商品列表



举例如首页调用方法: 
1、先打开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)); // 分类调用文章 
2、在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; 
} 
3、第二步是在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}--> 
View Code

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}-->
这段代码可以解释为调取分类名为“网站公告”的最新文章。
View Code

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首页显示的价格,改为登录查看
View Code

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
View Code

文章列表显示缩略图

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}-->
View Code

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} 
这样就可以了。
View Code

ECSHOP首页商品累计销售量显示

在商品详情页显示累计售出量
1、
对于交易量很大的网站,每个商品的“累计售出”个数可能随时都在变化,
所以本方法使用了 insert 函数来实现,以达到能体现实时最新的销售量(也就是销售量不会被缓存)
2、修改 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;
}

3、修改 模板文件夹下 goods.dwt 文件

在
<strong>{$lang.goods_click_count}:</strong>{$goods.click_count}
下面增加一行代码
<strong>累计售出:</strong>{insert name='goods_sells' goods_id=$id}{$goods.measure_unit}
View Code

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}
View Code

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}
View Code

 

获取指定类别下的所有商品

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/

 

转载于:https://www.cnblogs.com/blogpro/p/11464745.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值