Last active
August 29, 2015 14:07
-
-
Save hideki-a/398ab1173618f807cf6b to your computer and use it in GitHub Desktop.
EC-CUBEで、選択可能な支払い方法の抽出時に送料が勘案されないため、代引手数料等が狂う問題の解決。EC-CUBE 2.13.2。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php b/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
index 0cc5ee5..2bfef7f 100644 | |
--- a/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
+++ b/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
@@ -125,6 +125,11 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
// お届け日一覧の取得 | |
$this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $cart_key); | |
+ // 配達先の都道府県IDの取得 | |
+ // 本サイトでは単一の配送先しか認めていないので、複数のお届け先については未検証 | |
+ $strFirstKey = $this->firstKey($this->arrShipping); | |
+ $deliv_pref = $this->arrShipping[$strFirstKey]['shipping_pref']; | |
+ | |
switch ($this->getMode()) { | |
/* | |
* 配送業者選択時のアクション | |
@@ -136,7 +141,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
$this->arrErr = $objFormParam->checkError(); | |
if (SC_Utils_Ex::isBlank($this->arrErr)) { | |
$deliv_id = $objFormParam->getValue('deliv_id'); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref); | |
$arrSelectedDeliv['error'] = false; | |
} else { | |
$arrSelectedDeliv = array('error' => true); | |
@@ -158,7 +163,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
$this->setFormParams($objFormParam, $_POST, $this->is_download, $this->arrShipping); | |
$deliv_id = $objFormParam->getValue('deliv_id'); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref); | |
$this->arrPayment = $arrSelectedDeliv['arrPayment']; | |
$this->arrDelivTime = $arrSelectedDeliv['arrDelivTime']; | |
$this->img_show = $arrSelectedDeliv['img_show']; | |
@@ -214,7 +218,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
if (!SC_Utils_Ex::isBlank($deliv_id)) { | |
$objFormParam->setValue('deliv_id', $deliv_id); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref); | |
$this->arrPayment = $arrSelectedDeliv['arrPayment']; | |
$this->arrDelivTime = $arrSelectedDeliv['arrDelivTime']; | |
$this->img_show = $arrSelectedDeliv['img_show']; | |
@@ -232,6 +236,19 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
} | |
/** | |
+ * 連想配列の最初のキーを返す. | |
+ * | |
+ * @param array $array 処理する連想配列 | |
+ * @return string 最初のキー | |
+ * See Also: http://vinypara.s236.xrea.com/archives/544 | |
+ */ | |
+ public function firstKey($array) | |
+ { | |
+ reset($array); | |
+ return key($array); | |
+ } | |
+ | |
+ /** | |
* パラメーターの初期化を行い, 初期値を設定する. | |
* | |
* @param SC_FormParam $objFormParam SC_FormParam インスタンス | |
@@ -383,16 +400,30 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
* | |
* @param SC_CartSession $objCartSess SC_CartSession インスタンス | |
* @param integer $deliv_id 配送業者ID | |
+ * @param string $deliv_pref 配送先都道府県ID | |
* @return array 支払い方法, お届け時間を格納した配列 | |
*/ | |
- public function getSelectedDeliv(&$objCartSess, $deliv_id) | |
+ public function getSelectedDeliv(&$objCartSess, $deliv_id, $deliv_pref) | |
{ | |
$arrResults = array(); | |
$arrResults['arrDelivTime'] = SC_Helper_Delivery_Ex::getDelivTime($deliv_id); | |
$total = $objCartSess->getAllProductsTotal($objCartSess->getKey()); | |
- $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id); | |
+ $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id); // 選択した配送業者で利用可能な支払方法ID | |
$objPayment = new SC_Helper_Payment_Ex(); | |
- $payments_total = $objPayment->getByPrice($total); | |
+ $objQuery =& SC_Query_Ex::getSingletonInstance(); | |
+ $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); | |
+ | |
+ // 送料を取得 | |
+ $arrParam = array($deliv_id, $deliv_pref); | |
+ $arrDelivFee = $objQuery->getCol('fee', 'dtb_delivfee', 'deliv_id = ? AND pref = ?', $arrParam); | |
+ | |
+ // 商品の合計金額が送料無料条件未満の場合、送料を加算する | |
+ // 支払手数料を算定する際、商品の合計金額に送料を加味した金額で判定する業者があるため | |
+ if ($total < (float)$arrInfo['free_rule']) { | |
+ $total += (float)array_shift($arrDelivFee); | |
+ } | |
+ | |
+ $payments_total = $objPayment->getByPrice($total); // 合計金額に応じた支払方法 | |
$arrPayment = array(); | |
foreach ($payments_total as $payment) { | |
if (in_array($payment['payment_id'], $payments_deliv)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php b/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
index 0cc5ee5..80f42a3 100644 | |
--- a/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
+++ b/eccube_data/class/pages/shopping/LC_Page_Shopping_Payment.php | |
@@ -125,6 +125,12 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
// お届け日一覧の取得 | |
$this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $cart_key); | |
+ // 配達先の都道府県IDの取得 | |
+ // 本サイトでは単一の配送先しか認めていないので、複数のお届け先については未検証 | |
+ $strFirstKey = $this->firstKey($this->arrShipping); | |
+ $deliv_pref = $this->arrShipping[$strFirstKey]['shipping_pref']; | |
+ $arr_deliv_type = $this->getDelivType($this->arrShipping[$strFirstKey]['shipment_item']); | |
+ | |
switch ($this->getMode()) { | |
/* | |
* 配送業者選択時のアクション | |
@@ -136,7 +142,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
$this->arrErr = $objFormParam->checkError(); | |
if (SC_Utils_Ex::isBlank($this->arrErr)) { | |
$deliv_id = $objFormParam->getValue('deliv_id'); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref, $arr_deliv_type); | |
$arrSelectedDeliv['error'] = false; | |
} else { | |
$arrSelectedDeliv = array('error' => true); | |
@@ -158,7 +164,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
$this->setFormParams($objFormParam, $_POST, $this->is_download, $this->arrShipping); | |
$deliv_id = $objFormParam->getValue('deliv_id'); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref, $arr_deliv_type); | |
$this->arrPayment = $arrSelectedDeliv['arrPayment']; | |
$this->arrDelivTime = $arrSelectedDeliv['arrDelivTime']; | |
$this->img_show = $arrSelectedDeliv['img_show']; | |
@@ -205,7 +211,6 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
default: | |
// FIXME 前のページから戻ってきた場合は別パラメーター(mode)で処理分岐する必要があるのかもしれない | |
$this->setFormParams($objFormParam, $arrOrderTemp, $this->is_download, $this->arrShipping); | |
- | |
if (!$this->is_single_deliv) { | |
$deliv_id = $objFormParam->getValue('deliv_id'); | |
} else { | |
@@ -214,7 +219,7 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
if (!SC_Utils_Ex::isBlank($deliv_id)) { | |
$objFormParam->setValue('deliv_id', $deliv_id); | |
- $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id); | |
+ $arrSelectedDeliv = $this->getSelectedDeliv($objCartSess, $deliv_id, $deliv_pref, $arr_deliv_type); | |
$this->arrPayment = $arrSelectedDeliv['arrPayment']; | |
$this->arrDelivTime = $arrSelectedDeliv['arrDelivTime']; | |
$this->img_show = $arrSelectedDeliv['img_show']; | |
@@ -232,6 +237,37 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
} | |
/** | |
+ * 連想配列の最初のキーを返す. | |
+ * | |
+ * @param array $array 処理する連想配列 | |
+ * @return string 最初のキー | |
+ * See Also: http://vinypara.s236.xrea.com/archives/544 | |
+ */ | |
+ public function firstKey($array) | |
+ { | |
+ reset($array); | |
+ return key($array); | |
+ } | |
+ | |
+ /** | |
+ * 注文商品の配送温度帯を返す. | |
+ * | |
+ * @param array $arrShipmentItem カートの商品 | |
+ * @return array 配送温度帯 | |
+ * See Also: http://vinypara.s236.xrea.com/archives/544 | |
+ */ | |
+ public function getDelivType($arrShipmentItem) | |
+ { | |
+ $arrShippingType = array(); | |
+ | |
+ foreach ($arrShipmentItem as $item) { | |
+ $arrShippingType[] = $item['productsClass']['plg_cooldeliv_ondotai']; | |
+ } | |
+ | |
+ return array_unique($arrShippingType); | |
+ } | |
+ | |
+ /** | |
* パラメーターの初期化を行い, 初期値を設定する. | |
* | |
* @param SC_FormParam $objFormParam SC_FormParam インスタンス | |
@@ -383,16 +419,41 @@ class LC_Page_Shopping_Payment extends LC_Page_Ex | |
* | |
* @param SC_CartSession $objCartSess SC_CartSession インスタンス | |
* @param integer $deliv_id 配送業者ID | |
+ * @param string $deliv_pref 配送先都道府県ID | |
+ * @param array $arr_deliv_type 配送温度帯 | |
* @return array 支払い方法, お届け時間を格納した配列 | |
*/ | |
- public function getSelectedDeliv(&$objCartSess, $deliv_id) | |
+ public function getSelectedDeliv(&$objCartSess, $deliv_id, $deliv_pref, $arr_deliv_type) | |
{ | |
$arrResults = array(); | |
$arrResults['arrDelivTime'] = SC_Helper_Delivery_Ex::getDelivTime($deliv_id); | |
$total = $objCartSess->getAllProductsTotal($objCartSess->getKey()); | |
- $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id); | |
+ $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id); // 選択した配送業者で利用可能な支払方法ID | |
$objPayment = new SC_Helper_Payment_Ex(); | |
- $payments_total = $objPayment->getByPrice($total); | |
+ $objQuery =& SC_Query_Ex::getSingletonInstance(); | |
+ $arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); | |
+ $delivFee = 0; | |
+ | |
+ // 送料を取得 | |
+ $arrParam = array($deliv_id, $deliv_pref); | |
+ foreach ($arr_deliv_type as $type) { | |
+ if ($type == 2) { | |
+ $col = 'plg_cooldeliv_reizo'; | |
+ } else if ($type == 3) { | |
+ $col = 'plg_cooldeliv_reito'; | |
+ } else { | |
+ $col = 'plg_cooldeliv_jouon'; | |
+ } | |
+ $delivFee += (float)array_shift($objQuery->getCol($col, 'dtb_delivfee', 'deliv_id = ? AND pref = ?', $arrParam)); | |
+ } | |
+ | |
+ // 商品の合計金額が送料無料条件未満の場合、送料を加算する | |
+ // 支払手数料を算定する際、商品の合計金額に送料を加味した金額で判定する業者があるため | |
+ if ($total < (float)$arrInfo['free_rule']) { | |
+ $total += $delivFee; | |
+ } | |
+ | |
+ $payments_total = $objPayment->getByPrice($total); // 合計金額に応じた支払方法 | |
$arrPayment = array(); | |
foreach ($payments_total as $payment) { | |
if (in_array($payment['payment_id'], $payments_deliv)) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment