/** * このフォーム特有の複雑な入力チェックを行う. * * @param array 確認対象データ * @param array エラー配列 * @return array エラー配列 */ public function lfCheckErrorDetail($item, $arrErr) { // 規格IDの存在チェック // FIXME 規格分類ID自体のが有効かを主眼においたチェックをすべきと感じる。 if (!$this->lfIsDbRecord('dtb_products_class', 'product_class_id', $item)) { $arrErr['product_class_id'] = '※ 指定の商品規格IDは、登録されていません。'; } // 商品ID、規格IDの組合せチェック if (array_search('product_class_id', $this->arrFormKeyList) !== FALSE && $item['product_class_id'] != '') { if ($item['product_id'] == '') { $arrErr['product_class_id'] = '※ 商品規格ID指定時には商品IDの指定が必須です。'; } else { if (!$this->objDb->isRecord('dtb_products_class', 'product_id, product_class_id', array($item['product_id'], $item['product_class_id']))) { $arrErr['product_class_id'] = '※ 指定の商品IDと商品規格IDの組合せは正しくありません。'; } // product_class_idは(product_id, classcategory_id1, classcategory_id2)に対して一意。既に異なるproduct_class_idが存在した場合はエラー $classcategory_id1 = $item['classcategory_id'] ? $item['classcategory_id'] : 0; $classcategory_id2 = $item['parent_classcategory_id'] ? $item['parent_classcategory_id'] : 0; $product_class_id = Utils::sfGetProductClassId($item['product_id'], $classcategory_id1, $classcategory_id2); if ($product_class_id && $product_class_id != $item['product_class_id']) { $arrErr['product_class_id'] = '※ 指定の商品ID/規格分類と、商品規格IDの組合せは正しくありません。'; } } } // 表示ステータスの存在チェック if (!$this->lfIsArrayRecord($this->arrDISP, 'status', $item)) { $arrErr['status'] = '※ 指定の表示ステータスは、登録されていません。'; } // メーカーIDの存在チェック if (!$this->lfIsArrayRecord($this->arrMaker, 'maker_id', $item)) { $arrErr['maker_id'] = '※ 指定のメーカーIDは、登録されていません。'; } // 発送日目安IDの存在チェック if (!$this->lfIsArrayRecord($this->arrDELIVERYDATE, 'deliv_date_id', $item)) { $arrErr['deliv_date_id'] = '※ 指定の発送日目安IDは、登録されていません。'; } // 商品種別IDの存在チェック if (!$this->lfIsArrayRecord($this->arrProductType, 'product_type_id', $item)) { $arrErr['product_type_id'] = '※ 指定の商品種別IDは、登録されていません。'; } // 関連商品IDのチェック $arrRecommendProductUnique = array(); for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { $recommend_product_id_key = 'recommend_product_id' . $i; if (array_search($recommend_product_id_key, $this->arrFormKeyList) !== FALSE && $item[$recommend_product_id_key] != '') { // 商品IDの存在チェック if (!$this->objDb->isRecord('dtb_products', 'product_id', (array) $item[$recommend_product_id_key])) { $arrErr[$recommend_product_id_key] = "※ 指定の関連商品ID({$i})は、登録されていません。"; continue; } // 商品IDの重複チェック $recommend_product_id = $item[$recommend_product_id_key]; if (isset($arrRecommendProductUnique[$recommend_product_id])) { $arrErr[$recommend_product_id_key] = "※ 指定の関連商品ID({$i})は、すでに登録されています。"; } else { $arrRecommendProductUnique[$recommend_product_id] = true; } } } // カテゴリIDの存在チェック if (!$this->lfIsDbRecordMulti('dtb_category', 'category_id', 'category_ids', $item, ',')) { $arrErr['category_ids'] = '※ 指定のカテゴリIDは、登録されていません。'; } // 商品ステータスIDの存在チェック if (!$this->lfIsArrayRecordMulti($this->arrSTATUS, 'product_statuses', $item, ',')) { $arrErr['product_statuses'] = '※ 指定の商品ステータスIDは、登録されていません。'; } // 削除フラグのチェック if (array_search('del_flg', $this->arrFormKeyList) !== FALSE && $item['del_flg'] != '') { if (!($item['del_flg'] == '0' or $item['del_flg'] == '1')) { $arrErr['del_flg'] = '※ 削除フラグは「0」(有効)、「1」(削除)のみが有効な値です。'; } } /* TODO: 在庫数の扱いが2.4仕様ではぶれているのでどうするか・・ // 在庫数/在庫無制限フラグの有効性に関するチェック if ($item['stock'] == '') { if (array_search('stock_unlimited', $this->arrFormKeyList) === FALSE) { $arrErr['stock'] = '※ 在庫数は必須です(無制限フラグ項目がある場合のみ空欄許可)。'; } elseif ($item['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) { $arrErr['stock'] = '※ 在庫数または在庫無制限フラグのいずれかの入力が必須です。'; } } */ // ダウンロード商品チェック if (array_search('product_type_id', $this->arrFormKeyList) !== FALSE && $item['product_type_id'] != PRODUCT_TYPE_DOWNLOAD) { //実商品の場合 if ($item['down_filename'] != '') { $arrErr['down_filename'] = '※ ダウンロード商品ではない場合、ダウンロードファイル名は入力できません。'; } if ($item['down_realfilename'] != '') { $arrErr['down_realfilename'] = '※ ダウンロード商品ではない場合、ダウンロード商品用ファイルアップロードは入力できません。'; } } elseif (array_search('product_type_id', $this->arrFormKeyList) !== FALSE && $item['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) { //ダウンロード商品の場合 if ($item['down_filename'] == '') { $arrErr['down_filename'] = '※ ダウンロード商品の場合はダウンロードファイル名は必須です。'; } if ($item['down_realfilename'] == '') { $arrErr['down_realfilename'] = '※ ダウンロード商品の場合はダウンロード商品用ファイルアップロードは必須です。'; } } return $arrErr; }
/** * DBから商品データを取得する * * @param integer $product_id 商品ID * @return string 商品データ配列 */ public function lfGetProductData_FromDB($product_id) { $objQuery = Application::alias('eccube.query'); $arrProduct = array(); // 商品データ取得 $col = '*'; $table = <<<__EOF__ dtb_products AS T1 LEFT JOIN ( SELECT product_id AS product_id_sub, product_code, price01, price02, deliv_fee, stock, stock_unlimited, sale_limit, point_rate, product_type_id, down_filename, down_realfilename FROM dtb_products_class ) AS T2 ON T1.product_id = T2.product_id_sub __EOF__; $where = 'product_id = ?'; $objQuery->setLimit('1'); $arrProduct = $objQuery->select($col, $table, $where, array($product_id)); // カテゴリID取得 $col = 'category_id'; $table = 'dtb_product_categories'; $where = 'product_id = ?'; $objQuery->setOption(''); $arrProduct[0]['category_id'] = $objQuery->getCol($col, $table, $where, array($product_id)); // 規格情報ありなしフラグ取得 /* @var $objDb DbHelper */ $objDb = Application::alias('eccube.helper.db'); $arrProduct[0]['has_product_class'] = $objDb->hasProductClass($product_id); // 規格が登録されていなければ規格ID取得 if ($arrProduct[0]['has_product_class'] == false) { $arrProduct[0]['product_class_id'] = Utils::sfGetProductClassId($product_id, '0', '0'); } // 商品ステータス取得 /* @var $objProduct Product */ $objProduct = Application::alias('eccube.product'); $productStatus = $objProduct->getProductStatus(array($product_id)); $arrProduct[0]['product_status'] = $productStatus[$product_id]; // 関連商品データ取得 $arrRecommend = $this->lfGetRecommendProductsData_FromDB($product_id); $arrProduct[0] = array_merge($arrProduct[0], $arrRecommend); return $arrProduct[0]; }