EC-CUBE
EC-CUBE2でメール便、小型便などの個別配送設定をおこなおう
はち
更新日:2021/08/10
オンラインショッピングで、小さい小物だけメール便や小型便で送れるというのをよく目にします。
EC-CUBEでは、デフォルトでは商品ごとに配送方法を変更することはできないのでカスタマイズしましょう。
①配送方法に小型便を追加
管理画面メニュ-→基本情報管理→配送設定方法→配送方法・配送料を新規入力
から小型便を追加登録する。
②商品要テーブルに小型便用のカラムを作成
ALTER TABLE dtb_products ADD COLUMN small_deliver_enabled smallint; ALTER TABLE dtb_products ALTER COLUMN small_deliver_enabled SET NOT NULL; ALTER TABLE dtb_products ALTER COLUMN small_deliver_enabled SET DEFAULT 0;
③定数マスタとCSVの項目に小型便用の情報を登録
INSERT INTO `mtb_constants`(`id`, `name`, `rank`, `remarks`) VALUES ('SMALL_DELIVER_ENABLED','"1"',1602,'小型便対応');
INSERT INTO `mtb_constants`(`id`, `name`, `rank`, `remarks`) VALUES ('SMALL_DELIVER_DISABLED','"0"',1603,'小型便非対応');
INSERT INTO `dtb_csv`(`no`, `csv_id`, `col`, `disp_name`, `rank`, `rw_flg`, `status`, `create_date`, `update_date`, `mb_convert_kana_option`, `size_const_type`, `error_check_types`) VALUES
(`no`最大値,1,'small_deliver_enabled','小型便対応',57,2,1,NOW(),NOW(),'n','INT_LEN','NUM_CHECK,SPTAB_CHECK,MAX_LENGTH_CHECK');
④支払い画面で小型便対応商品のみ小型便の選択肢を表示
対象ファイル:
\data\Smarty\templates\default\shopping\payment.tpl
※赤字部分に①で追加した小型便のIDを設定
function changeForm(deliv_id) {
var deliv_time_id_select = $('select[id^=deliv_time_id]');
var deliv_date_select = $('select[id^=deliv_date]');
if (deliv_id == '5') {
⑤商品詳細画面で小型便対応商品の場合「小型便対応」を表記させる
対象ファイル:
\data\Smarty\templates\admin\products\product.tpl
<label>
<input type="checkbox" name="small_deliver_enabled" value="1" <!--{if $arrForm.small_deliver_enabled == "1"}-->checked<!--{/if}--> onclick="fnCheckStockLimit('<!--{$smarty.const.DISABLED_RGB}-->');"/>
小型便対応
</label><br><br>
⑥定数設定ファイルに小型便対応と小型便被対応の定数を追加
対象ファイル:
\data\cache\mtb_constants.php
/** 小型便対応 */
define('SMALL_DELIVER_ENABLED', "1");
/** 小型便非対応 */
define('SMALL_DELIVER_DISABLED', "0");
⑦
対象ファイル:
\data\Smarty\templates\admin\products\confirm.tpl
受注用商品種別小型対応:<!--{if $arrForm.small_deliver_enabled == 1}-->○<!--{else}-->×<!--{/if}-->
<br><br>
対象ファイル:
\data\Smarty\templates\default\products\detail.tpl
<!--{if $arrProduct.small_deliver_enabled == $smarty.const.SMALL_DELIVER_ENABLED}-->
<div class="deliv_explain">小型便対応対象品です</div>
<!--{else}-->
<!--{/if}-->
⑧
対象ファイル:
\data\class\helper\Sc_Helper_Purchase.php
※プラグインを追加していて反映されない場合コチラも編集
\data\class_extends\helper_extends\SC_Helper_Purchase_Ex.php
※赤字部分に①で追加した小型便のIDを設定
public function checkSmallDeliverAvailable($productTypeId, &$objCartSession) {
$available = false;
// カート内の情報を取得
$items = $objCartSession->getCartList($productTypeId);
if (count(array_keys($items))) {
$available = true;
foreach (array_keys($items) as $key) {
$item = & $items[$key];
$product = & $item['productsClass'];
if ($product['small_deliver_enabled'] === SMALL_DELIVER_ENABLED) {
continue;
} else {
$available = false;
}
}
}
return $available;
}
public function getDeliv($product_type_id,$small_delivery_available=true) {
$small_deliv_id = 5;
$objQuery = & SC_Query_Ex::getSingletonInstance();
$objQuery->setOrder('rank DESC');
$where='product_type_id = ? AND del_flg = 0';
$arrval=array($product_type_id);
if(!$small_delivery_available){
$where.=' AND deliv_id !=?';
$arrval[]=$small_deliv_id;
}
return $objQuery->select('*', 'dtb_deliv', $where ,$arrval );
}
これで「配送伝票番号」の項目ができます。
⑨カート内処理
対象ファイル:
\data\class\pages\cart\LC_Page_Cart.php
$this->arrData[$key]['is_deliv_free'] = $objCartSess->isDelivFree($key); $this->arrData[$key]['small_deliv_available'] = $objPurchase->checkSmallDeliverAvailable($key, $objCartSess);
⑩お支払い時の処理
対象ファイル:
\data\class\pages\shopping\LC_Page_Shopping_Payment.php
$small_delivery_available = $objPurchase->checkSmallDeliverAvailable($cart_key, $objCartSess); $this->arrDeliv = $objPurchase->getDeliv($cart_key,$small_delivery_available);
これで個別にメール便対応商品を作成できます。