2016/06/29
ECCUBE2.13
備忘録です。
ECCUBE2.13でパンくずリストを表示する方法です。
参考サイト
EC-CUBE でパンくず
【1】デザイン管理でパンくずブロックを作成
<div class="topicPath">
<a href="<!--{$smarty.const.TOP_URL}-->">TOP</a>
<!--{if $arrTopicPath}-->
<!--{foreach from=$arrTopicPath item=topic}-->
>
<!--{if $topic.url}-->
<a href="<!--{$topic.url}-->"><!--{$topic.title|h}--></a>
<!--{else}-->
<!--{$topic.title|h}-->
<!--{/if}-->
<!--{/foreach}-->
<!--{elseif $tpl_title}-->
> <!--{$tpl_title|h}-->
<!--{/if}-->
</div>
【2】商品一覧画面のパンくず
data/class_extends/page_extends/products/LC_Page_Products_List_Ex.php
class LC_Page_Products_List_Ex extends LC_Page_Products_List
{
/**
* Page のアクション.
*
* @return void
*/
function action()
{
parent::action();
// パンくずリスト取得
$this->arrTopicPath = $this->lfTopicPath(
$this->mode
,$this->arrSearchData['category_id']
,$this->arrSearchData['name']
);
}
/**
* パンくずリスト取得
*
* @return array
*/
function lfTopicPath( $mode, $category_id, $category_name )
{
$arrRet = array();
if( $mode == 'search' ){
$arrRet[] = array('title' => $category_name . ' の検索結果');
}
elseif( empty($category_id) ){
$arrRet[] = array('title' => '全商品');
}
else{
$objDb = new SC_Helper_DB_Ex();
$arrCatId = $objDb->sfGetParentCategories( $category_id );
foreach( $arrCatId as $cat ){
if( $cat['id'] == $category_id ){
$arrRet[] = array('title' => $cat['name']);
}
else{
$arrRet[] = array(
'url' => './list.php?category_id=' . $cat['id']
,'title' => $cat['name']
);
}
}
}
return $arrRet;
}
}
【3】商品詳細画面のパンくず
data/class_extends/page_extends/products/LC_Page_Products_Detail_Ex.php
class LC_Page_Products_Detail_Ex extends LC_Page_Products_Detail
{
/**
* Page のアクション.
*
* @return void
*/
function action()
{
parent::action();
// パンくずリスト取得
$this->arrTopicPath = $this->lfTopicPath( $this->tpl_product_id );
}
/**
* パンくずリスト取得
*
* @return array
*/
function lfTopicPath( $product_id )
{
$arrRet = array();
$objDb = new SC_Helper_DB_Ex();
$arrCategory_id = $objDb->sfGetCategoryId( $product_id );
$category_id = $arrCategory_id[0];
$arrCatId = $objDb->sfGetParentCategories( $category_id );
foreach( $arrCatId as $cat ){
$arrRet[] = array(
'url' => './list.php?category_id=' . $cat['id']
,'title' => $cat['name']
);
}
$arrRet[] = array('title' => $this->tpl_subtitle);
return $arrRet;
}
}
【4】共通関数
data/class_extends/helper_extends/SC_Helper_DB_Ex.php
class SC_Helper_DB_Ex extends SC_Helper_DB
{
/**
* 指定カテゴリIDの親カテゴリID・名称リスト(自身含む)を取得する.
*
* @param integer $category_id カテゴリID
* @return array カテゴリID・名称の配列
*/
public function sfGetParentCategories( $category_id )
{
$arrRet = array();
// 商品が属するカテゴリIDを縦に取得
$objQuery =& SC_Query_Ex::getSingletonInstance();
$arrCatID = $this->sfGetParents(
'dtb_category'
,'parent_category_id'
,'category_id'
,$category_id
);
foreach( $arrCatID as $id ){
// カテゴリ名称を取得
$sql = 'SELECT category_name FROM dtb_category WHERE category_id = ?';
$catName = $objQuery->getOne( $sql, array($id) );
$arrRet[] = array(
'id' => $id
,'name' => $catName
);
}
return $arrRet;
}
}
【5】ブロックを設置して完了
いくつかパンくずの参考サイトはあるのですが、2.13で使えたのはこれだけでした。
恐らく、あとのサイトは2.11~2.12くらいまでのソースコードではないかと思います。
ゼヒトモ内でのプロフィール: ROCKSTREAM, ゼヒトモのホームページ作成・制作サービス, 仕事をお願いしたい依頼者と様々な「プロ」をつなぐサービス
2025/01/31
JQuery
2025/01/01
神社
御朱印
相模原
2024/10/27
ブラウザ
カスタム投稿
Wordpress
2024/08/20
神社
御朱印
2024/07/06
神社
御朱印