/** * カートの内容を計算する. * * カートの内容を計算し, 下記のキーを保持する連想配列を返す. * * - 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; }
/** * 入力内容のチェックを行う. * * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @return array エラーメッセージの配列 */ public function lfCheckError(&$objFormParam) { $objProduct = new SC_Product_Ex(); $arrValues = $objFormParam->getHashArray(); $arrErr = array(); $arrErrTemp = $objFormParam->checkError(); $arrErrDate = array(); foreach ($arrValues['shipping_date_year'] as $key_index => $year) { $month = $arrValues['shipping_date_month'][$key_index]; $day = $arrValues['shipping_date_day'][$key_index]; $objError = new SC_CheckError_Ex(array('shipping_date_year' => $year, 'shipping_date_month' => $month, 'shipping_date_day' => $day)); $objError->doFunc(array('お届け日', 'shipping_date_year', 'shipping_date_month', 'shipping_date_day'), array('CHECK_DATE')); $arrErrDate['shipping_date_year'][$key_index] = $objError->arrErr['shipping_date_year']; } $arrErrTemp = array_merge($arrErrTemp, $arrErrDate); // 複数項目チェック $year = $arrValues['order_birth_year']; $month = $arrValues['order_birth_month']; $day = $arrValues['order_birth_day']; $objError = new SC_CheckError_Ex(array('order_birth_year' => $year, 'order_birth_month' => $month, 'order_birth_day' => $day)); $objError->doFunc(array('生年月日', 'order_birth_year', 'order_birth_month', 'order_birth_day'), array('CHECK_BIRTHDAY')); $arrErrTemp['order_birth_year'] = $objError->arrErr['order_birth_year']; // 商品の種類数 $max = count($arrValues['quantity']); $subtotal = 0; $totalpoint = 0; $totaltax = 0; for ($i = 0; $i < $max; $i++) { // 小計の計算 $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i]; // 小計の計算 $totaltax += SC_Utils_Ex::sfTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i]; // 加算ポイントの計算 $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i]; // 在庫数のチェック $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]); // 編集前の値と比較するため受注詳細を取得 $objPurchase = new SC_Helper_Purchase_Ex(); $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false)); if ($arrProduct['stock_unlimited'] != '1' && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) { $class_name1 = $arrValues['classcategory_name1'][$i]; $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? 'なし' : $class_name1; $class_name2 = $arrValues['classcategory_name2'][$i]; $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? 'なし' : $class_name2; $arrErr['quantity'][$i] .= $arrValues['product_name'][$i] . '/(' . $class_name1 . ')/(' . $class_name2 . ') の在庫が不足しています。 設定できる数量は「' . ($arrOrderDetail['quantity'][$i] + $arrProduct['stock']) . '」までです。<br />'; } } // 消費税 $arrValues['tax'] = $totaltax; // 小計 $arrValues['subtotal'] = $subtotal; // 合計 $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge']; // お支払い合計 $arrValues['payment_total'] = $arrValues['total'] - $arrValues['use_point'] * POINT_VALUE; // 加算ポイント $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']) + $arrValues['birth_point']; // 最終保持ポイント $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point']; if ($arrValues['total'] < 0) { $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; } if ($arrValues['payment_total'] < 0) { $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; } if ($arrValues['total_point'] < 0) { $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; } $objFormParam->setParam($arrValues); $arrErr = array_merge($arrErr, $arrErrTemp); return $arrErr; }
/** * 入力内容のチェックを行う. * * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @return array エラーメッセージの配列 */ function lfCheckError(&$objFormParam) { $objProduct = new SC_Product_Ex(); $arrErr = $objFormParam->checkError(); if (!SC_Utils_Ex::isBlank($objErr->arrErr)) { return $arrErr; } $arrValues = $objFormParam->getHashArray(); // 商品の種類数 $max = count($arrValues['quantity']); $subtotal = 0; $totalpoint = 0; $totaltax = 0; for ($i = 0; $i < $max; $i++) { // 小計の計算 $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; // 小計の計算 $totaltax += SC_Helper_DB_Ex::sfTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; // 加算ポイントの計算 $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i]; // 在庫数のチェック $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]); // 編集前の値と比較するため受注詳細を取得 $objPurchase = new SC_Helper_Purchase_Ex(); $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false)); if ($arrProduct['stock_unlimited'] != '1' && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) { $class_name1 = $arrValues['classcategory_name1'][$i]; $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? 'なし' : $class_name1; $class_name2 = $arrValues['classcategory_name2'][$i]; $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? 'なし' : $class_name2; $arrErr['quantity'][$i] .= $arrValues['product_name'][$i] . '/(' . $class_name1 . ')/(' . $class_name2 . ') の在庫が不足しています。 設定できる数量は「' . ($arrOrderDetail['quantity'][$i] + $arrProduct['stock']) . '」までです。<br />'; } } // 消費税 $arrValues['tax'] = $totaltax; // 小計 $arrValues['subtotal'] = $subtotal; // 合計 $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge']; // お支払い合計 $arrValues['payment_total'] = $arrValues['total'] - $arrValues['use_point'] * POINT_VALUE; // 加算ポイント $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']); // 最終保持ポイント $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point']; if ($arrValues['total'] < 0) { $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; } if ($arrValues['payment_total'] < 0) { $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; } if ($arrValues['total_point'] < 0) { $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; } $objFormParam->setParam($arrValues); return $arrErr; }
/** * 入力内容のチェックを行う. * * @param SC_FormParam $objFormParam SC_FormParam インスタンス * @return array エラーメッセージの配列 */ function lfCheckError(&$objFormParam) { $objProduct = new SC_Product_Ex(); $arrErr = $objFormParam->checkError(); if (!SC_Utils_Ex::isBlank($objErr->arrErr)) { return $arrErr; } $arrValues = $objFormParam->getHashArray(); // 商品の種類数 $max = count($arrValues['quantity']); $subtotal = 0; $totalpoint = 0; $totaltax = 0; for ($i = 0; $i < $max; $i++) { // 小計の計算 $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; // 小計の計算 $totaltax += SC_Helper_DB_Ex::sfTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; // 加算ポイントの計算 $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i]; // 在庫数のチェック $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]); // 編集前の値と比較するため受注詳細を取得 $objPurchase = new SC_Helper_Purchase_Ex(); $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false)); if ($arrProduct['stock_unlimited'] != '1' && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) { $class_name1 = $arrValues['classcategory_name1'][$i]; $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? t('c_None_01') : $class_name1; $class_name2 = $arrValues['classcategory_name2'][$i]; $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? t('c_None_01') : $class_name2; $arrErr['quantity'][$i] .= t('c_There is an inventory shortage for T_ARG1/(T_ARG2)/(T_ARG3). Up to T_ARG4 can be set for the quantity.<br />_1', array('T_ARG1' => $arrValues['product_name'][$i], 'T_ARG2' => $class_name1, 'T_ARG3' => $class_name2, 'T_ARG4' => $arrOrderDetail['quantity'][$i] + $arrProduct['stock'])); } } // 消費税 $arrValues['tax'] = $totaltax; // 小計 $arrValues['subtotal'] = $subtotal; // 合計 $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge']; // お支払い合計 $arrValues['payment_total'] = $arrValues['total'] - $arrValues['use_point'] * POINT_VALUE; // 加算ポイント $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']); // 最終保持ポイント $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point']; if ($arrValues['total'] < 0) { $arrErr['total'] = t('c_Adjust so that the total amount is not a negative number.<br />_01'); } if ($arrValues['payment_total'] < 0) { $arrErr['payment_total'] = t('c_Adjust so that a negative number is not displayed for the payment total.<br />_01'); } if ($arrValues['total_point'] < 0) { $arrErr['use_point'] = t('c_Adjust the final number of points registered so that it does not become a negative number.<br />_01'); } $objFormParam->setParam($arrValues); return $arrErr; }