ecshop2.7.0首页如何调用积分商城的商品

2009-08-19 18:23 来源:www.chinab4c.com 作者:ecshop专家

     在ECSHOP电子商务系统中,往往需要将积分商城的产品调用到首页。也很简单。写一个ecshop函数exchange_get_goods()来负责调用积分商城的产品。通过模板来显示。

function exchange_get_goods($children, $size, $page)
{
    $display = $GLOBALS['display'];
    $where = "eg.is_exchange = 1 AND g.is_delete = 0 AND ".
             "($children OR " . get_extension_goods($children) . ')';

 

    /* 获得商品列表 */
    $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, ' .$GLOBALS['ecs']->table('goods') . ' AS g ' .
            "WHERE eg.goods_id = g.goods_id AND $where  ORDER BY g.goods_id desc";
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);

    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        /* 处理商品水印图片 */
        $watermark_img = '';

//        if ($row['is_new'] != 0)
//        {
//            $watermark_img = "watermark_new_small";
//        }
//        elseif ($row['is_best'] != 0)
//        {
//            $watermark_img = "watermark_best_small";
//        }
//        else
        if ($row['is_hot'] != 0)
        {
            $watermark_img = 'watermark_hot_small';
        }

        if ($watermark_img != '')
        {
            $arr[$row['goods_id']]['watermark_img'] =  $watermark_img;
        }

        $arr[$row['goods_id']]['goods_id']          = $row['goods_id'];
        if($display == 'grid')
        {
            $arr[$row['goods_id']]['goods_name']    = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        }
        else
        {
            $arr[$row['goods_id']]['goods_name']    = $row['goods_name'];
        }
        $arr[$row['goods_id']]['name']              = $row['goods_name'];
        $arr[$row['goods_id']]['goods_brief']       = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_style_name']  = add_style($row['goods_name'],$row['goods_name_style']);
        $arr[$row['goods_id']]['exchange_integral'] = $row['exchange_integral'];
        $arr[$row['goods_id']]['type']              = $row['goods_type'];
        $arr[$row['goods_id']]['goods_thumb']       = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img']         = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url']               = build_uri('exchange_goods', array('gid'=>$row['goods_id']), $row['goods_name']);
    }

    return $arr;
}

$children = get_children($cat_id);
exchange_get_goods($children,10,1);
$smarty -> assign('ext',exchange_get_goods($children,10,1));

    以下是模板

     <div class="goodsList">
      <!--{foreach name=goods_list from=$goods_list item=goods}-->
      <ul class="clearfix bgcolor"<!--{if $smarty.foreach.goods_list.index mod 2 eq 0}-->id=""<!--{else}-->id="bgcolor"<!--{/if}-->>
      <li class="thumb"><a href="{$goods.url}"><img src="{$goods.goods_thumb}" alt="{$goods.goods_name}" /></a></li>
      <li class="exchangeGoodName">
      <a href="{$goods.url}">
        <!-- {if $goods.goods_style_name} -->
        <font class="f3">{$goods.goods_style_name}</font><br />
        <!-- {else} -->
        <font class="f3">{$goods.goods_name}</font><br />
        <!-- {/if} -->
      </a>
       <!-- {if $goods.goods_brief} -->
      {$lang.goods_brief}{$goods.goods_brief}<br />
      <!-- {/if} -->
      </li>
      <li>
      {$lang.exchange_integral}<font class="price">{$goods.exchange_integral}</font>
      </li>
      </ul>
      <!--{/foreach}-->
        </div>

     通过调整PHP和模板。完成了ecshop调用积分商城的信息。

    来源:中国B4C电子商务