博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ecshop调用指定商品分类下的商品
阅读量:4514 次
发布时间:2019-06-08

本文共 3134 字,大约阅读时间需要 10 分钟。

  1. 在系统目录文件找到includes/lib_goods.php  这个文件打开在此页最底部加入以下函数代码:

    /** * 首页获取指定分类产品 * * @access      public * @param       string      $cat_id53_best_goods * @param       array       $cat_id53_best_goods * @return      array */function get_cat_id_goods_list($cat_id = '', $num = '') {$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 ) ) ) ) ) . ")";$sql .= " 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;}

     

  2.  

    打开系统根目录下index.php文件加入如下代码,如果要在别的页面调用加到别的页面:

    $smarty->assign('cat_id_goods_list_86', get_cat_id_goods_list(86,9));   

    // 指定商品调用

    //其中86指的调用的栏目ID,9指的是调用商品的数量。

  3.  

    在首页模版中调用即可,如下:

    <!--{foreach from=$cat_id_goods_list_86 item=goods}-->

    <li>      <a href="{$goods.url}" target="_blank">        <img src="{$goods.thumb}" alt="{$goods.name|escape:html}" /></a>     <span class="a_title">        <a href="{$goods.url}" title="{$goods.name|escape:html}" target="_blank">            {$goods.short_style_name}</a>    </span>    <div style="text-indent: 5px;">市场价 <span class="del">{$goods.market_price}</span></div>    <div style="text-indent: 5px;"><span class="red">售 价 {$goods.shop_price}</span></div></li>

    <!--{/foreach}-->

转载于:https://www.cnblogs.com/phpall/p/4265568.html

你可能感兴趣的文章
Python---- 函数
查看>>
javascript中的函数作用域和声明提前
查看>>
Xcode10升级项目报错library not found for -lstdc++.6.0.9
查看>>
ZOJ-1129-Erdos Numbers
查看>>
java学习第四天 类和变量
查看>>
IDEA中如何添加RunDashboard
查看>>
单例静态继承
查看>>
Android开发:《Gradle Recipes for Android》阅读笔记(翻译)3.2——设置Flavors和Variants...
查看>>
Android零基础入门第36节:Android系统事件的响应
查看>>
POJ 2262 Goldbach's Conjecture
查看>>
自己手动写代码实现数据库连接池
查看>>
领域对象驱动开发:来吧,让我们从对象开始吧
查看>>
mysql分区分表讲解
查看>>
java编程思想读书笔记三(11-21)
查看>>
luogu P5302 [GXOI/GZOI2019]特技飞行
查看>>
EntityFramework 开始小试
查看>>
234 Palindrome Linked List
查看>>
Keil-MDK编译完成后代码大小
查看>>
ArcGIS JS 学习笔记4 实现地图联动
查看>>
ubuntu 12.04 lts安装golang并设置vim语法高亮
查看>>