A-A+

ecshop如何在首页显示指定商品

2015年12月04日 PHP开源系统 暂无评论 阅读 10 views 次

ecshop 首页默认的是有精品、新品、热卖这几个版块,当然也可以在后台进行这几个版块显示的商品,但是现在有这样一个问题,如果我不想要首页显示这些商品呢,我只想更人性化一些,人为的显示一些固定的商品,而且在后台又可以进行控制某些商品是否是特推的商品,这样的功能也很容易实现,只是 ecshop 二次开发的小技巧而已,下面夏日博客就来把方法分享一下。

1:首先我们给ecshop商品表增加一个字段is_index

  1. alter table ecs_goods add column is_index int(1) default 0;  

2:在商品列表中增加以下内容admin/templates/goods_list.htm

  1. <th><a href="javascript:listTable.sort('is_index'); ">首页推荐</th>  
  2.  <td align="center"><img src="images/{if $goods.is_index}yes{else}no{/if}.gif" onclick="listTable.toggle(this, 'toggle_is_index', {$goods.goods_id})" /></td>  

3:admin/goods.php中增加以下内容。

  1. elseif ($_REQUEST['act'] == 'toggle_is_index')  
  2. {  
  3.     check_authz_json('goods_manage');  
  4.     $goods_id       = intval($_POST['id']);  
  5.     $is_index        = intval($_POST['val']);  
  6.     if ($exc->edit("is_index = '$is_index', last_update=" .gmtime(), $goods_id))  
  7.     {  
  8.         clear_cache_files();  
  9.         make_json_result($is_index);  
  10.     }  
  11. }  

4:前台通过以下函数来调用数据

  1. function assign_is_index_goods( $num = 16)  
  2. {  
  3.      
  4.     $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .  
  5.                 "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".  
  6.                'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' .  
  7.             "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '.  
  8.             "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".  
  9.                     "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".  
  10.             'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND '.  
  11.                 'g.is_delete = 0 AND is_index =1  ';  
  12.     $order_rule = emptyempty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule;  
  13.     $sql .= $order_rule;  
  14.     if ($num > 0)  
  15.     {  
  16.         $sql .= ' LIMIT ' . $num;  
  17.     }  
  18.     $res = $GLOBALS['db']->getAll($sql);  
  19.     $goods = array();  
  20.     foreach ($res AS $idx => $row)  
  21.     {  
  22.         if ($row['promote_price'] > 0)  
  23.         {  
  24.             $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);  
  25.             $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';  
  26.         }  
  27.         else  
  28.         {  
  29.             $goods[$idx]['promote_price'] = '';  
  30.         }  
  31.         $goods[$idx]['id']           = $row['goods_id'];  
  32.         $goods[$idx]['name']         = $row['goods_name'];  
  33.         $goods[$idx]['brief']        = $row['goods_brief'];  
  34.         $goods[$idx]['market_price'] = price_format($row['market_price']);  
  35.         $goods[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?  
  36.                                         sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];  
  37.         $goods[$idx]['shop_price']   = price_format($row['shop_price']);  
  38.         $goods[$idx]['thumb']        = get_image_path($row['goods_id'], $row['goods_thumb'], true);  
  39.         $goods[$idx]['goods_img']    = get_image_path($row['goods_id'], $row['goods_img']);  
  40.         $goods[$idx]['url']          = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);  
  41.     }  
  42.     return $goods;  
  43. }  

以上就完成了ecshop 首页显示指定的商品

标签:

给我留言