Exemple #1
0
 /**
 * カートの内容を計算する.
 *
 * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
 *
 * - 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
 * @return array カートの計算結果の配列
 */
 function calculate($productTypeId, &$objCustomer, $use_point = 0, $deliv_pref = "", $charge = 0, $discount = 0, $deliv_id = 0)
 {
     $objDb = new SC_Helper_DB_Ex();
     $total_point = $this->getAllProductsPoint($productTypeId);
     $results['tax'] = $this->getAllProductsTax($productTypeId);
     $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
     $results['deliv_fee'] = 0;
     // 商品ごとの送料を加算
     if (OPTION_PRODUCT_DELIV_FEE == 1) {
         $cartItems = $this->getCartList($productTypeId);
         foreach ($cartItems as $item) {
             $results['deliv_fee'] += $item['productsClass']['deliv_fee'] * $item['quantity'];
         }
     }
     // 配送業者の送料を加算
     if (OPTION_DELIV_FEE == 1 && !SC_Utils_Ex::isBlank($deliv_pref) && !SC_Utils_Ex::isBlank($deliv_id)) {
         $results['deliv_fee'] += $objDb->sfGetDelivFee($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;
 }