ECSHOP搜索添加按“品牌名”、“父分类名”搜索范围,可根据这些搜索出符合条件商品

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



再发一实用的功能,很多人用的到

老杨ecshop官网技术原帖:http://www.lyecs.com/article/w-42.html

添加搜索,按品牌搜索,按分类名搜索:

打开search.php

找到:
  1. $keywords.= "(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)";
复制代码

替换为:

  1. $keywords.= "(goods_name LIKE '%$val%' OR cat_name LIKE '%$val%' OR brand_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR g.keywords LIKE '%$val%' $sc_dsad)";//老杨ecshop www.lyecs.com
复制代码


找到:

  1. /* 获得符合条件的商品总数 */
  2. $sql= "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ".
  3. "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  4. "AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock ." ) ".$tag_where." )";
  5. $count = $db->getOne($sql);
复制代码

替换为:

  1. /* 获得符合条件的商品总数 */
  2. $sql= "SELECT COUNT(*) FROM " .$ecs->table('goods'). " AS g ".
  3. "LEFT JOIN " . $GLOBALS['ecs']->table('brand') . " AS b ON b.brand_id =g.brand_id ".//老杨ecshop www.lyecs.com
  4. "LEFT JOIN " . $GLOBALS['ecs']->table('category') . " AS c ON c.cat_id = g.cat_id".//老杨ecshop www.lyecs.com
  5. "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  6. "AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock ." ) ".$tag_where." )";
  7. $count = $db->getOne($sql);
复制代码


找到:
  1. /* 查询商品 */
  2. $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, ".
  3. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  4. "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type ".
  5. "FROM " .$ecs->table('goods'). " AS g ".
  6. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  7. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  8. "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  9. "AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
  10. "ORDER BY $sort $order";
  11. $res = $db->SelectLimit($sql, $size, ($page - 1) * $size);
复制代码


替换为:
  1. /* 查询商品 */
  2. $sql = "SELECT g.goods_id, g.goods_name, g.market_price,b.start_time,b.end_time,g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ".
  3. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  4. "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type ".
  5. "FROM " .$ecs->table('goods'). " AS g ".
  6. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  7. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  8. 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id' .
  9. "LEFT JOIN " . $GLOBALS['ecs']->table('category') . " AS c ON c.cat_id = g.cat_id ". //老杨ecshop www.lyecs.com
  10. "WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in ".
  11. "AND (( 1 " . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . " ) ".$tag_where." ) " .
  12. "ORDER BY $sort $order";
  13. $res = $db->SelectLimit($sql, $size, ($page - 1) * $size);
复制代码


没有做过开发的,可以直接下载示例文件覆盖(3.7.3 utf-8)如果编码不对请自行修改

回答:
老杨大大的分享,不能不顶哇。。。。。。。。。。

顶。。。。。。。。。。。。。。。。。