EC-CUBEでパンくずリンクの追加

EC-CUBEでは、商品一覧ページや、商品詳細ページで、パンくずリンクが表示されないため、
カスタマイズすることで、表示する事が可能になります。

※2010年2月27日修正しました。

/data/class_extends/helper_extends/SC_Helper_DB_Ex.php を編集。

class SC_Helper_DB_Ex extends SC_Helper_DB 内に以下を追加。

    function sfGetTopicPath($category_id){
        // 商品が属するカテゴリIDを縦に取得
        $objQuery = new SC_Query();
        $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
        $TopicPath = " > ";

        // カテゴリー名称を取得する
        foreach($arrCatID as $key => $val){
            $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
            $arrVal = array($val);
            $CatName = $objQuery->getOne($sql,$arrVal);
            if( $val != $category_id){
              $TopicPath .= '<a href="./list.php?category_id=' .$val . '">' . $CatName . '</a> > ';
            }else{
              $TopicPath .= $CatName;
            }
        }

        return $TopicPath;
    }
    function sfGetTopicPath2($category_id){
        // 商品が属するカテゴリIDを縦に取得
        $objQuery = new SC_Query();
        $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
        $TopicPath = " > ";

        // カテゴリー名称を取得する
        foreach($arrCatID as $key => $val){
            $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
            $arrVal = array($val);
            $CatName = $objQuery->getOne($sql,$arrVal);
              $TopicPath .= '<a href="./list.php?category_id=' .$val . '">' . $CatName . '</a> > ';
            }
        return $TopicPath;
    }

商品一覧ページ用の修正。
/data/class/pages/products/LC_Page_Products_List.php のfunction process()の中身を
/data/class/pages/products/LC_Page_Products_List_EX.phpに上書き。

/data/class/pages/products/LC_Page_Products_List_EX.php を編集。

   $count = $objQuery->count("dtb_best_products", "category_id = ?", $arrCategory_id);
   //以下にパンくず用コードを追加。
   $TopicPath = $objDb->sfGetTopicPath($arrCategory_id[0]);
       $this->tpl_topicpath = $TopicPath;

/data/class/pages/products/LC_Page_Products_Detail.php のfunction process()の中身を
/data/class/pages/products/LC_Page_Products_Detail_EX.phpに上書き。

/data/class/pages/products/LC_Page_Products_Detail_EX.php を編集。
商品詳細ページ用修正。

        // 関連カテゴリを取得
        $this->arrRelativeCat = $objDb->sfGetMultiCatTree($tmp_id);

        //パンくずリンク
        $arrTopicPath = $objDb->sfGetTopicPath2($arrCategory_id[0]);
        $this->tpl_topicpath = $arrTopicPath;

パンくず用コードをテンプレートに挿入。
Smarty/templates/default/site_main.tpl

  <!--{* ▼CENTER COLUMN *}-->
  <!--{if $tpl_column_num == 3}-->
  <div id="three_maincolumn">
  <!--{elseif $tpl_column_num == 2}-->
  <div id="two_maincolumn">
  <!--{elseif $tpl_column_num == 1}-->
  <div id="one_maincolumn">
  <!--{/if}-->

//パンくずリンク用コードを追加
  <!--{if $tpl_topicpath != ""}-->
  <div id="pankuzu"><a href="<!--{$smarty.const.SITE_URL}-->index.php">トップページ</a><!--{$tpl_topicpath}--><!--{$arrProduct.name|escape}--></div>
  <!--{/if}-->
  
This entry was posted in EC-CUBE, ブログ記事 and tagged . Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.