EC-CUBE2.12:配送方法の指定で配送業者の送料の詳細を表示する

★配送業者が複数存在する場合は「お支払方法・お届け時間等の指定」に送料の詳細リンクが表示されるが、1つの場合は表示されない。「送料を見る」をクリックすると下図のように表示される。

▼ここでのカスタマイズファイルをすべてダウンロードできます。
必要な箇所だけコピーしてご利用ください。
他のカスタマイズも含まれている場合がありますので、ファイルの上書きは絶対におやめください。
こちらから(facebookユーザーのみ)

(1)ポップアップで表示するための新規ページを作成する。
■html/postage/index.php

<?php

// {{{ requires
require_once '../require.php';
require_once CLASS_EX_REALDIR . 'page_extends/postage/LC_Page_Postage_Ex.php';

// }}}
// {{{ generate page

$objPage = new LC_Page_Postage_Ex();
register_shutdown_function(array($objPage, "destroy"));
$objPage->init();
$objPage->process();
?>

■data/class_extends/page_extends/postage/LC_Page_Postage_Ex.php

<?php

// {{{ requires
require_once CLASS_REALDIR . 'pages/postage/LC_Page_Postage.php';

class LC_Page_Postage_Ex extends LC_Page_Postage {

// }}}
// {{{ functions

/**
* Page を初期化する.
*
* @return void
*/
function init() {
parent::init();
}

/**
* Page のプロセス.
*
* @return void
*/
function process() {
parent::process();
}

/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}
}
?>

■data/class/pages/postage/LC_Page_Postage.php

<?php

// {{{ requires
require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';

class LC_Page_Postage extends LC_Page_Ex {

// }}}
// {{{ functions

/**
* Page を初期化する.
*
* @return void
*/
function init() {
parent::init();
$this->tpl_page_category = 'postage';
$this->tpl_title = '配送業者の送料詳細';
}

/**
* Page のプロセス.
*
* @return void
*/
function process() {
parent::process();
$this->action();
$this->sendResponse();
}

/**
* Page のアクション.
*
* @return void
*/
function action() {
$this->setTemplate($this->tpl_mainpage = 'postage/postage.tpl');

$objQuery =SC_Query_Ex::getSingletonInstance();
$this->arrRet = array();
$this->arrRetPref1 = array();
$this->arrRetFee1 = array();
$this->arrRetPref2 = array();
$this->arrRetFee2 = array();
$this->arrRetPref3 = array();
$this->arrRetFee3 = array();

//
$devname = $_GET['devname'];

//配送業者を取得
$arrRet = $objQuery->select("*", "dtb_deliv", "deliv_id = $devname");

//データベースからデータの取得ができたか
if(isset($arrRet)){
$this->arrRet = $arrRet[0];
}

//県名を取得
$arrRetPref1 = $objQuery->select("*", "mtb_pref", "id between 1 and 14");
$arrRetPref2 = $objQuery->select("*", "mtb_pref", "id between 15 and 30");
$arrRetPref3 = $objQuery->select("*", "mtb_pref", "id between 31 and 47");

//データベースからデータの取得ができたか
if(isset($arrRet)){
$this->arrRetPref1 = $arrRetPref1;
}
if(isset($arrRet)){
$this->arrRetPref2 = $arrRetPref2;
}
if(isset($arrRet)){
$this->arrRetPref3 = $arrRetPref3;
}

//送料を取得
$arrRetFee1 = $objQuery->select("*", "dtb_delivfee", "deliv_id = $devname and pref between 1 and 14");
$arrRetFee2 = $objQuery->select("*", "dtb_delivfee", "deliv_id = $devname and pref between 15 and 30");
$arrRetFee3 = $objQuery->select("*", "dtb_delivfee", "deliv_id = $devname and pref between 31 and 47");

//データベースからデータの取得ができたか
if(isset($arrRet)){
$this->arrRetFee1 = $arrRetFee1;
}
if(isset($arrRet)){
$this->arrRetFee2 = $arrRetFee2;
}
if(isset($arrRet)){
$this->arrRetFee3 = $arrRetFee3;
}

}

/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}
}
?>

■data/Smarty/templates/default/postage/postage.tpl

<!--{include file="`$smarty.const.TEMPLATE_REALDIR`popup_header.tpl"}-->

<div id="pop_postage">
<div id="name">
<!--{if $arrRet}-->
<!--{$arrRet.name|h}-->の送料詳細
<!--{/if}-->
</div>

