商品列表页

  • 控制器:b2c_ctl_site_gallery
  • 方法:index
  • 使用到的主要模型层类:
    1. b2c_mdl_goods_virtual_cat
    2. b2c_mdl_search
    3. b2c_mdl_goods_cat
    4. b2c_mdl_goods
    5. b2c_mdl_goods_type
    6. b2c_mdl_goods_type_spec
    7. b2c_mdl_specification
  • 使用到的主要service:
    1. b2c_site_goods_list_viewer_apps 商品分类列表展示信息
    2. propselect.prop_search
    3. tags_special.add 列表页标签显示,show tag on goods image
  • 展示所有商品的各种模式,有列表基本模式(含图),大图(橱窗模式)和文字模式(不含图片)
  • 提供排序方式、价格、销量和人气等分类筛选功能。
  • 提供分类、品牌等筛选框(根据搜索条件得出)
  • 流程图


筛选条件区域

  • 筛选条件分为两部分一部分为品牌,类型筛选;另一部分就是展示类型和排序筛选(属性)
    1. 商品属性筛选区域
      • 商品分类、类型筛选
      • 商品品牌筛选
      • 商品虚拟分类筛选
    2. 商品排序区域
      • 提供排序方式、价格、销量和人气等分类筛选功能
      • 筛选功能可以自定义,可以提供扩展(劫持页面)

显示风格

  • 图文混排
  • 橱窗形式
  • 文字列表

商品搜索

  • 根据搜索条件得到相应的商品数据,显示商品列表,列表格式显示
  • 搜索可以包含很多内容,都是通过联想模糊搜索的方式去的,也可以通过分词搜素等,如scws和sphinx

