tpl複製
ランキング追加
パンくず設置
静的化
tpl複製
トップページのおすすめ商品を2列→4列にレイアウトを変更
EC-CUBEバージョン 2.4.4
PHPバージョン PHP 5.2.15
DBバージョン MySQL 5.0.91

管理画面→デザイン管理→ブロック編集→オススメ商品から

28行目付近

変更前↓↓

<!--{section name=cnt loop=$arrBestProducts step=2-->

変更後↓↓

<!--{section name=cnt loop=$arrBestProducts step=4}-->

※step=2をstep=4に変更

------------------------------------------------------------------------
------------------------------------------------------------------------

2つ目の商品ブロック「<div class="recomendright"> ・・・ </div>

の部分をコピーし、<div class="recomendright">の部分を<div class="recomendleft">に変更。

変更前↓↓

<!--{assign var=cnt2 value=`$smarty.section.cnt.iteration*$smarty.section.cnt.step-1` }-->

変更後↓↓

<!--{assign var=cnt2 value=`$smarty.section.cnt.iteration*$smarty.section.cnt.step-2` }-->

※step-1をstep-2に変更

------------------------------------------------------------------------

変更前↓↓


<!--{assign var=price01 value=`$arrBestProducts[$cnt].price01_min`}-->

<!--{assign var=price02 value=`$arrBestProducts[$cnt].price02_min`}-->


変更後↓↓

<!--{assign var=price01 value=`$arrBestProducts[$cnt2].price01_min`}-->

<!--{assign var=price02 value=`$arrBestProducts[$cnt2].price02_min`}-->


------------------------------------------------------------------------
------------------------------------------------------------------------

上記で追加した商品ブロック(recomendleft)をコピーし、3つ目の商品ブロックを追加

変更後↓↓

<!--{assign var=cnt3 value=`$smarty.section.cnt.iteration*$smarty.section.cnt.step-3` }-->

------------------------------------------------------------------------

変更後↓↓

<!--{assign var=price01 value=`$arrBestProducts[$cnt3].price01_min`}-->
<!--{assign var=price02 value=`$arrBestProducts[$cnt3].price02_min`}-->

------------------------------------------------------------------------
------------------------------------------------------------------------

最後(4つ目)の商品ブロック(recomendright)

変更後↓↓

<!--{assign var=cnt4 value=`$smarty.section.cnt.iteration*$smarty.section.cnt.step-1` }-->


------------------------------------------------------------------------

変更後↓↓

<!--{assign var=price01 value=`$arrBestProducts[$cnt4].price01_min`}-->
<!--{assign var=price02 value=`$arrBestProducts[$cnt4].price02_min`}-->



ビックリマークまとめビックリマーク

2つ目のブロック→ cnt2 step-2
3つ目のブロック→ cnt3 step-3
4つ目のブロック→ cnt4 step-1

※上記で変更している以外の箇所も、「cnt」「step」の数字はブロックごとにすべて同じに書き換える。
①/html/.htaccess ファイルに以下を追加。

↓↓

RewriteEngine on
RewriteRule detail\/([0-9]+)\/? /eccube/html/products/detail.php?product_id=$1 [L]

↑↑

赤字部分は適宜変更

[/html/products/detail/3]等の静的URLでアクセスできるようになったことを確認。


②管理画面→システム設定→パラメータ設定

「DETAIL_P_HTML」の項目を以下に様に変更

↓↓変更前

URL_DIR . "products/detail.php?product_id="


↓↓変更後

URL_DIR . "products/detail/"



URLの静的化によって、商品詳細ページの「画像を拡大する」「コメントを書き込む」
ボタンがリンク切れになってしまうので、下記を修正。


管理画面→デザイン管理→ページ詳細編集→商品詳細ページ


①72行目付近
----------------------------------------------------------------------------
■変更前↓↓

<!--★画像★-->
<a href="javascript:void(win01('./detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=main_large_image<!--{if $smarty.get.admin == 'on'}-->

----------------------------------------------------------------------------
■変更後↓↓

<!--★画像★-->
<a href="javascript:void(win01('<!--{$smarty.const.URL_DIR}-->products/detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=main_large_image<!--{if $smarty.get.admin == 'on'}-->

----------------------------------------------------------------------------


②76行目付近
----------------------------------------------------------------------------
■変更前↓↓

<!--★拡大する★-->
<p><a href="javascript:void(win01('./detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=main_large_image<!--{if $smarty.get.admin == 'on'}-->&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile.main_large_image.width+60}-->', '<!--{$arrFile.main_large_image.height+80}-->'))" onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion_on.gif','expansion01');" onMouseOut="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion.gif','expansion01');">
<img src="<!--{$TPL_DIR}-->img/products/b_expansion.gif" width="85" height="13" alt="画像を拡大する" name="expansion01" id="expansion01" />
</a>

