通过清心醉

Ecshop二次开发-增加自定义属性的搜索

首先把作者修改好了的贡献出来,需要的朋友请自行下载(放心没写后门)

Ecshop搜索强化-增加自定义属性搜索

ECSHOP前台可按商品名称关键词、商品货号关键词等查找商品,但不能按特点货号查找。特点货号是ECSHOP特点库存的仅有识别号,树立特点库存后,特点货号保存在products表中,下面分析怎么开发按特点货号关键词查找。
search.php

$keywords .= “(goods_name LIKE ‘%$val%’ OR goods_sn LIKE ‘%$val%’ OR keywords LIKE ‘%$val%’ $sc_dsad)”;
修改为
$keywords .= “(goods_name LIKE ‘%$val%’ OR goods_sn LIKE ‘%$val%’ OR product_sn LIKE ‘%$val%’ OR keywords LIKE ‘%$val%’ $sc_dsad)”;

ECSHOP默认使用的是goods_name\goods_sn\keywords。其实要想搜索出来的产品条件更多,可以goods_brief产品描述等,不过这样会影响速度,不建议。上面修改的SQL语句中增加了product_sn特点货号关键字的搜索

 

$sql = “SELECT COUNT(*) FROM ” .$ecs->table(‘goods’). ” AS g “.
“WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in “.
“AND (( 1 ” . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock .” ) “.$tag_where.” )”;
修改为:
$sql = “SELECT COUNT(*) FROM ” .$ecs->table(‘goods’). ” AS g “.
“LEFT JOIN ” . $GLOBALS[‘ecs’]->table(‘products’) . ” AS p “.
“ON g.goods_id = p.goods_id “.
“WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in “.
“AND (( 1 ” . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock .” ) “.$tag_where.” )”;

// 取得契合条件的商品总数,SQL语句增加goods表与products表衔接查询。

接下来就是查询产品了,同样要增加goods表与products表链接查询。

$sql = “SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, “.
“NULL.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, “.
“g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type “.
“FROM ” .$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_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in “.
“AND (( 1 ” . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . ” ) “.$tag_where.” ) ” .
“ORDER BY $sort $order”;
修改为:
/* 查询商品 */
$sql = “SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, “.
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, “.
“g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type “.
“FROM ” .$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]’ “.
“LEFT JOIN ” . $GLOBALS[‘ecs’]->table(‘products’) . ” AS p “.
“ON g.goods_id = p.goods_id “.
“WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in “.
“AND (( 1 ” . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . ” ) “.$tag_where.” ) ” .
“ORDER BY $sort $order”;

到此搜索自定义属性的产品开发完毕。

 

关于作者

清心醉 administrator

发表评论

请输入验证码: