ecshop3 调用指定分类下推荐/热卖/新品商品,可指定调用数量

第一步:--------------------------------------------------------------------------------------/** * 取指定分类ID及类型的商品信息 * @access public * @param string $cat_id 分类ID * @param string $num 显示商品数量 * @param string $cat_type 显示商品类型 new新品,hot热销,best为精品,promote特价 * @param auther 邓士鹏(自定义函数) * @return array */function index_get_cat_id_goods_list($cat_id = ‘‘, $num = ‘‘,$cat_type=‘‘){    $sql = ‘Select g.goods_id, g.cat_id,c.parent_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, " .        "g.is_best, g.is_new, g.is_hot, g.is_promote " .        ‘FROM ‘ . $GLOBALS[‘ecs‘]->table(‘goods‘) . ‘ AS g ‘ .        ‘LEFT JOIN ‘ . $GLOBALS[‘ecs‘]->table(‘category‘) . ‘ AS c ON c.cat_id = g.cat_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 ".        $sql .= " AND (c.parent_id =" . $cat_id. " or g.cat_id = " . $cat_id ." or g.cat_id ". db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) .")";    if($cat_type!=‘‘){        $sql .=" and is_".$cat_type."=1";    }else{        $sql .=" and is_best=0 and is_new=0 and is_hot=0 and is_promote=0";    }    $sql .= " order by g.goods_id desc LIMIT $num";    $res = $GLOBALS[‘db‘]->getAll($sql);    $goods = array();    foreach ($res AS $idx => $row)    {        $goods[$idx][‘id‘] = $row[‘article_id‘];        $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‘] = empty($row[‘goods_thumb‘]) ? $GLOBALS[‘_CFG‘][‘no_picture‘] : $row[‘goods_thumb‘];        $goods[$idx][‘goods_img‘] = empty($row[‘goods_img‘]) ? $GLOBALS[‘_CFG‘][‘no_picture‘] : $row[‘goods_img‘];        $goods[$idx][‘url‘] = build_uri(‘goods‘, array(‘gid‘ => $row[‘goods_id‘]), $row[‘goods_name‘]);    }    return $goods;}

?>
--------------------------------------------------------------------------------------

第二步:

打开根目录的 index.php 文件,在适当位置添加以下代码:

比如在

$smarty->assign(‘shop_notice‘,     $_CFG[‘shop_notice‘]);       // 商店公告--------添加
// new新品,hot热销,best为精品,promote特价$smarty->assign(‘cat_id1_new_goods‘, index_get_cat_id_goods_list(1,10));$smarty->assign(‘cat_id1_hot_goods‘, index_get_cat_id_goods_list(1,10,‘hot‘));$smarty->assign(‘cat_id1_hot_goods‘, index_get_cat_id_goods_list(1,10,‘promote‘));$smarty->assign(‘cat_id1_hot_goods‘, index_get_cat_id_goods_list(1,10,‘best‘));

根据自己的需要添加多条。

其中,1为分类ID,10为调用的数量。

如果不限制商品分类,分类ID可填 0

注:如果需要在 分类页调用,则在 category.php 文件中添加。

如果需要在 商品详情页调用,则在 good.php 文件中添加。

==================================================

<!--{foreach name=cat_id1_hot_goods from=$cat_id1_hot_goods item=goods}--><div style="padding-top: 8px;" class="new-tr">           <a target="_blank" href="{$goods.url}"><img width="116" height="130" border="0" alt="{$goods.name|escape:html}" src="{$goods.thumb}"></a>          <div class="right">          <a target="_blank" href="{$goods.url}">{$goods.name|escape:html}</a><br>          <span style="color: rgb(102, 102, 102); text-decoration: line-through;">市场价:{$goods.market_price}</span><br>特卖价:<span style="color: rgb(255, 0, 0);">{$goods.shop_price}</span><br>          <span class="font-gmm"><a  href="javascript:addToCart({$goods.id})">立即抢购</a></span>          </div>          <span class="new-line"></span>          </div><!--{/foreach}-->


原文地址:https://www.cnblogs.com/vip-deng-vip/p/9099818.html

时间: 2024-07-31 09:02:05

ecshop3 调用指定分类下推荐/热卖/新品商品,可指定调用数量的相关文章

ectouch手机商城首页调用指定分类下的商品

ECTouch是国内市面上唯一开源的ECSHOP移动商城系统,为广大电商以最低的成本快速搭建移动商城.最近最一商城实例,手机版首页需要调用指定分类下的商品,ECtouch商城默认好像没有此调用方式,只能自己动手添加了. 方法如下: 1.打开mobile\include\apps\default\model\IndexModel.class.php 在最下面 } 之前添加以下代码 /**      * 获得指定分类下的商品      */      function assign_cat_good

ecshop 首页调用指定分类下的销售排行

/*首页调用指定分类下的销售排行*/ function get_cats_top10($cat = '') { $sql = 'SELECT cat_id, cat_name ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '$cat' ORDER BY sort_order ASC, cat_id ASC LIMIT 3"; $res = $GLOBALS['db']->getAl

ecshop首页调用某分类下的商品|assign_cat_goods()

ecshop首页调用分类下的商品其实很简单,也有模板设置那里可以设置,不过那个只可以用cat_goods.lib,不方便,所以我想看看怎么能简单的实现ecshop首页调用分类下的商品 只需要在index.php写上这么一句:assign_cat_goods(20,10); 其中20是分类id,10是调用的条数 assign_cat_goods这个函数是在includes/lib_goods.php里面的 然后就是ecshop模板里调用商品了 <!–{foreach from=$cat_goods

ecshop调用制定分类下的分类

1.//在文件 includes/lib_goods.php最后加上 1 //*** 调用商品分类指定分类下级分类 2 function get_parentid_tree($parent_id) 3 { 4 $get_parentid_arr = array(); 5 $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_s

thinkphp 查询指定分类下的文章

$list = $Dao->query("SELECT xp_wztj.bt,xp_wztj.time,xp_wztj.gjz,xp_wztj.wz,xp_wzfl.name FROM xp_wztj, xp_wzfl WHERE xp_wztj.uid = xp_wzfl.id and xp_wzfl.name='丫丫' order by xp_wztj.id desc");

perl 遍历指定目录下的所有文件,替换指定文本内容,返回受影响的文件路径

不会读取 影藏文件 main #!/usr/bin/perl my ($path, $rp) = @ARGV; sub search_file{ my ($fname, $rp) = @_; # 获取操作文件名 和 查询的正则 my ($o) = split("/", $rp); open(of, "<$fname") or die "$fname 文件打开失败!$!"; while(<of>){ chomp; if($_ =~

Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件

脚本内容如下: #!/bin/bash function delete_file { dir=$1 days=$[$2-1] for i in `find $dir -type f -ctime +$days` do rm -rf $i done } while read line do dir=`echo $line

Linux下挂载指定分区下的某个文件夹到指定目录(mount)

# 挂载 mount --bind olddir newdir # 卸载 umount newdir 参考: http://www.cnblogs.com/dabaopku/archive/2010/12/18/1909965.html

ecshop首页调用指定商品分类下的商品品牌列表

转之--http://www.16css.com/ecshop/735.html 通过二次开发可以实现ECSHOP首页调用指定分类下的品牌列表. 第一步: 打开根目录下的index.php 在最后面 ?> 前面加入以下代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 /** * 获得某个分类下的品牌 列表 * * @access  public * @param   int     $cat * @return