EC-CUBEの小技:カテゴリ検索結果ページに下の階層のカテゴリを表示
この記事は最終更新日から1年以上が経過しています。
list.phpにちょっと書き足し
/data/class/pages/products/LC_Page_Products_List.phpに以下を追加
104行目辺りから書き替え //表示条件の取得 /* $this->arrSearchData = array( 'category_id' => $this->lfGetCategoryId(intval($this->arrForm['category_id'])), 'maker_id' => intval($this->arrForm['maker_id']), 'name' => $this->arrForm['name'] ); */ if(is_array($_GET['category_id'])){ $arrCategory_id = array(); if(preg_match("/^[0-9]+$/" , $_GET['category_id'][0])) array_push($arrCategory_id, $_GET['category_id'][0]); if(preg_match("/^[0-9]+$/" , $_GET['category_id'][1])) array_push($arrCategory_id, $_GET['category_id'][1]); if(preg_match("/^[0-9]+$/" , $_GET['category_id'][2])) array_push($arrCategory_id, $_GET['category_id'][2]); $this->arrSearchData = array( 'category_id' => $arrCategory_id ); }else{ $this->arrSearchData = array( 'category_id' => $this->lfGetCategoryId(intval($this->arrForm['category_id'])), 'maker_id' => intval($this->arrForm['maker_id']), 'name' => $this->arrForm['name'] ); } $this->orderby = $this->arrForm['orderby']; // サブカテゴリリストを取得 $this->arrSubCatList = $this->getSubCatList($this->arrSearchData['category_id']); 最後尾に追加 /* * 子カテゴリ一覧を取得 * * @param int $category_id 該当カテゴリID * @return Array $arrSubCatList 子カテゴリID */ function getSubCatList($category_id){ $arrRet = SC_Helper_DB_Ex::sfGetCatTree(); $cnt = 0; foreach($arrRet as $key => $val){ if($val['parent_category_id'] == $category_id){ $arrSubCatList[$cnt]['category_id'] = $val['category_id']; $arrSubCatList[$cnt]['category_name'] = $val['category_name']; $cnt++; } } return $arrSubCatList; }
tplに表示するコードを書いて完了
/data/Smarty/templates/sphone/products/list.tplに以下を追加
<!--{if $arrSubCatList|@count > 0}--> <section class="under_category"> <div class="title_box_sub clearfix"> <h2>下層カテゴリ一覧</h2> <span class="b_expand"><img src="<!--{$TPL_URLPATH}-->img/common/btn_minus.png" onclick="fnSubToggle($('#sub_areaxx'), this);" alt=""></span> </div> <div id="sub_areaxx" class="toggle_block"> <ul> <!--{foreach from=$arrSubCatList item=category}--> <li> <a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$category.category_id|h}-->"><!--{$category.category_name|h}--></a> </li> <!--{/foreach}--> </ul> </div> </section> <!--{/if}-->