在index.php中添加
$smarty->assign('filter_attr_list', filter_attr_list(2,'')); //2为大分类ID
function filter_attr_list($cat_id,$filter_attr='')
{
$cat = get_cat_info($cat_id);
$cat_id=$cat[cat_id];
$children = get_children($cat_id);
// $cat['filter_attr']=$filter_attr; ouyangyong
$cat_filter_attr = explode(',', $cat['filter_attr']); //提取出此分类的筛选属性
$all_attr_list = array();
foreach ($cat_filter_attr AS $key => $value)
{ $sql = "SELECT a.attr_name,a.attr_id FROM " . $GLOBALS['ecs']->table('attribute') . " AS a, " .
$GLOBALS['ecs']->table('goods_attr') . " AS ga, " .
$GLOBALS['ecs']->table('goods') . " AS g WHERE ($children OR " . get_extension_goods($children) . ") AND a.attr_id = ga.attr_id AND g.goods_id = ga.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND a.attr_id='$value'";
if($temp_name = $GLOBALS['db']->getRow($sql))
{
$all_attr_list[$key]['filter_attr_name'] = $temp_name['attr_name'];
$all_attr_list[$key]['filter_attr_id'] = $temp_name['attr_id'];
$sql = "SELECT a.attr_id, MIN(a.goods_attr_id ) AS goods_id, a.attr_value AS attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " AS a, " . $GLOBALS['ecs']->table('goods') .
" AS g" .
" WHERE ($children OR " . get_extension_goods($children) . ') AND g.goods_id = a.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 '.
" AND a.attr_id='$value' ".
" GROUP BY a.attr_value";
$attr_list = $GLOBALS['db']->getAll($sql);
$temp_arrt_url_arrcc = array();
for ($i = 0; $i < count($cat_filter_attr); $i++) //获取当前url中已选择属性的值,并保留在数组中
{
$temp_arrt_url_arrc[$i] = 0;
}
$temp_arrt_url_arrc[$key] = 0; //“全部”的信息生成
$temp_arrt_url = implode('.', $temp_arrt_url_arrc);
$all_attr_list[$key]['attr_list'][0]['attr_value'] = '全部'; //$_LANG['all_attribute'];
$all_attr_list[$key]['attr_list'][0]['url'] = build_uri('category', array('cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>$price_min, 'price_max'=>$price_max, 'filter_attr'=>$temp_arrt_url), $cat['cat_name']);
$all_attr_list[$key]['attr_list'][0]['selected'] = empty($filter_attr[$key]) ? 1 : 0;
foreach ($attr_list as $k => $v)
{
$temp_key = $k + 1;
$temp_arrt_url_arrc[$key] = $v['goods_id']; //为url中代表当前筛选属性的位置变量赋值,并生成以‘.’分隔的筛选属性字符串
$temp_arrt_url = implode('.', $temp_arrt_url_arrc);
$all_attr_list[$key]['attr_list'][$temp_key]['attr_value'] = $v['attr_value'];
$all_attr_list[$key]['attr_list'][$temp_key]['url'] = build_uri('category', array('cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>$price_min, 'price_max'=>$price_max, 'filter_attr'=>$temp_arrt_url), $cat['cat_name']);
if (!empty($filter_attr[$key]) AND $filter_attr[$key] == $v['goods_id'])
{
$all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 1;
}
else
{
$all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 0;
}
}
}
}
return $all_attr_list;
}
在index.dwt相应的位置添加。
<!--组合搜索 开始-->
<!--{if $brands.1 || $price_grade.1 || $filter_attr_list}-->
<div><img src="images/artt_top1.gif"></div>
<div class="indexscreeBox">
<ul>
<!--{foreach from=$filter_attr_list item=filter_attr}-->
<li> <strong>{$filter_attr.filter_attr_name|escape:html}:</strong>
<!--{foreach from=$filter_attr.attr_list item=attr}-->
<!-- {if $attr.selected} -->
<span>{$attr.attr_value}</span>
<!-- {else} -->
<a href="{$attr.url}">{$attr.attr_value}</a>
<!-- {/if} -->
<!--{/foreach}-->
<div class="clear"></div>
</li>
<!--{/foreach}-->
</ul>
</div>
<div><img src="images/artt_bottom1.gif"></div>
<div class="blank5"></div>
<!-- {/if} -->
<!--组合搜索 结束-->
效果。
其实可以在白酒分类下新建一个香型的分类,编辑商品 选择一下扩展分类为香型即可
二次开发怎么弄,我想用 category.php 里面的该,但是没有弄出来,能说说吗?