Example #1
0
 /**
  * DBに商品データを登録する
  *
  * @param  UploadFile  $objUpFile   UploadFileインスタンス
  * @param  UploadFile  $objDownFile UploadFileインスタンス
  * @param  array   $arrList     フォーム入力パラメーター配列
  * @return integer 登録商品ID
  */
 public function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList)
 {
     $objQuery = Application::alias('eccube.query');
     /* @var $objDb DbHelper */
     $objDb = Application::alias('eccube.helper.db');
     // 配列の添字を定義
     $checkArray = array('name', 'status', 'main_list_comment', 'main_comment', 'deliv_fee', 'comment1', 'comment2', 'comment3', 'comment4', 'comment5', 'comment6', 'sale_limit', 'deliv_date_id', 'maker_id', 'note');
     $arrList = Utils::arrayDefineIndexes($arrList, $checkArray);
     // INSERTする値を作成する。
     $sqlval['name'] = $arrList['name'];
     $sqlval['status'] = $arrList['status'];
     $sqlval['main_list_comment'] = $arrList['main_list_comment'];
     $sqlval['main_comment'] = $arrList['main_comment'];
     $sqlval['comment1'] = $arrList['comment1'];
     $sqlval['comment2'] = $arrList['comment2'];
     $sqlval['comment3'] = $arrList['comment3'];
     $sqlval['comment4'] = $arrList['comment4'];
     $sqlval['comment5'] = $arrList['comment5'];
     $sqlval['comment6'] = $arrList['comment6'];
     $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
     $sqlval['maker_id'] = $arrList['maker_id'];
     $sqlval['note'] = $arrList['note'];
     $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
     $sqlval['creator_id'] = $_SESSION['member_id'];
     $arrRet = $objUpFile->getDBFileList();
     $sqlval = array_merge($sqlval, $arrRet);
     for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
         $sqlval['sub_title' . $cnt] = $arrList['sub_title' . $cnt];
         $sqlval['sub_comment' . $cnt] = $arrList['sub_comment' . $cnt];
     }
     $objQuery->begin();
     // 新規登録(複製時を含む)
     if ($arrList['product_id'] == '') {
         $product_id = $objQuery->nextVal('dtb_products_product_id');
         $sqlval['product_id'] = $product_id;
         // INSERTの実行
         $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
         $objQuery->insert('dtb_products', $sqlval);
         $arrList['product_id'] = $product_id;
         // カテゴリを更新
         $objDb->updateProductCategories($arrList['category_id'], $product_id);
         // 複製商品の場合には規格も複製する
         if ($arrList['copy_product_id'] != '' && Utils::sfIsInt($arrList['copy_product_id'])) {
             if (!$arrList['has_product_class']) {
                 //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
                 $this->lfCopyProductClass($arrList, $objQuery);
             } else {
                 //規格がある場合の複製は複製元の内容で追加登録を行う
                 // dtb_products_class のカラムを取得
                 /* @var $dbFactory DBFactory */
                 $dbFactory = Application::alias('eccube.db.factory');
                 $arrColList = $objQuery->listTableFields('dtb_products_class');
                 $arrColList_tmp = array_flip($arrColList);
                 // 複製しない列
                 unset($arrColList[$arrColList_tmp['product_class_id']]);
                 //規格ID
                 unset($arrColList[$arrColList_tmp['product_id']]);
                 //商品ID
                 unset($arrColList[$arrColList_tmp['create_date']]);
                 // 複製元商品の規格データ取得
                 $col = Utils::sfGetCommaList($arrColList);
                 $table = 'dtb_products_class';
                 $where = 'product_id = ?';
                 $objQuery->setOrder('product_class_id');
                 $arrProductsClass = $objQuery->select($col, $table, $where, array($arrList['copy_product_id']));
                 // 規格データ登録
                 $objQuery = Application::alias('eccube.query');
                 foreach ($arrProductsClass as $arrData) {
                     $sqlval = $arrData;
                     $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
                     $sqlval['deliv_fee'] = $arrList['deliv_fee'];
                     $sqlval['point_rate'] = $arrList['point_rate'];
                     $sqlval['sale_limit'] = $arrList['sale_limit'];
                     $sqlval['product_id'] = $product_id;
                     $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
                     $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
                     $objQuery->insert($table, $sqlval);
                 }
             }
         }
         // 更新
     } else {
         $product_id = $arrList['product_id'];
         // 削除要求のあった既存ファイルの削除
         $arrRet = $this->lfGetProductData_FromDB($arrList['product_id']);
         // TODO: UploadFile::deleteDBFileの画像削除条件見直し要
         $objImage = new Image($objUpFile->temp_dir);
         $arrKeyName = $objUpFile->keyname;
         $arrSaveFile = $objUpFile->save_file;
         $arrImageKey = array();
         foreach ($arrKeyName as $key => $keyname) {
             if ($arrRet[$keyname] && !$arrSaveFile[$key]) {
                 $arrImageKey[] = $keyname;
                 $has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]);
                 if (!$has_same_image) {
                     $objImage->deleteImage($arrRet[$keyname], $objUpFile->save_dir);
                 }
             }
         }
         $objDownFile->deleteDBDownFile($arrRet);
         // UPDATEの実行
         $where = 'product_id = ?';
         $objQuery->update('dtb_products', $sqlval, $where, array($product_id));
         // カテゴリを更新
         $objDb->updateProductCategories($arrList['category_id'], $product_id);
     }
     // 商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
     if ($arrList['copy_product_id'] == '') {
         // 規格登録
         if ($objDb->hasProductClass($product_id)) {
             // 規格あり商品(商品規格テーブルのうち、商品登録フォームで設定するパラメーターのみ更新)
             $this->lfUpdateProductClass($arrList);
         } else {
             // 規格なし商品(商品規格テーブルの更新)
             $arrList['product_class_id'] = $this->lfInsertDummyProductClass($arrList);
         }
     }
     // 商品ステータス設定
     /* @var $objProduct Product */
     $objProduct = Application::alias('eccube.product');
     $objProduct->setProductStatus($product_id, $arrList['product_status']);
     // 税情報設定
     if (OPTION_PRODUCT_TAX_RULE && !$objDb->hasProductClass($product_id)) {
         TaxRuleHelper::setTaxRuleForProduct($arrList['tax_rate'], $arrList['product_id'], $arrList['product_class_id']);
     }
     // 関連商品登録
     $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
     $objQuery->commit();
     return $product_id;
 }
