ecshop 按照多属性的方式显示 按照多属性的格式搜索 php代码和演示
需求
1. ecshop 的分类 下面 有商品类型-》商品属性-》属性值
属性值 是手动输入的 也就是在ecs_goods_attr 这个表里面
2 网页打开速度要快,不能延迟太多,如果某个属性值下面的商品数量太少。不显示
3
====================================================================
解决
1
alter table ecs_category add attribute_line text null comment '属性列表'
2. 后台 建立一个文件 attribute_line_create.php 用户自动生成属性列表信息
3 .后台
category_info.htm 增加ajax调用
<div style="width:150px;float:left;">
<span style="cursor:pointer" οnclick="attribute_line_create('{$cat_info.cat_id}','{$filter_attr.filter_attr_id}')">生成全部属性列表</span>
</div>
function attribute_line_create(cat_id){
Ajax.call('attribute_line_create.php?action=sc&cat_id='+cat_id, '', conlistResponse, 'POST', 'JSON');
}
4 前台
category.dwt添加 对应的商品大于1个数量才显示
<!--属性列表-->
<div id="sxss">
<!--{foreach from=$attribute_line item=filter_attr}-->
<div class="screeBox">
<strong>{$filter_attr.filter_attr_name|escape:html} :</strong>
<!--{foreach from=$filter_attr.attr_list item=attr}-->
{if $attr.num>1}<a href="{$attr.url}">{$attr.attr_value} </a>| {/if}
<!--{/foreach}-->
</div>
<!--{/foreach}-->
category.php
在
$position = assign_ur_here($cat_id, $brand_name);附近 修改为
//属性列表
//属性列表 2015 - 7- 3 modified yanggg QQ346767073
$attribute_line = ( unserialize( $GLOBALS['db']->getOne("select attribute_line from ".$GLOBALS['ecs']->table('category')." where cat_id=".$cat_id)));;
assign_template('c', array($cat_id));
$position = assign_ur_here($cat_id, $brand_name);
$smarty->assign('attribute_line', $attribute_line); // 属性列表
附带 某分类下面的属性列表(不带商品数量)
if ($cat['filter_attr'] > 0)
{
//echo 'ffff';
$cat_filter_attr = explode(',', $cat['filter_attr']); //提取出此分类的筛选属性
//print_r($cat_filter_attr );
$all_attr_list = array();
foreach ($cat_filter_attr AS $key => $value)
{
$sql = "SELECT a.attr_name FROM " . $ecs->table('attribute') . " AS a, " . $ecs->table('goods_attr') . " AS ga, " . $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 = $db->getOne($sql))
{
$all_attr_list[$key]['filter_attr_name'] = $temp_name;
$sql = "SELECT a.attr_id, MIN(a.goods_attr_id ) AS goods_id, a.attr_value AS attr_value FROM " . $ecs->table('goods_attr') . " AS a, " . $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 = $db->getAll($sql);
$temp_arrt_url_arr = array();
for ($i = 0; $i < count($cat_filter_attr); $i++) //获取当前url中已选择属性的值,并保留在数组中
{
$temp_arrt_url_arr[$i] = !empty($filter_attr[$i]) ? $filter_attr[$i] : 0;
}
$temp_arrt_url_arr[$key] = 0; //“全部”的信息生成
$temp_arrt_url = implode('.', $temp_arrt_url_arr);
$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_arr[$key] = $v['goods_id']; //为url中代表当前筛选属性的位置变量赋值,并生成以‘.’分隔的筛选属性字符串
$temp_arrt_url = implode('.', $temp_arrt_url_arr);
$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;
}
}
}
}
print_r($all_attr_list);
exit();
$smarty->assign('filter_attr_list', $all_attr_list);
/* 扩展商品查询条件 */
if (!empty($filter_attr))
{
$ext_sql = "SELECT DISTINCT(b.goods_id) FROM " . $ecs->table('goods_attr') . " AS a, " . $ecs->table('goods_attr') . " AS b " . "WHERE ";
$ext_group_goods = array();
foreach ($filter_attr AS $k => $v) // 查出符合所有筛选属性条件的商品id */
{
if (is_numeric($v) && $v !=0 )
{
$sql = $ext_sql . "b.attr_value = a.attr_value AND b.attr_id = " . $cat_filter_attr[$k] ." AND a.goods_attr_id = " . $v;
$ext_group_goods = $db->getColCached($sql);
$ext .= ' AND ' . db_create_in($ext_group_goods, 'g.goods_id');
}
}
}
}
欢迎加入QQ 群 ecshop 二次开发 模板 348615323