Blog

【ECCUBE】商品一覧に下層カテゴリを表示

2015/05/25

ECCUBE2.11~

各商品一覧に下層カテゴリのリンクを表示します。

参考サイト 
http://sachips.byeto.jp/eccube/eccube-products-list-sabcat.html

1.data/class/pages/products/LC_Page_Products_List.php

     /**
     * Page のAction.
     *
     * @return void
     */
    function action() {
    中略
    // サブカテゴリリストを取得
    $this->arrSubCatList = $this->lfGetCatTree($this->arrSearchData['category_id']);
    }

2.同じくdata/class/pages/products/LC_Page_Products_List.php
末尾に以下の関数を追加

/**
 * カテゴリツリーの取得
 *
 * @param array $parent_category_id 親カテゴリID
 * @param boolean $count_check 登録商品数をチェックする場合はtrue
 * @return array $arrRet カテゴリツリーの配列を返す
 */
function lfGetCatTree($parent_category_id, $count_check = false) {
        $objQuery =& SC_Query_Ex::getSingletonInstance();
        $objDb = new SC_Helper_DB_Ex();
        $col = '*';
        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
        // 登録商品数のチェック
        if ($count_check) {
                $where = 'del_flg = 0 AND product_count > 0 AND parent_category_id = ?';
        } else {
                $where = 'del_flg = 0 AND parent_category_id = ?';
        }
        $arrval = array($parent_category_id);
        $objQuery->setOption('ORDER BY rank DESC');
        return $objQuery->select($col, $from, $where, $arrval);
}

カテゴリツリーを取得する処理をローカル関数として追加。
DBから取得する段階で、親カテゴリID(parent_category_id)を渡します。

3.data/Smarty/templates/default/products/list.tpl
子カテゴリを表示したい場所に以下を記述

<!--{* ▼下位カテゴリ *}-->
<!--{if $arrSubCatList|@count > 0}-->
        <ul class="subcatlist_area">
        <!--{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>
<!--{/if}-->
<!--{* ▲下位カテゴリ *}-->

CSSで表示調整をして完了です。

カテゴリー

月間アーカイブ

MORE

ミュージシャンズ・プラザ

神社仏閣ホームーページ制作

ホームページ制作問合せ