/**
  * 商品種別ごとにカート内商品の一覧を取得する.
  *
  * @param  integer $productTypeId 商品種別ID
  * @param  integer $pref_id       税金計算用注文者都道府県ID
  * @param  integer $country_id    税金計算用注文者国ID
  * @return array   カート内商品一覧の配列
  */
 public function getCartList($productTypeId, $pref_id = 0, $country_id = 0)
 {
     $objProduct = new SC_Product_Ex();
     $max = $this->getMax($productTypeId);
     $arrRet = array();
     /*
             $const_name = '_CALLED_SC_CARTSESSION_GETCARTLIST_' . $productTypeId;
             if (defined($const_name)) {
                 $is_first = true;
             } else {
                 define($const_name, true);
                 $is_first = false;
             }
     */
     for ($i = 0; $i <= $max; $i++) {
         if (isset($this->cartSession[$productTypeId][$i]['cart_no']) && $this->cartSession[$productTypeId][$i]['cart_no'] != '') {
             // 商品情報は常に取得
             // TODO: 同一インスタンス内では1回のみ呼ぶようにしたい
             // TODO: ここの商品の合計処理は getAllProductsTotalや getAllProductsTaxとで類似重複なので統一出来そう
             /*
                             // 同一セッション内では初回のみDB参照するようにしている
                             if (!$is_first) {
                                 $this->setCartSession4getCartList($productTypeId, $i);
                             }
             */
             $this->cartSession[$productTypeId][$i]['productsClass'] =& $objProduct->getDetailAndProductsClass($this->cartSession[$productTypeId][$i]['id']);
             $price = $this->cartSession[$productTypeId][$i]['productsClass']['price02'];
             $this->cartSession[$productTypeId][$i]['price'] = $price;
             $this->cartSession[$productTypeId][$i]['point_rate'] = $this->cartSession[$productTypeId][$i]['productsClass']['point_rate'];
             $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
             $arrTaxRule = SC_Helper_TaxRule_Ex::getTaxRule($this->cartSession[$productTypeId][$i]['productsClass']['product_id'], $this->cartSession[$productTypeId][$i]['productsClass']['product_class_id'], $pref_id, $country_id);
             $incTax = $price + SC_Helper_TaxRule_Ex::calcTax($price, $arrTaxRule['tax_rate'], $arrTaxRule['tax_rule'], $arrTaxRule['tax_adjust']);
             $total = $incTax * $quantity;
             $this->cartSession[$productTypeId][$i]['price_inctax'] = $incTax;
             $this->cartSession[$productTypeId][$i]['total_inctax'] = $total;
             $this->cartSession[$productTypeId][$i]['tax_rate'] = $arrTaxRule['tax_rate'];
             $this->cartSession[$productTypeId][$i]['tax_rule'] = $arrTaxRule['tax_rule'];
             $this->cartSession[$productTypeId][$i]['tax_adjust'] = $arrTaxRule['tax_adjust'];
             $arrRet[] = $this->cartSession[$productTypeId][$i];
             // セッション変数のデータ量を抑制するため、一部の商品情報を切り捨てる
             // XXX 上で「常に取得」するのだから、丸ごと切り捨てて良さそうにも感じる。
             $this->adjustSessionProductsClass($this->cartSession[$productTypeId][$i]['productsClass']);
         }
     }
     return $arrRet;
 }
 /**
  * 受注商品一覧側に商品を追加
  *
  * @param SC_FormParam  $objFormParam               SC_FormParam インスタンス
  * @param array         $arrProductClassIds        対象配列の商品規格ID
  * @param int           $insert_product_class_id    追加商品規格ID
  * @param array         $arrAddProductInfo          追加データ
  * @return array|null   $arrAddProducts             更新データ
  */
 public function checkInsertOrderProducts(&$objFormParam, $arrProductClassIds, $insert_product_class_id, $arrAddProductInfo)
 {
     if (!$arrProductClassIds || !in_array($insert_product_class_id, $arrProductClassIds)) {
         $arrAddProducts = array();
         $arrTax = SC_Helper_TaxRule_Ex::getTaxRule(0, $insert_product_class_id);
         $arrAddProductInfo['product_name'] = $arrAddProductInfo['product_name'] ? $arrAddProductInfo['product_name'] : $arrAddProductInfo['name'];
         $arrAddProductInfo['price'] = $arrAddProductInfo['price'] ? $arrAddProductInfo['price'] : $arrAddProductInfo['price02'];
         $arrAddProductInfo['quantity'] = 1;
         $arrAddProductInfo['tax_rate'] = $objFormParam->getValue('order_tax_rate') == '' ? $arrTax['tax_rate'] : $objFormParam->getValue('order_tax_rate');
         $arrAddProductInfo['tax_rule'] = $objFormParam->getValue('order_tax_rule') == '' ? $arrTax['tax_rule'] : $objFormParam->getValue('order_tax_rule');
         foreach ($this->arrProductKeys as $insert_key) {
             $value = $objFormParam->getValue($insert_key);
             $arrAddProducts[$insert_key] = is_array($value) ? $value : array();
             $arrAddProducts[$insert_key][] = $arrAddProductInfo[$insert_key];
         }
         return $arrAddProducts;
     } else {
         //受注商品の数量は、複数配送側の集計で出しているので、重複しても数量を増やさない。
         return null;
     }
 }