----------------------------------------------------------------------------
■変更後↓↓

<!--★拡大する★-->
<a href="javascript:void(win01('<!--{$smarty.const.URL_DIR}-->products/detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=main_large_image<!--{if $smarty.get.admin == 'on'}-->
&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile.main_large_image.width+60}-->', '<!--{$arrFile.main_large_image.height+80}-->'))" onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion_on.gif','expansion01');" onMouseOut="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion.gif','expansion01');">
<img src="<!--{$TPL_DIR}-->img/products/b_expansion.gif" width="85" height="13" alt="画像を拡大する" name="expansion01" id="expansion01" />
</a>


----------------------------------------------------------------------------


③100行目付近

----------------------------------------------------------------------------
■変更前↓↓

<a href="<!--{$smarty.server.PHP_SELF|escape}-->" onClick="win01('./detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=<!--{$lkey}--><!--{if $smarty.get.admin == 'on'}-->&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile[$lkey].width+60}-->','<!--{$arrFile[$lkey].height+80}-->'); return false;" target="_blank">
<!--{else}-->
<a>
<!--{/if}-->
<!--サブ画像-->
<img src="<!--{$arrFile[$key].filepath}-->" alt="<!--{$arrProduct.name|escape}-->" width="<!--{$smarty.const.NORMAL_SUBIMAGE_WIDTH}-->" height="<!--{$smarty.const.NORMAL_SUBIMAGE_HIGHT}-->" /></a>
<!--{if $arrFile[$lkey].filepath != ""}-->
<p>
<a href="<!--{$smarty.server.PHP_SELF|escape}-->"
onclick="win01('./detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=<!--{$lkey}--><!--{if $smarty.get.admin == 'on'}-->&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile[$lkey].width+60}-->','<!--{$arrFile[$lkey].height+80}-->'); return false;"
onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion_on.gif','expansion02');"
onmouseout="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion.gif','expansion02');" target="_blank">
<img src="<!--{$TPL_DIR}-->img/products/b_expansion.gif" width="85" height="13" alt="画像を拡大する" />
</p></a>

----------------------------------------------------------------------------
■変更後↓↓

<a href="<!--{$smarty.server.PHP_SELF|escape}-->" onClick="win01('<!--{$smarty.const.URL_DIR}-->products/detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=<!--{$lkey}--><!--{if $smarty.get.admin == 'on'}-->&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile[$lkey].width+60}-->','<!--{$arrFile[$lkey].height+80}-->'); return false;" target="_blank">
<!--{else}-->
<a>
<!--{/if}-->
<!--サブ画像-->
<img src="<!--{$arrFile[$key].filepath}-->" alt="<!--{$arrProduct.name|escape}-->" width="<!--{$smarty.const.NORMAL_SUBIMAGE_WIDTH}-->" height="<!--{$smarty.const.NORMAL_SUBIMAGE_HIGHT}-->" /></a>
<!--{if $arrFile[$lkey].filepath != ""}-->
<p>
<a href="<!--{$smarty.server.PHP_SELF|escape}-->"
onclick="win01('<!--{$smarty.const.URL_DIR}-->products/detail_image.php?product_id=<!--{$arrProduct.product_id}-->&amp;image=<!--{$lkey}--><!--{if $smarty.get.admin == 'on'}-->&amp;admin=on<!--{/if}-->','detail_image','<!--{$arrFile[$lkey].width+60}-->','<!--{$arrFile[$lkey].height+80}-->'); return false;"
onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion_on.gif','expansion02');"
onmouseout="chgImg('<!--{$TPL_DIR}-->img/products/b_expansion.gif','expansion02');" target="_blank">
<img src="<!--{$TPL_DIR}-->img/products/b_expansion.gif" width="85" height="13" alt="画像を拡大する" />
</p></a>

