fukap様のを参考に私も自分なり適当に作ってみた(゜o゜)
[お断り!!:コードはあくまでサンプルです。コードが判る人のみ参考にしてください]
----
1.新規ブロックを作成する。
→方法は省略。(仮:ProductNaviって名前で作ってます)
2.新規ブロックのPHPに以下を記述
require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
/**
* パンくず のページクラス.
*
*/
class LC_Page_FrontParts_Bloc_ProductNavi extends LC_Page_FrontParts_Bloc {
// }}}
// {{{ functions
/**
* Page を初期化する.
*
* @return void
*/
function init() {
parent::init();
}
/**
* Page のプロセス.
*
* @return void
*/
function process() {
$this->action();
$this->sendResponse();
}
/**
* Page のアクション.
*
* @return void
*/
function action() {
if ( !empty($_GET['category_id'])){
$this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET);
$arrTopic = $this->sfGetTopic($this->tpl_category_id[0]);
} elseif ( !empty($_GET['product_id'])) {
$this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET);
$arrTopic = $this->sfGetTopic2($this->tpl_category_id[0],$_GET['product_id']);
} elseif (($_GET['mode'] == 'search')){
$arrTopic[0]['url'] = ROOT_URLPATH;
$arrTopic[0]['name'] = "TopPage";
$arrTopic[1]['name'] = $_GET['name'] . " の検索結果";
}
$this->arrTopic = $arrTopic;
}
//商品一覧用
function sfGetTopic($category_id) {
$objDb = new SC_Helper_DB_Ex();
$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);
//トップページ
$arrTopic[0]['url'] = ROOT_URLPATH . 'index.php';
$arrTopic[0]['name'] = "TopPage";
$i = 1;
foreach($arrCatId as $key => $val){
$arrCatName = $objDb->sfGetCat($val);
if($val != $category_id){
//商品ページってDefineきってないのか?
$arrTopic[$i]['url'] = ROOT_URLPATH . 'products/list.php?category_id=' .$val;
$arrTopic[$i]['name'] = $arrCatName['name'];
} else {
$arrTopic[$i]['name'] = $arrCatName['name'];
}
$i++;
}
return $arrTopic;
}
//商品詳細用
function sfGetTopic2($category_id, $product_id) {
$objDb = new SC_Helper_DB_Ex();
$arrCatId = $objDb->sfGetParents("dtb_category", "parent_category_id", "category_id", $category_id);
//トップページ
$arrTopic[0]['url'] = ROOT_URLPATH . 'index.php';
$arrTopic[0]['name'] = "TopPage";
$i = 1;
foreach($arrCatId as $key => $val){
$arrCatName = $objDb->sfGetCat($val);
//商品ページってDefineきってないのか?
$arrTopic[$i]['url'] = ROOT_URLPATH . 'products/list.php?category_id=' . $val;
$arrTopic[$i]['name'] = $arrCatName['name'];
$i++;
}
//最後に商品IDから商品名を取得
$arrRes = $objDb->sfGetProductName($product_id);
$arrTopic[$i]['name'] = $arrRes['name'];
return $arrTopic;
}
/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}
//↓LC_Page_FrontParts_Bloc_Category.phpにあったやつ、まんまコピペしちゃいました。
/**
* 選択中のカテゴリIDを取得する.
*
* @param array $arrRequest リクエスト配列
* @return array $arrCategoryId 選択中のカテゴリID
*/
function lfGetSelectedCategoryId($arrRequest) {
// 商品ID取得
$product_id = '';
if ( isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id']) ) {
$product_id = $arrRequest['product_id'];
}
// カテゴリID取得
$category_id = '';
if ( isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id']) ) {
$category_id = $arrRequest['category_id'];
}
// 選択中のカテゴリIDを判定する
$objDb = new SC_Helper_DB_Ex();
$arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
if (empty($arrCategoryId)) {
$arrCategoryId = array(0);
}
return $arrCategoryId;
}
}
?>
3.SC_Helper_DB.phpに以下を追加
/**
* 指定した商品IDの商品名を取得する.
*
* @param integer $product_id 商品ID
* @return array 商品IDの商品名
*/
function sfGetProductName($product_id){
$objQuery =& SC_Query_Ex::getSingletonInstance();
// 商品名を取得する
$arrVal = array($product_id);
$res = $objQuery->select('name', 'dtb_products', 'product_id = ?', $arrVal);
return $res[0];
}
4.新規ブロックのtplに以下を記述
<!--{* ▼パンくずリスト *}-->
<!--{foreach from=$arrTopic item=Topic }-->
<!--{if $Topic.url != ''}-->
<a href = <!--{$Topic.url}-->><!--{$Topic.name|escape}--> </a> >
<!--{else}-->
<!--{$Topic.name|escape}-->
<!--{/if}-->
<!--{/foreach}-->
<!--{* ▲パンくずリスト *}-->
5.管理画面のページレイアウトの設定で適当に配置
----駄文---
なんとなくブロックでやってみただけです。