public function doAction($arrParam) { $this->doInitParam($arrParam); if ($this->isParamError()) { return false; } // メンバー情報を取得 $this->memberData = $this->getMemberData($arrParam['access_token']); // アップロードファイル情報の初期化 $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); $this->lfInitFile($objUpFile); $objUpFile->setHiddenFileList($_POST); // ファイルを一時ディレクトリにアップロード $arrImgKey = array('main_large_image'); for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { $arrImgKey[] = 'sub_large_image' . $cnt; } foreach ($arrImgKey as $val) { $this->arrErr[$val] = $objUpFile->makeTempFile($val, IMAGE_RENAME); if ($this->arrErr[$val] == '') { // 縮小画像作成 $this->lfSetScaleImage($objUpFile, $val); } } // DBへデータ登録 $product_id = $this->lfRegistProduct($objUpFile, $arrParam); // 件数カウントバッチ実行 $objQuery =& SC_Query_Ex::getSingletonInstance(); $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); $objDb->sfCountMaker($objQuery); // 一時ファイルを本番ディレクトリに移動する $this->lfSaveUploadFiles($objUpFile, $product_id); $arrData[] = array('result_id' => 1, 'product_id' => $product_id, 'error_msg' => ''); $this->setResponse('Item', $arrData); $this->setResponse('StatusCode', '0'); return true; }
/** * Page のアクション. * * @return void */ function action() { $objDb = new SC_Helper_DB_Ex(); $objFormParam = new SC_FormParam_Ex(); $objProduct = new SC_Product_Ex(); $objQuery =& SC_Query_Ex::getSingletonInstance(); // パラメーター情報の初期化 $this->lfInitParam($objFormParam); $objFormParam->setParam($_POST); $this->arrHidden = $objFormParam->getSearchArray(); $this->arrForm = $objFormParam->getFormParamList(); switch ($this->getMode()) { case 'delete': // 商品、子テーブル(商品規格)、会員お気に入り商品の削除 $this->doDelete('product_id = ?', array($objFormParam->getValue('product_id'))); // 件数カウントバッチ実行 $objDb->sfCountCategory($objQuery); $objDb->sfCountMaker($objQuery); // 削除後に検索結果を表示するため breakしない // 検索パラメーター生成後に処理実行するため breakしない // 削除後に検索結果を表示するため breakしない // 検索パラメーター生成後に処理実行するため breakしない case 'csv': case 'delete_all': case 'search': $objFormParam->convParam(); $objFormParam->trimParam(); $this->arrErr = $this->lfCheckError($objFormParam); $arrParam = $objFormParam->getHashArray(); if (count($this->arrErr) == 0) { $where = 'del_flg = 0'; $arrWhereVal = array(); foreach ($arrParam as $key => $val) { if ($val == '') { continue; } $this->buildQuery($key, $where, $arrWhereVal, $objFormParam, $objDb); } $order = 'update_date DESC'; /* ----------------------------------------------- * 処理を実行 * ----------------------------------------------- */ switch ($this->getMode()) { // CSVを送信する。 case 'csv': $objCSV = new SC_Helper_CSV_Ex(); // CSVを送信する。正常終了の場合、終了。 $objCSV->sfDownloadCsv(1, $where, $arrWhereVal, $order, true); SC_Response_Ex::actionExit(); // 全件削除(ADMIN_MODE) // 全件削除(ADMIN_MODE) case 'delete_all': $this->doDelete($where, $arrWhereVal); break; // 検索実行 // 検索実行 default: // 行数の取得 $this->tpl_linemax = $this->getNumberOfLines($where, $arrWhereVal); // ページ送りの処理 $page_max = SC_Utils_Ex::sfGetSearchPageMax($objFormParam->getValue('search_page_max')); // ページ送りの取得 $objNavi = new SC_PageNavi_Ex($this->arrHidden['search_pageno'], $this->tpl_linemax, $page_max, 'fnNaviSearchPage', NAVI_PMAX); $this->arrPagenavi = $objNavi->arrPagenavi; // 検索結果の取得 $this->arrProducts = $this->findProducts($where, $arrWhereVal, $page_max, $objNavi->start_row, $order, $objProduct); // 各商品ごとのカテゴリIDを取得 if (count($this->arrProducts) > 0) { foreach ($this->arrProducts as $key => $val) { $this->arrProducts[$key]['categories'] = $objDb->sfGetCategoryId($val['product_id'], 0, true); $objDb->g_category_on = false; } } } } break; } // カテゴリの読込 list($this->arrCatKey, $this->arrCatVal) = $objDb->sfGetLevelCatList(false); $this->arrCatList = $this->lfGetIDName($this->arrCatKey, $this->arrCatVal); }
function changeProductStatus(LC_Page $objPage) { $objQuery = SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $n = array(); $n2 = array("auto_display_status" => 0); $objSql = new SC_SelectSql_Ex(); $objSql->setWhere("auto_display_status = 1"); $objSql->setWhere("del_flg = 0"); $s = "auto_display_end_date"; $e = "auto_display_start_date"; // 公開日による状態変更 // {$s} > NOW() 公開開始前 // {$e} < NOW() 公開終了後 // その他 公開中 $objQuery->update("dtb_products", $n, $objSql->getWhere(), $n, array("status" => "CASE WHEN {$s} > NOW() THEN 2 WHEN {$e} < NOW() THEN 2 ELSE 1 END", "auto_display_status" => "CASE WHEN {$e} < NOW() THEN 0 ELSE 1 END")); $objSql->setWhere("{$e} < NOW() "); $objQuery->update("dtb_products", $n, $objSql->getWhere(), $n2); $objQuery->commit(); if (GC_Utils_Ex::isFrontFunction()) { // 商品数量を再計算 $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); $objDb->sfCountMaker($objQuery); } }
} $objData = new CreateEcCubeData(); $start = microtime(true); //$objData->objQuery->begin(); // カテゴリ生成 $objData->createCategories(); // 規格生成 $objData->createClassData(); // 商品生成 $objData->createProducts(); // 商品と規格の関連づけ $objData->relateClass(); // 商品とカテゴリの関連づけ $objData->relateProductsCategories(); $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory(NULL, true); //$objData->objQuery->rollback(); //$objData->objQuery->commit(); $end = microtime(true); print "データの生成が完了しました!\n"; printf("所要時間 %f 秒\n", $end - $start); // }}} // {{{ classes /** * EC-CUBE のデータを生成する */ class CreateEcCubeData { /** SC_Query インスタンス */ var $objQuery; /** 大カテゴリID の配列 */
/** * 規格の削除を実行する * * @param $product_id * @return void */ function doDelete($product_id) { $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); // 商品規格なしデータの復元 $where = 'product_id = ? AND classcategory_id1 = 0 AND classcategory_id2 = 0'; $objQuery->update('dtb_products_class', array('del_flg' => 0), $where, array($product_id)); // 商品規格データの削除 $where = 'product_id = ? AND (classcategory_id1 <> 0 OR classcategory_id2 <> 0)'; $objQuery->delete('dtb_products_class', $where, array($product_id)); $objQuery->commit(); // 在庫無し商品の非表示対応 if (NOSTOCK_HIDDEN) { // 件数カウントバッチ実行 $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); } }
/** * Page のアクション. * * @return void */ function action() { $objFormParam = new SC_FormParam_Ex(); // アップロードファイル情報の初期化 $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); $this->lfInitFile($objUpFile); $objUpFile->setHiddenFileList($_POST); // ダウンロード販売ファイル情報の初期化 $objDownFile = new SC_UploadFile_Ex(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR); $this->lfInitDownFile($objDownFile); $objDownFile->setHiddenFileList($_POST); // 検索パラメーター引き継ぎ $this->arrSearchHidden = $this->lfGetSearchParam($_POST); $mode = $this->getMode(); switch ($mode) { case 'pre_edit': case 'copy': // パラメーター初期化(商品ID) $this->lfInitFormParam_PreEdit($objFormParam, $_POST); // エラーチェック $this->arrErr = $objFormParam->checkError(); if (count($this->arrErr) > 0) { trigger_error('', E_USER_ERROR); } // 商品ID取得 $product_id = $objFormParam->getValue('product_id'); // 商品データ取得 $arrForm = $this->lfGetFormParam_PreEdit($objUpFile, $objDownFile, $product_id); // 複製の場合は、ダウンロード商品情報部分はコピーしない if ($mode == 'copy') { // ダウンロード商品ファイル名をunset $arrForm['down_filename'] = ''; // $objDownFile->setDBDownFile()でsetされたダウンロードファイル名をunset unset($objDownFile->save_file[0]); } // ページ表示用パラメーター設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // 商品複製の場合、画像ファイルコピー if ($mode == 'copy') { $this->arrForm['copy_product_id'] = $this->arrForm['product_id']; $this->arrForm['product_id'] = ''; // 画像ファイルのコピー $this->lfCopyProductImageFiles($objUpFile); } // ページonload時のJavaScript設定 $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); break; case 'edit': // パラメーター初期化, 取得 $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $objFormParam->getHashArray(); // エラーチェック $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm); if (count($this->arrErr) == 0) { // 確認画面表示設定 $this->tpl_mainpage = 'products/confirm.tpl'; $this->arrCatList = $this->lfGetCategoryList_Edit(); $this->arrForm = $this->lfSetViewParam_ConfirmPage($objUpFile, $objDownFile, $arrForm); } else { // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); } break; case 'complete': // パラメーター初期化, 取得 $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $this->lfGetFormParam_Complete($objFormParam); // エラーチェック $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm); if (count($this->arrErr) == 0) { // DBへデータ登録 $product_id = $this->lfRegistProduct($objUpFile, $objDownFile, $arrForm); // 件数カウントバッチ実行 $objQuery =& SC_Query_Ex::getSingletonInstance(); $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); $objDb->sfCountMaker($objQuery); // ダウンロード商品の複製時に、ダウンロード商品用ファイルを // 変更すると、複製元のファイルが削除されるのを回避。 if (!empty($arrForm['copy_product_id'])) { $objDownFile->save_file = array(); } // 一時ファイルを本番ディレクトリに移動する $this->lfSaveUploadFiles($objUpFile, $objDownFile, $product_id); $this->tpl_mainpage = 'products/complete.tpl'; $this->arrForm['product_id'] = $product_id; } else { // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); } break; // 画像のアップロード // 画像のアップロード case 'upload_image': case 'delete_image': // パラメーター初期化 $this->lfInitFormParam_UploadImage($objFormParam); $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $objFormParam->getHashArray(); switch ($mode) { case 'upload_image': // ファイルを一時ディレクトリにアップロード $this->arrErr[$arrForm['image_key']] = $objUpFile->makeTempFile($arrForm['image_key'], IMAGE_RENAME); if ($this->arrErr[$arrForm['image_key']] == '') { // 縮小画像作成 $this->lfSetScaleImage($objUpFile, $arrForm['image_key']); } break; case 'delete_image': // ファイル削除 $this->lfDeleteTempFile($objUpFile, $arrForm['image_key']); break; default: break; } // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $anchor_hash = $this->getAnchorHash($arrForm['image_key']); $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); break; // ダウンロード商品ファイルアップロード // ダウンロード商品ファイルアップロード case 'upload_down': case 'delete_down': // パラメーター初期化 $this->lfInitFormParam_UploadDown($objFormParam); $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $objFormParam->getHashArray(); switch ($mode) { case 'upload_down': // ファイルを一時ディレクトリにアップロード $this->arrErr[$arrForm['down_key']] = $objDownFile->makeTempDownFile(); break; case 'delete_down': // ファイル削除 $objDownFile->deleteFile($arrForm['down_key']); break; default: break; } // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $anchor_hash = $this->getAnchorHash($arrForm['down_key']); $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); break; // 関連商品選択 // 関連商品選択 case 'recommend_select': // パラメーター初期化 $this->lfInitFormParam_RecommendSelect($objFormParam); $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $objFormParam->getHashArray(); // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // 選択された関連商品IDがすでに登録している関連商品と重複していないかチェック $this->lfCheckError_RecommendSelect($this->arrForm, $this->arrErr); // ページonload時のJavaScript設定 $anchor_hash = $this->getAnchorHash($this->arrForm['anchor_key']); $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); break; // 確認ページからの戻り // 確認ページからの戻り case 'confirm_return': // パラメーター初期化 $this->lfInitFormParam($objFormParam, $_POST); $arrForm = $objFormParam->getHashArray(); // 入力画面表示設定 $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); break; default: // 入力画面表示設定 $arrForm = array(); $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); // ページonload時のJavaScript設定 $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); break; } // 関連商品の読み込み $this->arrRecommend = $this->lfGetRecommendProducts($this->arrForm); }
/** * CSVアップロードを実行する * * @param SC_FormParam $objFormParam * @param SC_UploadFile $objUpFile * @return void */ public function doUploadCsv(&$objFormParam, &$objUpFile) { // ファイルアップロードのチェック $objUpFile->makeTempFile('csv_file'); $arrErr = $objUpFile->checkExists(); if (count($arrErr) > 0) { $this->arrErr = $arrErr; return; } // 一時ファイル名の取得 $filepath = $objUpFile->getTempFilePath('csv_file'); // CSVファイルの文字コード変換 $enc_filepath = SC_Utils_Ex::sfEncodeFile($filepath, CHAR_CODE, CSV_TEMP_REALDIR); // CSVファイルのオープン $fp = fopen($enc_filepath, 'r'); // 失敗した場合はエラー表示 if (!$fp) { SC_Utils_Ex::sfDispError(''); } // 登録先テーブル カラム情報の初期化 $this->lfInitTableInfo(); // 登録フォーム カラム情報 $this->arrFormKeyList = $objFormParam->getKeyList(); // 登録対象の列数 $col_max_count = $objFormParam->getCount(); // 行数 $line_count = 0; $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $errFlag = false; while (!feof($fp)) { $arrCSV = fgetcsv($fp, CSV_LINE_MAX); // 行カウント $line_count++; // ヘッダ行はスキップ if ($line_count == 1) { continue; } // 空行はスキップ if (empty($arrCSV)) { continue; } // 列数が異なる場合はエラー $col_count = count($arrCSV); if ($col_max_count != $col_count) { $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。'); $errFlag = true; break; } // シーケンス配列を格納する。 $objFormParam->setParam($arrCSV, true); // 入力値の変換 $objFormParam->convParam(); // <br>なしでエラー取得する。 $arrCSVErr = $this->lfCheckError($objFormParam); // 入力エラーチェック if (count($arrCSVErr) > 0) { foreach ($arrCSVErr as $err) { $this->addRowErr($line_count, $err); } $errFlag = true; break; } $category_id = $this->lfRegistCategory($objQuery, $line_count, $objFormParam); $this->addRowResult($line_count, 'カテゴリID:' . $category_id . ' / カテゴリ名:' . $objFormParam->getValue('category_name')); } // 実行結果画面を表示 $this->tpl_mainpage = 'products/upload_csv_category_complete.tpl'; fclose($fp); if ($errFlag) { $objQuery->rollback(); return; } $objQuery->commit(); // カテゴリ件数を更新 $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); return; }
/** * 規格の削除を実行する * * @param $product_id * @return void */ function doDelete($product_id) { $objQuery =& SC_Query_Ex::getSingletonInstance(); $objQuery->begin(); $arrClassCombi = $objQuery->getCol('class_combination_id', 'dtb_products_class', 'product_id = ?', array($product_id)); foreach ($arrClassCombi as $class_combination_id) { if (SC_Utils_Ex::isBlank($class_combination_id)) { continue; } $existsCombi = $objQuery->getRow('*', 'dtb_class_combination', 'class_combination_id = ?', array($class_combination_id)); $objQuery->delete('dtb_class_combination', 'class_combination_id IN (?, ?)', array($existsCombi['class_combination_id'], $existsCombi['parent_class_combination_id'])); } $objQuery->update("dtb_products_class", array('del_flg' => 0), "product_id = ? AND class_combination_id IS NULL", array($product_id)); $objQuery->delete("dtb_products_class", "product_id = ? AND class_combination_id IS NOT NULL", array($product_id)); $objQuery->commit(); // 在庫無し商品の非表示対応 if (NOSTOCK_HIDDEN === true) { // 件数カウントバッチ実行 $objDb = new SC_Helper_DB_Ex(); $objDb->sfCountCategory($objQuery); } }