ecshop控制某些商品显示首页
2011-08-31 23:09 来源:www.chinab4c.com 作者:ecshop专家
ecshop后台虽然在产品列表里面可以设置商品属于精品,新品,热卖几个类型。但是很多时候,我们在首页不但要展示这些商品,我们还可能需要人为的展现某些特被推荐的产品。而且很灵活的在ecshop商品列表的后台控制和选择某些商品是否属于特推商品。这样我们必须在ecshop商品数据库里面增加一字段is_index来控制。
1: 首先我们给ecshop商品表增加一个字段is_index
alter table ecs_goods add column is_index int(1) default 0;
2:在商品列表中增加以下内容admin/templates/goods_list.htm
<th><a href="javascript:listTable.sort('is_index'); ">首页推荐</th>
<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中增加以下内容。
elseif ($_REQUEST['act'] == 'toggle_is_index')
{
check_authz_json('goods_manage');
$goods_id = intval($_POST['id']);
$is_index = intval($_POST['val']);
if ($exc->edit("is_index = '$is_index', last_update=" .gmtime(), $goods_id))
{
clear_cache_files();
make_json_result($is_index);
}
}
4:前台通过以下函数来调用数据
function assign_is_index_goods( $num = 16)
{
$sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' .
"FROM " . $GLOBALS['ecs']->table('goods') . ' AS g '.
"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 AND is_index =1 ';
$order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule;
$sql .= $order_rule;
if ($num > 0)
{
$sql .= ' LIMIT ' . $num;
}
$res = $GLOBALS['db']->getAll($sql);
$goods = array();
foreach ($res AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$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]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
}
return $goods;
}
以上就完成了ecshop控制某些商品显示首页
最近更新
常用插件
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...