Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
【EC-CUBE2.13.3】商品別送料設定で0円設定されている商品が含まれる注文は送料無料にする
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require_once CLASS_REALDIR . 'SC_CartSession.php';
class SC_CartSession_Ex extends SC_CartSession
{
/**
* カートの内容を計算する.
*
* カートの内容を計算し, 下記のキーを保持する連想配列を返す.
*
* - tax: 税額
* - subtotal: カート内商品の小計
* - deliv_fee: カート内商品の合計送料
* - total: 合計金額
* - payment_total: お支払い合計
* - add_point: 加算ポイント
*
* @param integer $productTypeId 商品種別ID
* @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
* @param integer $use_point 今回使用ポイント
* @param integer|array $deliv_pref 配送先都道府県ID.
* 複数に配送する場合は都道府県IDの配列
* @param integer $charge 手数料
* @param integer $discount 値引き
* @param integer $deliv_id 配送業者ID
* @param integer $order_pref 注文者の都道府県ID
* @param integer $order_country_id 注文者の国
* @return array カートの計算結果の配列
*/
public function calculate($productTypeId, &$objCustomer, $use_point = 0,
$deliv_pref = '', $charge = 0, $discount = 0, $deliv_id = 0,
$order_pref = 0, $order_country_id = 0
) {
$results = array();
$total_point = $this->getAllProductsPoint($productTypeId);
// MEMO: 税金計算は注文者の住所基準
$results['tax'] = $this->getAllProductsTax($productTypeId, $order_pref, $order_country_id);
$results['subtotal'] = $this->getAllProductsTotal($productTypeId, $order_pref, $order_country_id);
$results['deliv_fee'] = 0;
// 商品ごとの送料を加算
$isDelivFeeFree = false;// 商品送料無料フラグ
if (OPTION_PRODUCT_DELIV_FEE == 1) {
$cartItems = $this->getCartList($productTypeId);
foreach ($cartItems as $arrItem) {
if (!is_null($arrItem['productsClass']['deliv_fee']) && $arrItem['productsClass']['deliv_fee'] == 0) {
$isDelivFeeFree = true; // 商品送料0円設定の場合true
}
$results['deliv_fee'] += $arrItem['productsClass']['deliv_fee'] * $arrItem['quantity'];
}
}
// 配送業者の送料を加算
if($isDelivFeeFree){
// 送料0円設定の商品がみつかったら全体の送料を0円にする
$results['deliv_fee'] = 0;
}else{
if (OPTION_DELIV_FEE == 1
&& !SC_Utils_Ex::isBlank($deliv_pref)
&& !SC_Utils_Ex::isBlank($deliv_id)) {
$results['deliv_fee'] += SC_Helper_Delivery_Ex::getDelivFee($deliv_pref, $deliv_id);
}
}
// 送料無料チェック
if ($this->isDelivFree($productTypeId)) {
$results['deliv_fee'] = 0;
}
// 合計を計算
$results['total'] = $results['subtotal'];
$results['total'] += $results['deliv_fee'];
$results['total'] += $charge;
$results['total'] -= $discount;
// お支払い合計
$results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
// 加算ポイントの計算
if (USE_POINT !== false) {
$results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point, $use_point);
if ($objCustomer != '') {
// 誕生日月であった場合
if ($objCustomer->isBirthMonth()) {
$results['birth_point'] = BIRTH_MONTH_POINT;
$results['add_point'] += $results['birth_point'];
}
}
if ($results['add_point'] < 0) {
$results['add_point'] = 0;
}
}
return $results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment