/** * CSVファイルを送信する * * @param integer $csv_id CSVフォーマットID * @param string $where WHERE条件文 * @param array $arrVal プリペアドステートメントの実行時に使用される配列。配列の要素数は、クエリ内のプレースホルダの数と同じでなければなりません。 * @param string $order ORDER文 * @param boolean $is_download true:ダウンロード用出力までさせる false:CSVの内容を返す(旧方式、メモリを食います。) * @return boolean|string $is_download = true時 成功失敗フラグ(boolean) 、$is_downalod = false時 string */ public function sfDownloadCsv($csv_id, $where = '', $arrVal = array(), $order = '', $is_download = false) { $objQuery = Application::alias('eccube.query'); // CSV出力タイトル行の作成 $arrOutput = Utils::sfSwapArray($this->sfGetCsvOutput($csv_id, 'status = ' . CSV_COLUMN_STATUS_FLG_ENABLE)); if (count($arrOutput) <= 0) { return false; } // 失敗終了 $arrOutputCols = $arrOutput['col']; $cols = Utils::sfGetCommaList($arrOutputCols, true); // 商品の場合 if ($csv_id == 1) { // この WHERE 句を足さないと無効な規格も出力される。現行仕様と合わせる為追加。 $inner_where = 'dtb_products_class.del_flg = 0'; $from = Application::alias('eccube.product')->prdclsSQL($inner_where); // 会員の場合 } elseif ($csv_id == 2) { $from = 'dtb_customer'; // 注文の場合 } elseif ($csv_id == 3) { $from = 'dtb_order'; // レビューの場合 } elseif ($csv_id == 4) { $from = 'dtb_review AS A INNER JOIN dtb_products AS B on A.product_id = B.product_id'; // カテゴリの場合 } elseif ($csv_id == 5) { $from = 'dtb_category'; } $objQuery->setOrder($order); $sql = $objQuery->getSql($cols, $from, $where); return $this->sfDownloadCsvFromSql($sql, $arrVal, $this->arrSubnavi[$csv_id], $arrOutput['disp_name'], $is_download); }
/** * 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; }
/** * 子孫カテゴリーの表示順を一括して下げる. * * @param Query $objQuery * @param int $category_id * @param int $count * @return array|bool */ private function reduceBranchRank(Query $objQuery, $category_id, $count) { $table = 'dtb_category'; /* @var $objDb DbHelper */ $objDb = Application::alias('eccube.helper.db'); // 子ID一覧を取得 $arrRet = $objDb->getChildrenArray($table, 'parent_category_id', 'category_id', $category_id); $line = Utils::sfGetCommaList($arrRet); $where = "category_id IN ({$line}) AND del_flg = 0"; $arrRawVal = array('rank' => "(rank - {$count})"); return $objQuery->update($table, array(), $where, array(), $arrRawVal); }
/** * WHERE文の作成 * * @param array $query フォームデータ * @return array WHERE文、判定値 */ private function makeWhere($query = array()) { //削除されていない商品を検索 $where = 'A.del_flg = 0 AND B.del_flg = 0'; $values = array(); foreach ($query as $key => $val) { if (empty($val)) { continue; } switch ($key) { case 'product_id': if (is_array($val)) { $where .= ' AND A.product_id IN (' . Utils::sfGetCommaList($val) . ')'; } else { $where .= ' AND A.product_id = ?'; $values[] = $val; } break; case 'review_id': if (is_array($val)) { $where .= ' AND review_id IN (' . Utils::sfGetCommaList($val) . ')'; } else { $where .= ' AND review_id = ?'; $values[] = $val; } break; case 'reviewer_name': $val = preg_replace('/ /', '%', $val); $where .= ' AND reviewer_name LIKE ? '; $values[] = "%{$val}%"; break; case 'reviewer_url': $val = preg_replace('/ /', '%', $val); $where .= ' AND reviewer_url LIKE ? '; $values[] = "%{$val}%"; break; case 'product_name': $val = preg_replace('/ /', '%', $val); $where .= ' AND name LIKE ? '; $values[] = "%{$val}%"; break; case 'product_code': $val = preg_replace('/ /', '%', $val); $where .= ' AND A.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ?)'; $values[] = "%{$val}%"; break; case 'reviewer_sex': $tmp_where = ''; //$val=配列の中身,$element=各キーの値(1,2) if (is_array($val)) { foreach ($val as $element) { if ($element != '') { if ($tmp_where == '') { $tmp_where .= ' AND (sex = ?'; } else { $tmp_where .= ' OR sex = ?'; } $values[] = $element; } } if ($tmp_where != '') { $tmp_where .= ')'; $where .= " {$tmp_where} "; } } break; case 'recommend_level': $where .= ' AND recommend_level = ? '; $values[] = $val; break; case 'date_from': $where .= ' AND A.create_date >= ? '; $values[] = $val; break; case 'date_to': $where .= " AND A.create_date <= cast( ? as date) "; $values[] = $val; break; default: break; } } return array($where, $values); }
/** * @param Query $objQuery * @param string $table * @param string $pid_name * @param string $id_name * @param integer $count */ public function lfDownRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { /* @var $objDb DbHelper */ $objDb = Application::alias('eccube.helper.db'); // 子ID一覧を取得 $arrRet = $objDb->getChildrenArray($table, $pid_name, $id_name, $id); $line = Utils::sfGetCommaList($arrRet); $where = "{$id_name} IN ({$line}) AND del_flg = 0"; $arrRawVal = array('rank' => "(rank - {$count})"); return $objQuery->update($table, array(), $where, array(), $arrRawVal); }