Example #3
0
 /**
  * 税率設定情報を登録する(商品管理用)
  *
  * @param float $tax_rate 消費税率
  * @param int $product_id 商品ID
  * @param int $product_class_id 商品規格ID
  * @param integer $tax_adjust 消費税加算額
  * @param int $pref_id 県ID
  * @param int $country_id 国ID
  * @return void
  */
 public static function setTaxRuleForProduct($tax_rate, $product_id = 0, $product_class_id = 0, $tax_adjust = 0, $pref_id = 0, $country_id = 0)
 {
     // 基本設定を取得
     $arrRet = SC_Helper_TaxRule_Ex::getTaxRule($product_id, $product_class_id);
     // 基本設定の消費税率と一緒であれば設定しない
     if ($arrRet['tax_rate'] != $tax_rate) {
         // 課税規則は基本設定のものを使用
         $calc_rule = $arrRet['calc_rule'];
         // 日付は登録時点を設定
         $apply_date = date('Y/m/d H:i:s');
         // 税情報を設定
         SC_Helper_TaxRule_Ex::setTaxRule($calc_rule, $tax_rate, $apply_date, NULL, $tax_adjust, $product_id, $product_class_id, $pref_id, $country_id);
     }
 }
 /**
  * 表示用フォームパラメーター取得
  * - 入力画面
  *
  * @param  SC_UploadFile_Ex $objUpFile   SC_UploadFileインスタンス
  * @param  SC_UploadFile_Ex $objDownFile SC_UploadFileインスタンス
  * @param  array  $arrForm     フォーム入力パラメーター配列
  * @return array  表示用フォームパラメーター配列
  */
 public function lfSetViewParam_InputPage(&$objUpFile, &$objDownFile, &$arrForm)
 {
     // カテゴリマスターデータ取得
     $objDb = new SC_Helper_DB_Ex();
     list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
     if (isset($arrForm['category_id']) && !is_array($arrForm['category_id'])) {
         $arrForm['category_id'] = SC_Utils_Ex::jsonDecode($arrForm['category_id']);
     }
     $this->tpl_json_category_id = !empty($arrForm['category_id']) ? SC_Utils_Ex::jsonEncode($arrForm['category_id']) : SC_Utils_Ex::jsonEncode(array());
     if ($arrForm['status'] == '') {
         $arrForm['status'] = DEFAULT_PRODUCT_DISP;
     }
     if ($arrForm['product_type_id'] == '') {
         $arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
     }
     if (OPTION_PRODUCT_TAX_RULE) {
         // 編集の場合は設定された税率、新規の場合はデフォルトの税率を取得
         if ($arrForm['product_id'] == '') {
             $arrRet = SC_Helper_TaxRule_Ex::getTaxRule();
         } else {
             $arrRet = SC_Helper_TaxRule_Ex::getTaxRule($arrForm['product_id'], $arrForm['product_class_id']);
         }
         $arrForm['tax_rate'] = $arrRet['tax_rate'];
     }
     // アップロードファイル情報取得(Hidden用)
     $arrHidden = $objUpFile->getHiddenFileList();
     $arrForm['arrHidden'] = array_merge((array) $arrHidden, (array) $objDownFile->getHiddenFileList());
     // 画像ファイル表示用データ取得
     $arrForm['arrFile'] = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
     // ダウンロード商品実ファイル名取得
     $arrForm['down_realfilename'] = $objDownFile->getFormDownFile();
     // 基本情報(デフォルトポイントレート用)
     $arrForm['arrInfo'] = SC_Helper_DB_Ex::sfGetBasisData();
     // サブ情報ありなしフラグ
     $arrForm['sub_find'] = $this->hasSubProductData($arrForm);
     return $arrForm;
 }
 /**
  * 規格編集画面を表示する
  *
  * @param SC_FormParam $objFormParam
  */
 public function doPreEdit(&$objFormParam)
 {
     $product_id = $objFormParam->getValue('product_id');
     $objProduct = new SC_Product_Ex();
     $existsProductsClass = $objProduct->getProductsClassFullByProductId($product_id);
     // 規格のデフォルト値(全ての組み合わせ)を取得し, フォームに反映
     $class_id1 = $existsProductsClass[0]['class_id1'];
     $class_id2 = $existsProductsClass[0]['class_id2'];
     $objFormParam->setValue('class_id1', $class_id1);
     $objFormParam->setValue('class_id2', $class_id2);
     $this->doDisp($objFormParam);
     /*
      * 登録済みのデータで, フォームの値を上書きする.
      *
      * 登録済みデータと, フォームの値は, 配列の形式が違うため,
      * 同じ形式の配列を生成し, マージしてフォームの値を上書きする
      */
     $arrKeys = array('classcategory_id1', 'classcategory_id2', 'product_code', 'classcategory_name1', 'classcategory_name2', 'stock', 'stock_unlimited', 'price01', 'price02', 'product_type_id', 'down_filename', 'down_realfilename', 'upload_index', 'tax_rate');
     $arrFormValues = $objFormParam->getSwapArray($arrKeys);
     // フォームの規格1, 規格2をキーにした配列を生成
     $arrClassCatKey = array();
     foreach ($arrFormValues as $formValue) {
         $arrClassCatKey[$formValue['classcategory_id1']][$formValue['classcategory_id2']] = $formValue;
     }
     // 登録済みデータをマージ
     foreach ($existsProductsClass as $existsValue) {
         $arrClassCatKey[$existsValue['classcategory_id1']][$existsValue['classcategory_id2']] = $existsValue;
     }
     // 規格のデフォルト値に del_flg をつけてマージ後の1次元配列を生成
     $arrMergeProductsClass = array();
     foreach ($arrClassCatKey as $arrC1) {
         foreach ($arrC1 as $arrValues) {
             $arrValues['del_flg'] = (string) $arrValues['del_flg'];
             if (SC_Utils_Ex::isBlank($arrValues['del_flg']) || $arrValues['del_flg'] === '1') {
                 $arrValues['del_flg'] = '1';
             } else {
                 $arrValues['del_flg'] = '0';
             }
             // 消費税率を設定
             if (OPTION_PRODUCT_TAX_RULE) {
                 $arrRet = SC_Helper_TaxRule_Ex::getTaxRule($arrValues['product_id'], $arrValues['product_class_id']);
                 $arrValues['tax_rate'] = $arrRet['tax_rate'];
             }
             $arrMergeProductsClass[] = $arrValues;
         }
     }
     // 登録済みのデータで上書き
     $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrMergeProductsClass));
     // $arrMergeProductsClass で product_id が配列になってしまうため数値で上書き
     $objFormParam->setValue('product_id', $product_id);
     // check を設定
     $arrChecks = array();
     $index = 0;
     foreach ($objFormParam->getValue('del_flg') as $key => $val) {
         if ($val === '0') {
             $arrChecks[$index] = 1;
         }
         $index++;
     }
     $objFormParam->setValue('check', $arrChecks);
     // class_id1, class_id2 を取得値で上書き
     $objFormParam->setValue('class_id1', $class_id1);
     $objFormParam->setValue('class_id2', $class_id2);
 }