----------------------------------------------------------------------------


④300行目付近
----------------------------------------------------------------------------
■変更前↓↓

<!--{if count($arrReview) < $smarty.const.REVIEW_REGIST_MAX}-->
<!--★新規コメントを書き込む★-->
<a href="./review.php"
onclick="win02('./review.php?product_id=<!--{$arrProduct.product_id}-->','review','580','580'); return false;"
onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_comment_on.gif','review');"
onmouseout="chgImg('<!--{$TPL_DIR}-->img/products/b_comment.gif','review');" target="_blank">
<img src="<!--{$TPL_DIR}-->img/products/b_comment.gif" width="150" height="22" alt="新規コメントを書き込む" name="review" id="review" /></a>
<!--{/if}-->


----------------------------------------------------------------------------
■変更後↓↓

<!--{if count($arrReview) < $smarty.const.REVIEW_REGIST_MAX}-->
<!--★新規コメントを書き込む★-->
<a href="<!--{$smarty.const.URL_DIR}-->products/review.php"
onclick="win02('<!--{$smarty.const.URL_DIR}-->products/review.php?product_id=<!--{$arrProduct.product_id}-->','review','580','580'); return false;"
onmouseover="chgImg('<!--{$TPL_DIR}-->img/products/b_comment_on.gif','review');"
onmouseout="chgImg('<!--{$TPL_DIR}-->img/products/b_comment.gif','review');" target="_blank">
<img src="<!--{$TPL_DIR}-->img/products/b_comment.gif" width="150" height="22" alt="新規コメントを書き込む" name="review" id="review" /></a>
<!--{/if}-->


----------------------------------------------------------------------------

http://wiki.ec-orange2.jp/index.php?%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA%EF%BC%9A%E5%BF%9C%E7%94%A8%2F%E5%8B%95%E7%9A%84%E3%83%9A%E3%83%BC%E3%82%B8%E3%81%AE%E9%9D%99%E7%9A%84%E5%8C%96
EC-CUBEバージョン 2.4.4
PHPバージョン PHP 5.2.15
DBバージョン MySQL 5.0.91


SEO対策+ユーザビリティの為、パンくずリストは設置したいので、以下の方法で。

①以下のプログラムを「insert.pan.php」という名前で作成し、「data/module/Smarty/libs/plugins/」に保存→アップロード