Example #2
0
 /**
  * DBおよびファイルシステムにテンプレートパッケージを追加する.
  *
  * エラーが発生した場合は, エラーを出力し, false を返す.
  *
  * @param  FormParam  $objFormParam FormParamのインスタンス
  * @param  UploadFile  $objUpFile    UploadFileのインスタンス
  * @return boolean 成功した場合 true; 失敗した場合 false
  */
 public function doUpload($objFormParam, $objUpFile)
 {
     $template_code = $objFormParam->getValue('template_code');
     $template_name = $objFormParam->getValue('template_name');
     $device_type_id = $objFormParam->getValue('device_type_id');
     $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code;
     $compile_dir = DATA_REALDIR . 'Smarty/templates_c/' . $template_code;
     $objQuery = Application::alias('eccube.query');
     $objQuery->begin();
     $arrValues = array('template_code' => $template_code, 'device_type_id' => $device_type_id, 'template_name' => $template_name, 'create_date' => 'CURRENT_TIMESTAMP', 'update_date' => 'CURRENT_TIMESTAMP');
     $objQuery->insert('dtb_templates', $arrValues);
     // フォルダ作成
     if (!file_exists($template_dir)) {
         if (!mkdir($template_dir)) {
             $this->arrErr['err'] = '※ テンプレートフォルダが作成できませんでした。<br/>';
             $objQuery->rollback();
             return false;
         }
     }
     if (!file_exists($compile_dir)) {
         if (!mkdir($compile_dir)) {
             $this->arrErr['err'] = '※ Smarty コンパイルフォルダが作成できませんでした。<br/>';
             $objQuery->rollback();
             return false;
         }
     }
     // 一時フォルダから保存ディレクトリへ移動
     $objUpFile->moveTempFile();
     // 解凍
     if (!Application::alias('eccube.helper.file_manager')->unpackFile($template_dir . '/' . $_FILES['template_file']['name'])) {
         $this->arrErr['err'] = '※ テンプレートファイルの解凍に失敗しました。<br/>';
         $objQuery->rollback();
         return false;
     }
     // ユーザデータの下のファイルをコピーする
     $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . '/_packages/';
     $to_dir = USER_REALDIR . 'packages/' . $template_code . '/';
     if (!Utils::recursiveMkdir($to_dir)) {
         $this->arrErr['err'] = '※ ' . $to_dir . ' の作成に失敗しました。<br/>';
         $objQuery->rollback();
         return false;
     }
     Utils::sfCopyDir($from_dir, $to_dir);
     $objQuery->commit();
     return true;
 }
Example #3
0
 /**
  * ファイルの情報をセットする
  *
  * @param UploadFile $objUpFile
  * @param array $arrProduct
  * @param array $arrFile
  * @return bool
  */
 public function lfSetFile(UploadFile $objUpFile, $arrProduct, &$arrFile)
 {
     // DBからのデータを引き継ぐ
     $objUpFile->setDBFileList($arrProduct);
     // ファイル表示用配列を渡す
     $arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH, true);
     // サブ画像の有無を判定
     $subImageFlag = false;
     for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
         if (isset($arrFile['sub_image' . $i]['filepath']) && $arrFile['sub_image' . $i]['filepath'] != '') {
             $subImageFlag = true;
         }
     }
     return $subImageFlag;
 }
 /**
  * ファイル情報の初期化を行う.
  *
  * @param UploadFile $objUpFile
  * @return void
  */
 public function lfInitFile(UploadFile &$objUpFile)
 {
     $objUpFile->addFile('CSVファイル', 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false);
 }
Example #5
0
 /**
  * ファイルパラメーター初期化.
  *
  * @param  UploadFile $objUpFile UploadFileのインスタンス.
  * @param  string           $key       登録するキー.
  * @return void
  */
 public function initUploadFile(&$objUpFile, $key)
 {
     $objUpFile->addFile('プラグインファイル', $key, explode(',', PLUGIN_EXTENSION), FILE_SIZE, true, 0, 0, false);
 }