业务代码分析

  • 前台控制器类b2c_ctl_site_gallery::index()方法参数
    /**
     *
     * @param int $cat_id 商品分类ID
     * @param string $urlFilter 品牌,规格等过滤参数
     * @param int $orderBy 排序array(
           1=>array('label'=>app::get('b2c')->_('默认')),
           2=>array('label'=>app::get('b2c')->_('按发布时间 新->旧'),'sql'=>'last_modify desc'),
           3=>array('label'=>app::get('b2c')->_('按发布时间 旧->新'),'sql'=>'last_modify'),
           4=> array('label'=>app::get('b2c')->_('按价格 从高到低'),'sql'=>'price desc'),
           5=>array('label'=>app::get('b2c')->_('按价格 从低到高'),'sql'=>'price'),
           6=>array('label'=>app::get('b2c')->_('访问周次数'),'sql'=>'view_w_count desc'),
           7=> array('label'=>app::get('b2c')->_('总访问次数'),'sql'=>'view_count desc'),
           8=>array('label'=>app::get('b2c')->_('周购买次数'),'sql'=>'buy_count desc'),
           9=> array('label'=>app::get('b2c')->_('总购买次数'),'sql'=>'buy_w_count desc'),
           10=> array('label'=>app::get('b2c')->_('评论次数'),'sql'=>'comments_count desc'),
        );
     * @param unknown_type $tab 参数分隔符
     * @param int $page 页数
     * @param int $cat_type 虚拟分类时使用,虚拟分类id,与分类$cat_id互斥的
     * @param string $view 商品列表页展示方式,index,text,grid三种显示方式
     */
    public function index($cat_id='',$urlFilter=null,$orderBy=0,$tab=null,$page=1,$cat_type=null,$view=null) {}
    
    注:http://localhost/ecos/index.php/gallery-12-b,2_1,59-1--1--grid.html?scontent=b,2_1,59_)
    
  • 前台控制器类b2c_ctl_site_gallery::index()方法来处理
    1.$urlFilter=htmlspecialchars(urldecode($urlFilter));
            $_GET['scontent'] = htmlspecialchars($_GET['scontent']);
            if(!empty($urlFilter) && $urlFilter != $_GET['scontent']){
                $urlFilter .= '_'.$_GET['scontent'];
            }else{
                $urlFilter = $_GET['scontent'];
            }
            if( $cat_type ){
                $vcatid = $cat_type;
                $oVcat = $this->app->model('goods_virtual_cat');
                $oSearch = &$this->app->model('search');
                $vcat = $oVcat->getList('cat_id,cat_path,virtual_cat_id,filter,virtual_cat_name as cat_name',array('virtual_cat_id'=>intval($vcatid)));
                $vcat = current( $vcat );
                $vcatFilters=$oVcat->_mkFilter($vcat['filter']);
                $vcatFilters=$oVcat->getFilter($vcatFilters);
                $old_cat_id = $cat_id;
                $old_urlFilter = $urlFilter;
                $cat_id = $cat_id?$cat_id.implode(",",$vcatFilters['cat_id']):implode(",",$vcatFilters['cat_id']);
                $urlFilter = $urlFilter?$urlFilter:$oSearch->encode($vcatFilters);
            }
    
     过滤生成参数,将参数加入filter
     2.品牌参数的筛选
     $propargs = $searchtools->decode($urlFilter,$path,$cat);
            if(is_array($propargs)){
                foreach($propargs as $rk=>$rv){
                    $pos = strpos($rk,'p_');
                    if($pos === 0){
                        $propz[$rk] = $rv[0];
                        $rk =substr($rk,2);
                        $proparg[$rk] = $rv;
                        $prot[] = $rk;
                    }
                }
            }
            if(isset($propargs['name'])){
                $GLOBALS['runtime']['search_key'] = $propargs['name'][0];
            }
           $this->pagedata['prot'] = $prot;
           $filter = $propargs;
           if(is_array($filter)){
                $filter=array_merge(array('cat_id'=>$cat_id,'marketable'=>'true'),$filter);
                if( ($filter['cat_id'][0] === '' || $filter['cat_id'][0] === null ) && !isset( $filter['cat_id'][1] ) )
                    unset($filter['cat_id']);
                if( ($filter['brand_id'][0] ==='' || $filter['brand_id'][0] === null) && !isset( $filter['brand_id'][1] ))
                    unset($filter['brand_id']);
            }else{
                $filter = array('cat_id'=>$cat_id,'marketable'=>'true');
            }
     3.获取类型关联的规格
     $type_id = $type_filter['type_id'];
            $gType = &$this->app->model('goods_type');
            $SpecList = $gType->getSpec($type_id,1);//获取关联的规格
            $oGoodsTypeSpec = $this->app->model('goods_type_spec');
            $type_spec = $oGoodsTypeSpec->get_type_spec($type_id);
            $oSpecification = &$this->app->model('specification');
            $filter['cat_id'] = $cat_id;
            $filter['goods_type'] = 'normal';
            $filter['marketable'] = 'true';
            //-----查找当前类别子类别的关联类型ID
            if ($urlFilter){
                if($vcat['type_id']){
                    //$filter['type_id']=$vcat['type_id'];
                    $filter['type_id']=null;
                }
            }
     4.商品搜索-品牌,分类(虚拟分类),标签等搜索的筛选
     if ($SpecList){
                if ($curSpec)
                    $curSpecKey=array_keys($curSpec);
                foreach($SpecList as $spk => $spv){
                    $selected=0;
                    if ($curSpecKey&&in_array($spk,$curSpecKey)){
                        $spv['spec_value'][$curSpec[$spk]]['selected']=true;
                        $selected=1;
                    }
                    if ($spv['spec_style']=="select"){ //下拉
                        $SpecSelList[$spk] = $spv;
                        if ($selected)
                            $SpecSelList[$spk]['selected'] = true;
                    }
                    elseif ($spv['spec_style']=="flat"){
                        $SpecFlatList[$spk] = $spv;
                        if ($selected)
                            $SpecFlatList[$spk]['selected'] = true;
                    }
                }
            }
            $this->pagedata['SpecFlatList'] = $SpecFlatList;
            $this->pagedata['specimagewidth'] = $this->app->getConf('spec.image.width');
            $this->pagedata['specimageheight'] = $this->app->getConf('spec.image.height');
            $this->pagedata['orderBy'] = $objGoods->orderBy();//排序方式
            if(empty($orderBy)) $orderBy = 1;
            if(!isset($this->pagedata['orderBy'][$orderBy])){
                $this->_response->set_http_response_code(404);
            }else{
                $orderby = $this->pagedata['orderBy'][$orderBy]['sql'];
            }
            $selector['ordernum'] = $cat['ordernum'];
            if(app::get('base')->getConf('server.search_server.search_goods')){
               $searchApp = search_core::instance('search_goods');
               $sfilter['filter'] = $filter;
               $sfilter['from'] = $pageLimit*($page-1);     //分页
               $sfilter['to'] = $pageLimit;
               $sfilter['order'] = $orderby;
               $sfilter['scount'] = count($cat['props']);
            }
            $res = false;   //初始化
            if(is_object($searchApp)){
               $sphinxstart = true;
               $queryRes = $searchApp->query($sfilter);
               if($queryRes){
                   $res = $searchApp->commit();
                   $nprop = $res['prop'];           //属性搜索
                   $cbrand = $res['brand'];
                   $rfilter['goods_id'] = $res['result'];
                   if(is_array($res['result'])){
                       $count = $res['total'];
                       $search_data = $objGoods->getList('*', $rfilter);
                       foreach($search_data AS $tmp_data){
                           $tmp_search_data[$tmp_data['goods_id']] = $tmp_data;
                       }
                       foreach($res['result'] as $v){
                           if(!isset($tmp_search_data[$v])) continue;
                           $aProduct[] = $tmp_search_data[$v];  //产品
                       }
                       unset($search_data);
                       unset($tmp_search_data);
                   }else{
                       $count = 0;
                       $aProduct = array();
                   }
               }
            }
            if($res === false){
                if (isset($filter['tag'][0])&&!$filter['tag'][0]) unset($filter['tag']);
                $aProduct = $objGoods->getList('*',$filter,$pageLimit*($page-1),$pageLimit,$orderby);
                $count = $objGoods->count($filter);
            }
     5.展示页面
     $this->page('site/gallery/index.html');
    

內容目录

上一个主题

商品详情页流程图

下一个主题

ECStore工具集

快速搜索

输入相关的模块,术语,类或者函数名称进行搜索