<?php
function smarty_insert_pan($param, &$smarty) {
require_once("../require.php");
$pan = array();
$count = 0;
// パンくず情報となるデータを取得
$objQuery = new SC_Query();
switch($param) {
case (SC_Utils::sfIsInt($param['product_id'])): // product_idが入ってきた場合
$sql = "
SELECT
dtb_category.category_id,
category_name,
dtb_category.parent_category_id
FROM
dtb_category
WHERE
category_id = (SELECT MIN(category_id)
FROM
dtb_product_categories
WHERE
product_id = ?
)
";
$res = $objQuery->conn->getAll($sql, array($param['product_id']), DB_FETCHMODE_ASSOC);

if (is_array($res)) {
$pan[$count]['category_id'] = $res[0]['category_id'];
$pan[$count]['category_name'] = $res[0]['category_name'];
if (ereg("[0-9]+$", $res[0]['parent_category_id']) and ($res[0]['parent_category_id'] > 0)) { // 上位にカテゴリーがある場合
do {
$sql = "SELECT category_id, category_name, parent_category_id FROM dtb_category WHERE category_id =?";
$res = $objQuery->conn->getAll($sql, array($res[0]['parent_category_id']), DB_FETCHMODE_ASSOC);
if (is_array($res)) {
$count++;
$pan[$count]['category_id'] = $res[0]['category_id'];
$pan[$count]['category_name'] = $res[0]['category_name'];
}
} while ($res[0]['parent_category_id'] != "0");
}
}
break;
case (SC_Utils::sfIsInt($param['category_id'])): // カテゴリーIDが入ってきた場合
$res[0]['parent_category_id'] = $param['category_id'];
do {
$sql = "
SELECT
category_id,
category_name,
parent_category_id
FROM
dtb_category
WHERE
category_id =?
";
$res = $objQuery->conn->getAll($sql, array($res[0]['parent_category_id']), DB_FETCHMODE_ASSOC);
if (is_array($res)) {
$count++;
$pan[$count]['category_id'] = $res[0]['category_id'];
$pan[$count]['category_name'] = $res[0]['category_name'];
}
} while ($res[0]['parent_category_id'] != "0");
break;
}
// 取得した配列を逆ソート(上位カテゴリー順)に並び替える
if (count($pan) > 0) {
krsort($pan);
}

// 取得したデータをSmartyに渡す
$smarty->caching=0;


$smarty->assign("pan",$pan);
$pan = $smarty->fetch("pan.tpl"); // Smartyテンプレートで生成されたデータを一旦配列に入れる
print($pan);
}
?>



②以下の内容で「pan.tpl」という名前で「data/Smarty/templates/default」へアップロード
デフォルト以外のテンプレートを使用している場合は「default」の部分を適宜変更。







<!--{if $pan}-->
<!--{strip}-->
<a href="<!--{$smarty.const.URL_DIR}-->"></a>&nbsp;&nbsp;
<!--{foreach from=$pan item=item name=loops}-->
<!--{if !$smarty.foreach.loops.last}-->
<a href="<!--{$smarty.const.URL_DIR}-->products/list.php?category_id=<!--{$item.category_id}-->"><!--{$item.category_name}--></a>
&nbsp;>&nbsp;
<!--{elseif $smarty.foreach.loops.last && $arrProduct.name}-->
<a href="<!--{$smarty.const.URL_DIR}-->products/list.php?category_id=<!--{$item.category_id}-->"><!--{$item.category_name}--></a>
<!--{elseif $smarty.foreach.loops.last && !$arrProduct.name}-->
<strong><!--{$item.category_name}--></strong>
<!--{/if}-->
<!--{/foreach}-->
<!--{if $arrProduct.name}-->
&nbsp;>&nbsp;<strong><!--{$arrProduct.name|escape}--></strong>
<!--{/if}-->
<!--{/strip}-->
<!--{/if}-->



③管理画面 → デザイン管理 → ページ詳細編集 → 「商品一覧ページ」


<input type="hidden" name="product_id" value="" />
↓↓追加
<!--パンくずリスト追加-->
<!--{insert name="pan" category_id=$smarty.get.category_id}-->
↑↑追加
<div id="listtitle"><h2><!--★タイトル★--><!--{$tpl_subtitle}--></h2></div>



④管理画面 → デザイン管理 → ページ詳細編集 → 「商品詳細ページ」

<!--▼CONTENTS-->
<div id="undercolumn">
↓↓追加
<!--パンくずリスト追加-->
<!--{insert name="pan" product_id=$tpl_product_id}-->
↑↑追加
<div id="detailtitle"><h2><!--★タイトル★--><!--{$tpl_subtitle|escape}--></h2></div>