<table>
<tr>
<th colspan="2">北海道・東北・関東</th><th colspan="2">中部・近畿</th><th colspan="2">中国・四国・九州</th>
</tr>
<tr>
<td class="pref">
<!--{if $arrRetPref1}-->
<!--{section name=cnt loop=$arrRetPref1}-->
<!--{$arrRetPref1[cnt].name|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
<td class="fee">
<!--{if $arrRetFee1}-->
<!--{section name=cnt loop=$arrRetFee1}-->
<!--{$arrRetFee1[cnt].fee|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
<td class="pref">
<!--{if $arrRetPref2}-->
<!--{section name=cnt loop=$arrRetPref2}-->
<!--{$arrRetPref2[cnt].name|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
<td class="fee">
<!--{if $arrRetFee2}-->
<!--{section name=cnt loop=$arrRetFee2}-->
<!--{$arrRetFee2[cnt].fee|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
<td class="pref">
<!--{if $arrRetPref3}-->
<!--{section name=cnt loop=$arrRetPref3}-->
<!--{$arrRetPref3[cnt].name|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
<td class="fee">
<!--{if $arrRetFee3}-->
<!--{section name=cnt loop=$arrRetFee3}-->
<!--{$arrRetFee3[cnt].fee|h}--><br />
<!--{/section}-->
<!--{/if}-->
</td>
</tr>
</table>
</div>

<!--{include file="`$smarty.const.TEMPLATE_REALDIR`popup_footer.tpl"}-->

(2)配送業者の送料詳細を表示するかしないかを選択できるように、パラメータ設定に新たに項目を設ける。データベースに追加。
テーブル:mtb_constants

INSERT INTO mtb_constants (id, name, rank, remarks) VALUES ('POSTAGE_SHOW', 'true', 1417, '配送業者の送料の詳細 true/表示する false/表示しない');

★設定後、管理画面のパラメーター設定を開き「この内容で登録する」をクリックすると反映される。

(3)ColorBoxが適用されていて、送料詳細表示にColorBoxを利用する場合
$(“.cbox_postage”).colorbox({width:”600″, height:”500″, iframe:true}); ←site_frame.tplに追記
■data/Smarty/templates/default/site_frame.tpl

<!--ColorBox-->
<link media="screen" rel="stylesheet" href="<!--{$smarty.const.ROOT_URLPATH}-->js/jquery.colorbox/colorbox.css" />
<script type="text/javascript" src="<!--{$smarty.const.ROOT_URLPATH}-->js/jquery.colorbox/jquery.colorbox.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".cbox").colorbox();
$(".cbox_map").colorbox({width:"650", height:"500", iframe:true});
$(".cbox_postage").colorbox({width:"600", height:"500", iframe:true});
});
</script>

★ColorBoxを利用しない場合
(3)は記述しない。
(4)の (4)「お支払方法・お届け時間等の指定」ページのコードを変更
■data/Smarty/templates/default/shopping/payment.tpl

▼変更前

<td>
<label for="deliv_<!--{$smarty.section.cnt.iteration}-->"><!--{$arrDeliv[cnt].name|h}--><!--{if $arrDeliv[cnt].remark != ""}--><p><!--{$arrDeliv[cnt].remark|h|nl2br}--></p><!--{/if}--></label>
</td>

▼変更後

<td>
<label for="deliv_<!--{$smarty.section.cnt.iteration}-->"><!--{$arrDeliv[cnt].name|h}-->
<!--{if $smarty.const.POSTAGE_SHOW == "true"}-->
<a class="cbox_postage" href="<!--{$smarty.const.ROOT_URLPATH}-->postage/index.php?devname=<!--{$arrDeliv[cnt].deliv_id|h}-->" title="<!--{$arrDeliv[cnt].name|h}-->の送料詳細">(送料を見る)</a>
<!--{/if}-->
<!--{if $arrDeliv[cnt].remark != ""}-->
<p><!--{$arrDeliv[cnt].remark|h|nl2br}--></p>
<!--{/if}--></label>
</td>

(5)CSSに追加する
■html/user_data/packages/default/css/popup.css

/* 配送業者の送料詳細
----------------------------------------------- */
div#pop_postage #name {
border-left:#CCC 10px solid;
padding-left:5px;
font-size:120%;
}

div#pop_postage table {
width:100%;
}

div#pop_postage th{
text-align:center;
}

div#pop_postage td{
text-align:right;
vertical-align:top;
}

div#pop_postage td.pref{
border-right:none;
}

div#pop_postage td.fee{
width:10%;
padding-right:30px;
}