/**
 * カートの内容を計算する.
 *
 * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
 *
 * - 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;
     // 商品ごとの送料を加算
     if (OPTION_PRODUCT_DELIV_FEE == 1) {
         $cartItems = $this->getCartList($productTypeId);
         foreach ($cartItems as $arrItem) {
             $results['deliv_fee'] += $arrItem['productsClass']['deliv_fee'] * $arrItem['quantity'];
         }
     }
     // 配送業者の送料を加算
     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;
 }
Example #2
0
 /**
  * 集計情報を元に最終計算を行う.
  *
  * @param array $arrData 各種情報
  * @param LC_Page $objPage LC_Page インスタンス
  * @param SC_CartSession $objCartSess SC_CartSession インスタンス
  * @param array $arrInfo 店舗情報の配列
  * @param SC_Customer $objCustomer SC_Customer インスタンス
  * @return array 最終計算後の配列
  */
 function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $arrInfo, $objCustomer = "")
 {
     // 未定義変数を定義
     if (!isset($arrData['deliv_pref'])) {
         $arrData['deliv_pref'] = "";
     }
     if (!isset($arrData['payment_id'])) {
         $arrData['payment_id'] = "";
     }
     if (!isset($arrData['charge'])) {
         $arrData['charge'] = "";
     }
     if (!isset($arrData['use_point'])) {
         $arrData['use_point'] = "";
     }
     // 商品の合計個数
     $total_quantity = $objCartSess->getTotalQuantity(true);
     // 税金の取得
     $arrData['tax'] = $objPage->tpl_total_tax;
     // 小計の取得
     $arrData['subtotal'] = $objPage->tpl_total_pretax;
     // 合計送料の取得
     $arrData['deliv_fee'] = 0;
     // 商品ごとの送料が有効の場合
     if (OPTION_PRODUCT_DELIV_FEE == 1) {
         $arrData['deliv_fee'] += $objCartSess->getAllProductsDelivFee();
     }
     // 配送業者の送料が有効の場合
     if (OPTION_DELIV_FEE == 1) {
         // 送料の合計を計算する
         $arrData['deliv_fee'] += $this->sfGetDelivFee($arrData);
     }
     // 送料無料の購入数が設定されている場合
     if (DELIV_FREE_AMOUNT > 0) {
         if ($total_quantity >= DELIV_FREE_AMOUNT) {
             $arrData['deliv_fee'] = 0;
         }
     }
     // 送料無料条件が設定されている場合
     if ($arrInfo['free_rule'] > 0) {
         // 小計が無料条件を超えている場合
         if ($arrData['subtotal'] >= $arrInfo['free_rule']) {
             $arrData['deliv_fee'] = 0;
         }
     }
     // 合計の計算
     $arrData['total'] = $objPage->tpl_total_pretax;
     // 商品合計
     $arrData['total'] += $arrData['deliv_fee'];
     // 送料
     $arrData['total'] += $arrData['charge'];
     // 手数料
     // お支払い合計
     $arrData['payment_total'] = $arrData['total'] - $arrData['use_point'] * POINT_VALUE;
     // 加算ポイントの計算
     if (USE_POINT === false) {
         $arrData['add_point'] = 0;
     } else {
         $arrData['add_point'] = SC_Utils::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
         if ($objCustomer != "") {
             // 誕生日月であった場合
             if ($objCustomer->isBirthMonth()) {
                 $arrData['birth_point'] = BIRTH_MONTH_POINT;
                 $arrData['add_point'] += $arrData['birth_point'];
             }
         }
     }
     if ($arrData['add_point'] < 0) {
         $arrData['add_point'] = 0;
     }
     return $arrData;
 }