EC-CUBE2.12:「のし」の付加が選択でき、メールや納品書に表示する。

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


(1)
データベースを拡張する。

「dtb_products」に「のし」の選択可・不可を保持するためのカラム「noshi」を追加する。

ALTER TABLE dtb_products ADD noshi smallint NOT NULL DEFAULT 2

「dtb_order」に購入時に選択された「のし」情報を保持するためのカラム「gift_paper」を追加する。

ALTER TABLE dtb_order ADD gift_paper smallint

「dtb_order_temp」(受注情報一時保存)に購入時に選択された「のし」情報を保持するためのカラム「gift_paper」を追加する。

ALTER TABLE dtb_order_temp ADD gift_paper smallint


マスターテーブルを2つ追加
■1つめのテーブル(mtb_noshi)を作成する
【MySQL・PostgreSQL】

CREATE TABLE mtb_noshi (
id smallint,
name text,
rank smallint NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);

■2つめのテーブル(mtb_gift_paper)を作成する
【MySQL・PostgreSQL】

CREATE TABLE mtb_gift_paper (
id smallint,
name text,
rank smallint NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);

 ④で作成したテーブルに値を登録する。「システム設定>マスターデータ管理」で開くことになる。
■mtb_noshi

INSERT INTO mtb_noshi (id, name, rank) VALUES (1, '可', 0);
INSERT INTO mtb_noshi (id, name, rank) VALUES (2, '不可', 1)

■mtb_gift_paper

INSERT INTO mtb_gift_paper (id, name, rank) VALUES (0, '希望しない', 0);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (1, '無地のし(紅白)', 1);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (2, '内祝(蝶むすび)', 2);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (3, '内祝(むすび切り)', 3);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (4, '内祝(婚礼)', 4);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (5, '快気祝', 5);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (6, '粗供養', 6);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (7, '志(蓮のし)', 7);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (8, '無地のし(仏)', 8);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (9, '御礼', 9);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (10, '御挨拶', 10);
INSERT INTO mtb_gift_paper (id, name, rank) VALUES (11, 'その他', 11)

管理者が商品を登録する際、のしの選択「可」「不可」の初期値をパラメータ設定で行う。
mtb_constantsにカラムを追加する。

INSERT INTO mtb_constants (id, name, rank, remarks) VALUES ('DEFAULT_PRODUCT_NOSHI', '2', 1418, 'のしデフォルト選択値(1:可 2:不可)');

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

(2)カートセッションの管理

■data/class/SC_CartSession.php
390行目あたり 「すべてのカートの内容を取得する. function getAllCartList()」の次に。

//■のし
/**
* カート内の商品IDを取得する
*
* @param $cartKey カートキー名
* @return array カート内の商品IDの配列
*/
function getCartProductID($cartKey) {
// カートキーの最大要素番号を取得する
$max = $this->getMax($cartKey);
// 全てのカートに含まれている商品IDを取得する
for($i = 0; $i <= $max; $i++) {
if($this->cartSession[$cartKey][$i]['cart_no'] != "") {
$arrRet[] = $this->cartSession[$cartKey][$i]['productsClass']['product_id'];
}
}
return $arrRet;
}

(3)DB関連で共通の処理を追加

■data/class/helper/SC_Helper_DB.php
class SC_Helper_DB{}内に挿入(最下部)

//「のし」
/**
* 指定されたIDの商品にのし選択可能商品が
* 存在するかで「のし選択」項目の表示有無を決定する.
*
* @param array $arrProductid 商品IDの配列
* @return bool true:のし選択可能商品がある false:のし選択可能商品が無し
*/
function sfJudgeShowGiftPaper($arrProductid) {

// 商品IDが一件もない場合、falseで終了
if(strlen($arrProductid[0] < 1)) return false;

// カート内にのし選択可能商品が存在する判断する為のSQL用WHERE句を作成する
$where = "noshi = 1 AND product_id IN(";
$first = true;
foreach($arrProductid as $val) {
if(!$first) {
$where .= ",";
} else {
$first = false;
}
$where .= "?";
$sqlval[] = $val;
}
$where .= ")";

// カート内ののし選択可能商品の件数を取得する
$objQuery =& SC_Query_Ex::getSingletonInstance();
$cnt = $objQuery->count("dtb_products", $where, $sqlval);

return $cnt > 0;
}

(4)管理画面→商品管理に「のし」項目を追加
■data/class/page/admin/products/LC_Page_Admin_Products_Product.php
5カ所追加

function init() {
・
・
・
$this->arrAllowedTag = $masterData->getMasterData('mtb_allowed_tag');
$this->arrNOSHI = $masterData->getMasterData('mtb_noshi'); //■のし①/⑤
function lfInitFormParam(&$objFormParam, $arrPost) {
・
・
・
$objFormParam->addParam('公開・非公開', 'status', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('のし', 'noshi', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); //■のし②/⑤
function lfSetViewParam_InputPage(&$objUpFile, &$objDownFile, &$arrForm) {
・
・
・
if ($arrForm['product_type_id'] == '') {
$arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
}

// ▼のし③/⑤
if($arrForm['noshi'] == '') {
$arrForm['noshi'] = DEFAULT_PRODUCT_NOSHI;
}
// ▲のし

// アップロードファイル情報取得(Hidden用)
$arrHidden = $objUpFile->getHiddenFileList();
$arrForm['arrHidden'] = array_merge((array)$arrHidden, (array)$objDownFile->getHiddenFileList());
function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList) {

・
・
// 配列の添字を定義
・
・

'sale_limit', 'deliv_date_id', 'maker_id', 'note', 'noshi'); // ■のし④/⑤
・
・
・
$sqlval['creator_id'] = $_SESSION['member_id'];
$sqlval['noshi'] = $arrList['noshi']; // ■のし⑤/⑤
$arrRet = $objUpFile->getDBFileList();
$sqlval = array_merge($sqlval, $arrRet);

■data/Smarty/templates/admin/products/product.tpl

<tr>
<th>公開・非公開<span class="attention"> *</span></th>
<td>
<!--{html_radios name="status" options=$arrDISP selected=$arrForm.status separator='&nbsp;&nbsp;'}-->
</td>
</tr>
<tr>
<th>のし選択<span class="attention"> *</span></th>
<td>
<span class="attention"><!--{$arrErr.noshi}--></span>
<input type="radio" name="noshi" value="1"<!--{if $arrForm.noshi eq '1'}--> checked="checked"<!--{/if}-->/>可 <input type="radio" name="noshi" value="2"<!--{if $arrForm.noshi eq '2'}--> checked="checked"<!--{/if}--> />不可
</td>
</tr>

■data/Smarty/templates/admin/products/confirm.tpl

<tr>
<th>公開・非公開</th>
<td>
<!--{$arrDISP[$arrForm.status]}-->
</td>
</tr>
<tr>
<th>のし選択</th>
<td>
<!--{$arrNOSHI[$arrForm.noshi]}-->
</td>
</tr>

(5)管理画面→受注管理に「のしの種類」情報を追加
■data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
3カ所追加

$this->arrORDERSTATUS = $masterData->getMasterData('mtb_order_status');
$this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
$this->arrGIFTPAPER = $masterData->getMasterData('mtb_gift_paper'); //■のし①/③
// 新規受注登録で入力エラーがあった場合の画面表示用に、会員の現在ポイントを取得
if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) {
$customer_id = $objFormParam->getValue('customer_id');
$arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id);
$objFormParam->setValue('customer_point', $arrCustomer['point']);

// 新規受注登録で、ポイント利用できるように現在ポイントを設定
$objFormParam->setValue('point', $arrCustomer['point']);
}

// ▼のし②/③
parent::action();
// 「のしの選択」項目表示フラグ設定
$objDb = new SC_Helper_DB_Ex();
$this->gift_paper_flg = $objDb->sfJudgeShowGiftPaper($this->arrForm['product_id']['value']);
// ▲のし
$objFormParam->addParam('FAX番号2', 'order_fax02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK'));
$objFormParam->addParam('FAX番号3', 'order_fax03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK'));
$objFormParam->addParam('のしの選択', 'gift_paper', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); //■のし③/③

■data/Smarty/templates/admin/order/edit.tpl

<!--{if $arrForm.payment_info|@count > 0}-->
<tr>
<th><!--{$arrForm.payment_type}-->情報</th>
<td>
<!--{foreach key=key item=item from=$arrForm.payment_info}-->
<!--{if $key != "title"}--><!--{if $item.name != ""}--><!--{$item.name}-->:<!--{/if}--><!--{$item.value}--><br/><!--{/if}-->
<!--{/foreach}-->
</td>
</tr>
<!--{/if}-->

<tr>
<th>のしの選択</th>
<td>
<!--{assign var=key value="gift_paper"}-->

<select name="<!--{$key}-->" style="<!--{$arrErr[$key]|sfGetErrorColor}-->">
<!--{html_options options=$arrGIFTPAPER selected=$arrForm[$key].value}-->
</select>

</td>
</tr>

(6)「MYページ/購入履歴詳細」に「のしの種類」情報を追加
■data/class/pages/mypage/LC_Page_Mypage_History.php
1カ所

function init() {
parent::init();
$this->tpl_mypageno     = 'index';
$this->tpl_subtitle     = '購入履歴詳細';
・
・
・
$this->arrWDAY          = $masterData->getMasterData('mtb_wday');
$this->arrProductType   = $masterData->getMasterData('mtb_product_type');
$this->arrGIFTPAPER = $masterData->getMasterData("mtb_gift_paper"); //■のし①
}

■data/Smarty/templates/default/mypage/history.tpl

<span class="st">お支払い方法:&nbsp;</span><!--{$arrPayment[$tpl_arrOrderData.payment_id]|h}-->
<!--{if $tpl_arrOrderData.gift_paper != ""}--><br />
<span class="st">のしの種類:&nbsp;</span><!--{$arrGIFTPAPER[$tpl_arrOrderData.gift_paper]|h}-->
<!--{/if}-->

■data/Smarty/templates/mobile/mypage/history.tpl

<!--{if $tpl_arrOrderData.deliv_date != ""}--><br>
お届け日:<!--{$tpl_arrOrderData.deliv_date|h}-->
<!--{/if}-->
<!--{if $tpl_arrOrderData.gift_paper != ""}--><br />
のしの種類:<!--{$arrGIFTPAPER[$tpl_arrOrderData.gift_paper]|h}-->
<!--{/if}-->

■data/Smarty/templates/sphone/mypage/history.tpl

<pre><!--{if $tpl_arrOrderData.deliv_date != ""}-->
<br />
<em>お届け日</em>:&nbsp;</strong><!--{$tpl_arrOrderData.deliv_date|h}-->
<!--{/if}-->
<!--{if $tpl_arrOrderData.gift_paper != ""}-->
<br />
<em>のしの種類</em>:&nbsp;</strong><!--{$arrGIFTPAPER[$tpl_arrOrderData.gift_paper]|h}-->
<!--{/if}-->

(7)「商品購入/お支払い方法・お届け時間等の指定」に「のしの種類」情報を追加
■data/class/pages/shopping/LC_Page_Shopping_Payment.php
4カ所

function init() {
・
・
・
$this->arrPref = $masterData->getMasterData('mtb_pref');
$this->arrGIFTPAPER = $masterData->getMasterData('mtb_gift_paper'); //■のし①/④
function action() {
$objDb = new SC_Helper_DB_Ex();// ■のし②/④
$objSiteSess = new SC_SiteSession_Ex();
$objCartSess = new SC_CartSession_Ex();
・
・
・
// 配送業者を取得
$this->arrDeliv = $objPurchase->getDeliv($cart_key);
$this->is_single_deliv = $this->isSingleDeliv($this->arrDeliv);

// ■のし③/④
$this->gift_paper_flg = $objDb->sfJudgeShowGiftPaper($objCartSess->getCartProductID($this->cartKey));
function lfInitParam(&$objFormParam, $deliv_only, &$arrShipping) {
$objFormParam->addParam('配送業者', 'deliv_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
$objFormParam->addParam('ポイント', 'use_point', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK', 'ZERO_START'));
$objFormParam->addParam('その他お問い合わせ', 'message', LTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$objFormParam->addParam('ポイントを使用する', 'point_check', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '2');
$objFormParam->addParam('のしの種類', 'gift_paper', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); //■のし④/④

■data/Smarty/templates/default/shopping/payment.tpl
←次に

・
・
・
</div>
<!--{/if}-->
<!-- ▲ポイント使用 ここまで -->

<!--{if $gift_paper_flg}-->
<div class="pay_area02">
<h3>のしの選択</h3>
<p>ご希望の方は、のしの種類を選択してください。<br />選択肢の中にご希望のものがございませんでしたら、<br />「その他」をお選びいただき、その他お問い合わせ欄にお書き添えくださいませ。</p>
<div>
<!--★のしの選択★-->
<!--{assign var=key value="gift_paper"}-->
<span class="attention"><!--{$arrErr[$key]}--></span>
のしの種類:
<select name="<!--{$key}-->" style="<!--{$arrErr[$key]|sfGetErrorColor}-->">
<!--{html_options options=$arrGIFTPAPER selected=$arrForm[$key].value}-->
</select>
</div>
</div>
<!--{/if}-->

■data/Smarty/templates/mobile/shopping/payment.tpl
■その他お問い合わせ
←前に

<!--{if $gift_paper_flg}-->
<!--★のしの選択★-->
<!--{assign var=key value="gift_paper"}-->
<!--{if $arrErr[$key] != ""}-->
<font color="#FF0000"><!--{$arrErr[$key]}--></font>
<!--{/if}-->
のしの種類:<br>
<select name="<!--{$key}-->">
<!--{html_options options=$arrGIFTPAPER selected=$arrForm[$key].value}-->
</select>
<br>
<!--{/if}-->

■その他お問い合わせ<br>
<!--{assign var=key value="message"}-->
・
・
・

■data/Smarty/templates/sphone/shopping/payment.tpl
←前に

<!--{if $gift_paper_flg}-->
<section class="pay_area02">
<h3 class="subtitle">のしの選択</h3>
<div class="form_area">
<p>ご希望の方は、のしの種類を選択してください。<br />選択肢の中にご希望のものがございませんでしたら、<br />「その他」をお選びいただき、その他お問い合わせ欄にお書き添えくださいませ。</p>
<!--★のしの選択★-->
<!--{assign var=key value="gift_paper"}-->
<span class="attention"><!--{$arrErr[$key]}--></span>
のしの種類:
<select name="<!--{$key}-->" style="<!--{$arrErr[$key]|sfGetErrorColor}-->" class="boxLong data-role-none">
<!--{html_options options=$arrGIFTPAPER selected=$arrForm[$key].value}-->
</select>
</div>
</section>
<!--{/if}-->

<!--★ポイント使用の指定★-->
<!--{if $tpl_login == 1 && $smarty.const.USE_POINT !== false}-->

・
・
・

(8)「商品購入/ご入力内容のご確認」に「のしの種類」情報を追加
■data/class/pages/shopping/LC_Page_Shopping_Confirm.php

function init() {
parent::init();
$this->tpl_title = 'ご入力内容のご確認';
$masterData = new SC_DB_MasterData_Ex();
$this->arrPref = $masterData->getMasterData('mtb_pref');
$this->arrSex = $masterData->getMasterData('mtb_sex');
$this->arrMAILMAGATYPE = $masterData->getMasterData('mtb_mail_magazine_type');
$this->arrReminder = $masterData->getMasterData('mtb_reminder');
$this->arrDeliv = SC_Helper_DB_Ex::sfGetIDValueList('dtb_deliv', 'deliv_id', 'service_name');
$this->arrGIFTPAPER = $masterData->getMasterData('mtb_gift_paper'); //■のし
$this->httpCacheControl('nocache');
}

■data/Smarty/templates/default/shopping/confirm.tpl

<!--{if $arrForm.gift_paper neq ''}-->
<tr>
<th scope="row">のしの種類</th>
<td><!--{$arrGIFTPAPER[$arrForm.gift_paper]|h}--></td>
</tr>
<!--{/if}-->
<tr>
<th scope="row">その他お問い合わせ</th>
<td><!--{$arrForm.message|h|nl2br}--></td>
</tr>

■data/Smarty/templates/mobile/shopping/confirm.tpl

【お支払い方法】<br>
<!--{$arrForm.payment_method|h}--><br>

<br>

<!--{if $arrForm.gift_paper neq ''}-->
【のしの種類】<br>
<!--{$arrGIFTPAPER[$arrForm.gift_paper]|escape}--><br>
<br>
<!--{/if}-->

■data/Smarty/templates/sphone/shopping/confirm.tpl

<!--▼フォームボックスここから -->
<div class="formBox">
<div class="innerBox">
<em>配送方法</em>:<!--{$arrDeliv[$arrForm.deliv_id]|h}-->
</div>
<div class="innerBox">
<em>お支払方法:</em><!--{$arrForm.payment_method|h}-->
</div>

<!--{if $arrForm.gift_paper neq ''}-->
<div class="innerBox">
<em>のしの種類:</em><!--{$arrGIFTPAPER[$arrForm.gift_paper]|h}-->
</div>
<!--{/if}-->

(9)「のしの種類」情報をメールに反映させる
■data/class/helper/SC_Helper_Mail.php 2カ所に追加

①50行目あたりに追加

$this->arrPref = $masterData->getMasterData('mtb_pref');
$this->arrGIFTPAPER = $masterData->getMasterData('mtb_gift_paper'); //■のし①/②

②181行目あたりに追加

// 都道府県変換
$arrTplVar->arrPref = $this->arrPref;

//■のし情報の変換 ②/②
$arrTplVar->arrGIFTPAPER = $this->arrGIFTPAPER;

▼PC用メール
■data/Smarty/templates/default/mail_templates/order_mail.tpl
34行目あたり

ご決済方法:<!--{$arrOrder.payment_method}-->
のしの種類:<!--{$arrGIFTPAPER[$arrOrder.gift_paper]}-->

▼携帯用メール
■data/Smarty/templates/mobile/mail_templates/order_mail.tpl
33行目あたり

ご決済方法:<!--{$arrOrder.payment_method}-->
のしの種類:<!--{$arrGIFTPAPER[$arrOrder.gift_paper]}-->

(10)納品書に反映

■data/class/SC_Fpdf.php 2カ所に追加
① 42行目あたり

$this->arrPref = $masterData->getMasterData('mtb_pref');
$this->arrGIFTPAPER = $masterData->getMasterData('mtb_gift_paper'); //■のし①/②

② 323行目あたり

// その他支払い情報を表示
if ($this->arrDisp['memo02'] != '') {
$this->arrDisp['payment_info'] = unserialize($this->arrDisp['memo02']);
}
$this->arrDisp['payment_type'] = 'お支払い';

//■のし情報②/②
if ($this->arrDisp['gift_paper'] != 0) {
$text ="のしの種類:". $this->arrGIFTPAPER[$this->arrDisp['gift_paper']];
$this->lfText(125, 120, $text, 10);
}