1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | // {{{ requires |
---|
25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * 商品登録 のページクラス |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Products_Product extends LC_Page_Admin { |
---|
35 | |
---|
36 | // {{{ properties |
---|
37 | |
---|
38 | /** ファイル管理クラスのインスタンス */ |
---|
39 | var $objUpFile; |
---|
40 | |
---|
41 | /** ダウンロード用ファイル管理クラスのインスタンス */ |
---|
42 | var $objDownFile; |
---|
43 | |
---|
44 | /** hidden 項目の配列 */ |
---|
45 | var $arrHidden; |
---|
46 | |
---|
47 | /** エラー情報 */ |
---|
48 | var $arrErr; |
---|
49 | |
---|
50 | // }}} |
---|
51 | // {{{ functions |
---|
52 | |
---|
53 | /** |
---|
54 | * Page を初期化する. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function init() { |
---|
59 | parent::init(); |
---|
60 | $this->tpl_mainpage = 'products/product.tpl'; |
---|
61 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
62 | $this->tpl_mainno = 'products'; |
---|
63 | $this->tpl_subno = 'product'; |
---|
64 | $this->tpl_subtitle = '商品登録'; |
---|
65 | $this->arrErr = array(); |
---|
66 | |
---|
67 | $masterData = new SC_DB_MasterData_Ex(); |
---|
68 | $this->arrDISP = $masterData->getMasterData("mtb_disp"); |
---|
69 | $this->arrCLASS = $masterData->getMasterData("mtb_class"); |
---|
70 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
71 | $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); |
---|
72 | $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); |
---|
73 | $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag"); |
---|
74 | $this->arrProductType = $masterData->getMasterData("mtb_product_type"); |
---|
75 | $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList("dtb_maker", "maker_id", "name"); |
---|
76 | $this->tpl_nonclass = true; |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * Page のプロセス. |
---|
81 | * |
---|
82 | * @return void |
---|
83 | */ |
---|
84 | function process() { |
---|
85 | $this->action(); |
---|
86 | $this->sendResponse(); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * Page のアクション. |
---|
91 | * |
---|
92 | * @return void |
---|
93 | */ |
---|
94 | function action() { |
---|
95 | $objSiteInfo = new SC_SiteInfo(); |
---|
96 | $objQuery = new SC_Query(); |
---|
97 | $objDb = new SC_Helper_DB_Ex(); |
---|
98 | $objProduct = new SC_Product(); |
---|
99 | |
---|
100 | // 認証可否の判定 |
---|
101 | $objSess = new SC_Session(); |
---|
102 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
103 | |
---|
104 | // Downファイル管理クラス |
---|
105 | $this->objDownFile = new SC_UploadFile(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR); |
---|
106 | // Downファイル情報の初期化 |
---|
107 | $this->lfInitDownFile(); |
---|
108 | // Hiddenからのデータを引き継ぐ |
---|
109 | $this->objDownFile->setHiddenFileList($_POST); |
---|
110 | |
---|
111 | // ファイル管理クラス |
---|
112 | $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
113 | |
---|
114 | // ファイル情報の初期化 |
---|
115 | $this->lfInitFile(); |
---|
116 | // Hiddenからのデータを引き継ぐ |
---|
117 | $this->objUpFile->setHiddenFileList($_POST); |
---|
118 | |
---|
119 | // 規格の有り無し判定 |
---|
120 | $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['product_id']); |
---|
121 | |
---|
122 | // 検索パラメータの引き継ぎ |
---|
123 | foreach ($_POST as $key => $val) { |
---|
124 | if (ereg("^search_", $key)) { |
---|
125 | $this->arrSearchHidden[$key] = $val; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | // FORMデータの引き継ぎ |
---|
130 | $this->arrForm = $_POST; |
---|
131 | |
---|
132 | switch($this->getMode()) { |
---|
133 | // 検索画面からの編集 |
---|
134 | case 'pre_edit': |
---|
135 | case 'copy' : |
---|
136 | if (!SC_Utils_Ex::sfIsInt($_POST['product_id'])) { |
---|
137 | SC_Utils_Ex::sfDispException(); |
---|
138 | } |
---|
139 | |
---|
140 | // DBから商品情報の読込 |
---|
141 | $this->arrForm = $this->lfGetProduct($_POST['product_id']); |
---|
142 | $productStatus= $objProduct->getProductStatus(array($_POST['product_id'])); |
---|
143 | $this->arrForm['product_status'] = $productStatus[$_POST['product_id']]; |
---|
144 | |
---|
145 | // DBデータから画像ファイル名の読込 |
---|
146 | $this->objUpFile->setDBFileList($this->arrForm); |
---|
147 | // DBデータからダウンロードファイル名の読込 |
---|
148 | $this->objDownFile->setDBDownFile($this->arrForm); |
---|
149 | |
---|
150 | // 商品ステータスの変換 |
---|
151 | $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag"); |
---|
152 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
153 | // DBから関連商品の読み込み |
---|
154 | $this->lfPreGetRecommendProducts($_POST['product_id']); |
---|
155 | |
---|
156 | $this->lfProductPage(); // 商品登録ページ |
---|
157 | //TODO 要リファクタリング(MODE if利用) |
---|
158 | if($this->getMode() == "copy"){ |
---|
159 | $this->arrForm["copy_product_id"] = $this->arrForm["product_id"]; |
---|
160 | $this->arrForm["product_id"] = ""; |
---|
161 | // 画像ファイルのコピー |
---|
162 | $arrKey = $this->objUpFile->keyname; |
---|
163 | $arrSaveFile = $this->objUpFile->save_file; |
---|
164 | |
---|
165 | foreach($arrSaveFile as $key => $val){ |
---|
166 | $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true); |
---|
167 | } |
---|
168 | } |
---|
169 | break; |
---|
170 | // 商品登録・編集 |
---|
171 | case 'edit': |
---|
172 | if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){ |
---|
173 | $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['copy_product_id']); |
---|
174 | } |
---|
175 | |
---|
176 | // 入力値の変換 |
---|
177 | $this->arrForm = $this->lfConvertParam($this->arrForm); |
---|
178 | // エラーチェック |
---|
179 | $this->arrErr = $this->lfErrorCheck($this->arrForm); |
---|
180 | // ファイル存在チェック |
---|
181 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS()); |
---|
182 | // エラーなしの場合 |
---|
183 | if(count($this->arrErr) == 0) { |
---|
184 | $this->lfProductConfirmPage(); // 確認ページ |
---|
185 | } else { |
---|
186 | $this->lfProductPage(); // 商品登録ページ |
---|
187 | } |
---|
188 | break; |
---|
189 | // 確認ページから完了ページへ |
---|
190 | case 'complete': |
---|
191 | $this->tpl_mainpage = 'products/complete.tpl'; |
---|
192 | |
---|
193 | $this->arrForm['product_id'] = $this->lfRegistProduct($_POST); // データ登録 |
---|
194 | |
---|
195 | // 件数カウントバッチ実行 |
---|
196 | $objDb->sfCountCategory($objQuery); |
---|
197 | $objDb->sfCountMaker($objQuery); |
---|
198 | // 一時ファイルを本番ディレクトリに移動する |
---|
199 | // TODO: SC_UploadFile::moveTempFileの画像削除条件見直し要 |
---|
200 | $objImage = new SC_Image($this->objUpFile->temp_dir); |
---|
201 | $arrKeyName = $this->objUpFile->keyname; |
---|
202 | $arrTempFile = $this->objUpFile->temp_file; |
---|
203 | $arrSaveFile = $this->objUpFile->save_file; |
---|
204 | $arrImageKey = array(); |
---|
205 | foreach ($arrTempFile as $key => $temp_file) { |
---|
206 | if ($temp_file) { |
---|
207 | $objImage->moveTempImage($temp_file, $this->objUpFile->save_dir); |
---|
208 | $arrImageKey[] = $arrKeyName[$key]; |
---|
209 | if (!empty($arrSaveFile[$key]) && !$this->lfHasSameProductImage($this->arrForm['product_id'], $arrImageKey, $arrSaveFile[$key]) && !in_array($temp_file, $arrSaveFile)) { |
---|
210 | $objImage->deleteImage($arrSaveFile[$key], $this->objUpFile->save_dir); |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | $this->objDownFile->moveTempDownFile(); |
---|
215 | |
---|
216 | break; |
---|
217 | // 画像のアップロード |
---|
218 | case 'upload_image': |
---|
219 | // ファイル存在チェック |
---|
220 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key'])); |
---|
221 | // 画像保存処理 |
---|
222 | $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key'],IMAGE_RENAME); |
---|
223 | |
---|
224 | // 中、小画像生成 |
---|
225 | $this->lfSetScaleImage(); |
---|
226 | |
---|
227 | $this->lfProductPage(); // 商品登録ページ |
---|
228 | break; |
---|
229 | // 画像の削除 |
---|
230 | case 'delete_image': |
---|
231 | // TODO: SC_UploadFile::deleteFileの画像削除条件見直し要 |
---|
232 | $arrTempFile = $this->objUpFile->temp_file; |
---|
233 | $arrKeyName = $this->objUpFile->keyname; |
---|
234 | foreach ($arrKeyName as $key => $keyname) { |
---|
235 | if ($keyname != $_POST['image_key']) continue; |
---|
236 | if (!empty($arrTempFile[$key])) { |
---|
237 | $temp_file = $arrTempFile[$key]; |
---|
238 | $arrTempFile[$key] = ''; |
---|
239 | if (!in_array($temp_file, $arrTempFile)) { |
---|
240 | $this->objUpFile->deleteFile($_POST['image_key']); |
---|
241 | } else { |
---|
242 | $this->objUpFile->temp_file[$key] = ''; |
---|
243 | $this->objUpFile->save_file[$key] = ''; |
---|
244 | } |
---|
245 | } else { |
---|
246 | $this->objUpFile->temp_file[$key] = ''; |
---|
247 | $this->objUpFile->save_file[$key] = ''; |
---|
248 | } |
---|
249 | } |
---|
250 | $this->lfProductPage(); // 商品登録ページ |
---|
251 | break; |
---|
252 | // ダウンロード商品ファイルアップロード |
---|
253 | case 'upload_down': |
---|
254 | // ファイル存在チェック |
---|
255 | $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objDownFile->checkEXISTS($_POST['down_key'])); |
---|
256 | // 画像保存処理 |
---|
257 | $this->arrErr[$_POST['down_key']] = $this->objDownFile->makeTempDownFile(); |
---|
258 | |
---|
259 | $this->lfProductPage(); // 商品登録ページ |
---|
260 | break; |
---|
261 | // ダウンロードファイルの削除 |
---|
262 | case 'delete_down': |
---|
263 | $this->objDownFile->deleteFile($_POST['down_key']); |
---|
264 | $this->lfProductPage(); // 商品登録ページ |
---|
265 | break; |
---|
266 | // 確認ページからの戻り |
---|
267 | case 'confirm_return': |
---|
268 | $this->lfProductPage(); // 商品登録ページ |
---|
269 | break; |
---|
270 | // 関連商品選択 |
---|
271 | case 'recommend_select' : |
---|
272 | $this->lfProductPage(); // 商品登録ページ |
---|
273 | break; |
---|
274 | default: |
---|
275 | $this->lfProductPage(); // 商品登録ページ |
---|
276 | break; |
---|
277 | } |
---|
278 | |
---|
279 | // 関連商品の読み込み |
---|
280 | $this->arrRecommend = $this->lfGetRecommendProducts(); |
---|
281 | |
---|
282 | // 基本情報を渡す |
---|
283 | $this->arrInfo = $objSiteInfo->data; |
---|
284 | |
---|
285 | // サブ情報の入力があるかどうかチェックする |
---|
286 | $sub_find = false; |
---|
287 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
288 | if( (isset($this->arrForm['sub_title'.$cnt]) |
---|
289 | && !empty($this->arrForm['sub_title'.$cnt])) || |
---|
290 | (isset($this->arrForm['sub_comment'.$cnt]) |
---|
291 | && !empty($this->arrForm['sub_comment'.$cnt])) || |
---|
292 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
293 | && !empty($this->arrForm['sub_image'.$cnt])) || |
---|
294 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
295 | && !empty($this->arrForm['sub_large_image'.$cnt])) || |
---|
296 | (isset($this->arrForm['sub_image'.$cnt]) |
---|
297 | && is_array($this->arrFile['sub_image'.$cnt])) || |
---|
298 | (isset($this->arrForm['sub_large_image'.$cnt]) |
---|
299 | && is_array($this->arrFile['sub_large_image'.$cnt]))) { |
---|
300 | $sub_find = true; |
---|
301 | break; |
---|
302 | } |
---|
303 | } |
---|
304 | |
---|
305 | // サブ情報表示・非表示のチェックに使用する。 |
---|
306 | $this->sub_find = $sub_find; |
---|
307 | } |
---|
308 | |
---|
309 | /** |
---|
310 | * デストラクタ. |
---|
311 | * |
---|
312 | * @return void |
---|
313 | */ |
---|
314 | function destroy() { |
---|
315 | parent::destroy(); |
---|
316 | } |
---|
317 | |
---|
318 | /** |
---|
319 | * 関連商品の名称などを商品マスタから読み込み、一つの配列にまとめて返す |
---|
320 | * |
---|
321 | * @return array 関連商品の情報を格納した2次元配列 |
---|
322 | */ |
---|
323 | function lfGetRecommendProducts() { |
---|
324 | $objQuery = new SC_Query(); |
---|
325 | $arrRecommend = array(); |
---|
326 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
327 | $keyname = "recommend_id" . $i; |
---|
328 | $delkey = "recommend_delete" . $i; |
---|
329 | $commentkey = "recommend_comment" . $i; |
---|
330 | |
---|
331 | if (!isset($this->arrForm[$delkey])) $this->arrForm[$delkey] = null; |
---|
332 | |
---|
333 | if((isset($this->arrForm[$keyname]) && !empty($this->arrForm[$keyname])) && $this->arrForm[$delkey] != 1) { |
---|
334 | $objProduct = new SC_Product(); |
---|
335 | $arrRecommend[$i] = $objProduct->getDetail($this->arrForm[$keyname]); |
---|
336 | $arrRecommend[$i]['product_id'] = $this->arrForm[$keyname]; |
---|
337 | $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey]; |
---|
338 | } |
---|
339 | } |
---|
340 | return $arrRecommend; |
---|
341 | } |
---|
342 | |
---|
343 | /* 関連商品の登録 */ |
---|
344 | function lfInsertRecommendProducts($objQuery, $arrList, $product_id) { |
---|
345 | // 一旦関連商品をすべて削除する |
---|
346 | $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
347 | $sqlval['product_id'] = $product_id; |
---|
348 | $rank = RECOMMEND_PRODUCT_MAX; |
---|
349 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
350 | $keyname = "recommend_id" . $i; |
---|
351 | $commentkey = "recommend_comment" . $i; |
---|
352 | $deletekey = "recommend_delete" . $i; |
---|
353 | |
---|
354 | if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null; |
---|
355 | |
---|
356 | if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') { |
---|
357 | $sqlval['recommend_product_id'] = $arrList[$keyname]; |
---|
358 | $sqlval['comment'] = $arrList[$commentkey]; |
---|
359 | $sqlval['rank'] = $rank; |
---|
360 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
361 | $sqlval['create_date'] = "now()"; |
---|
362 | $sqlval['update_date'] = "now()"; |
---|
363 | $objQuery->insert("dtb_recommend_products", $sqlval); |
---|
364 | $rank--; |
---|
365 | } |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | /** |
---|
370 | * 指定商品の関連商品をDBから読み込む |
---|
371 | * |
---|
372 | * @param string $product_id 商品ID |
---|
373 | * @return void |
---|
374 | */ |
---|
375 | function lfPreGetRecommendProducts($product_id) { |
---|
376 | $objQuery = new SC_Query(); |
---|
377 | $objQuery->setOrder("rank DESC"); |
---|
378 | $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
379 | $no = 1; |
---|
380 | |
---|
381 | foreach ($arrRet as $ret) { |
---|
382 | $this->arrForm['recommend_id' . $no] = $ret['recommend_product_id']; |
---|
383 | $this->arrForm['recommend_comment' . $no] = $ret['comment']; |
---|
384 | $no++; |
---|
385 | } |
---|
386 | } |
---|
387 | |
---|
388 | /* 商品情報の読み込み */ |
---|
389 | function lfGetProduct($product_id) { |
---|
390 | $objQuery = new SC_Query(); |
---|
391 | $objDb = new SC_Helper_DB_Ex(); |
---|
392 | |
---|
393 | $col = "*"; |
---|
394 | $table = <<< __EOF__ |
---|
395 | dtb_products AS T1 |
---|
396 | LEFT JOIN ( |
---|
397 | SELECT product_id AS product_id_sub, |
---|
398 | product_code, |
---|
399 | price01, |
---|
400 | price02, |
---|
401 | stock, |
---|
402 | stock_unlimited, |
---|
403 | sale_limit, |
---|
404 | point_rate, |
---|
405 | product_type_id, |
---|
406 | down_filename, |
---|
407 | down_realfilename |
---|
408 | FROM dtb_products_class |
---|
409 | WHERE class_combination_id IS NULL |
---|
410 | ) AS T2 |
---|
411 | ON T1.product_id = T2.product_id_sub |
---|
412 | __EOF__; |
---|
413 | $where = "product_id = ?"; |
---|
414 | |
---|
415 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
416 | |
---|
417 | // カテゴリID を取得 |
---|
418 | $arrRet[0]['category_id'] = $objQuery->getCol( |
---|
419 | "category_id", |
---|
420 | "dtb_product_categories", |
---|
421 | "product_id = ?", |
---|
422 | array($product_id) |
---|
423 | ); |
---|
424 | //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する |
---|
425 | if (!$objDb->sfHasProductClass($_POST['product_id'])) { |
---|
426 | $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0"); |
---|
427 | } |
---|
428 | return $arrRet[0]; |
---|
429 | } |
---|
430 | |
---|
431 | /* 商品登録ページ表示用 */ |
---|
432 | function lfProductPage() { |
---|
433 | $objDb = new SC_Helper_DB_Ex(); |
---|
434 | |
---|
435 | // カテゴリの読込 |
---|
436 | list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
437 | |
---|
438 | if (isset($this->arrForm['category_id']) && !is_array($this->arrForm['category_id'])) { |
---|
439 | $this->arrForm['category_id'] = unserialize($this->arrForm['category_id']); |
---|
440 | } |
---|
441 | if($this->arrForm['status'] == "") { |
---|
442 | $this->arrForm['status'] = DEFAULT_PRODUCT_DISP; |
---|
443 | } |
---|
444 | if($this->arrForm['product_type_id'] == "") { |
---|
445 | $this->arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN; |
---|
446 | } |
---|
447 | |
---|
448 | // HIDDEN用に配列を渡す。 |
---|
449 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList()); |
---|
450 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objDownFile->getHiddenFileList()); |
---|
451 | // Form用配列を渡す。 |
---|
452 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
453 | |
---|
454 | $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile(); |
---|
455 | |
---|
456 | // アンカーを設定 |
---|
457 | if (isset($_POST['image_key']) && !empty($_POST['image_key'])) { |
---|
458 | $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'"; |
---|
459 | } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
460 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
461 | } else { |
---|
462 | $anchor_hash = ""; |
---|
463 | } |
---|
464 | |
---|
465 | $this->tpl_onload = "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash; |
---|
466 | } |
---|
467 | |
---|
468 | /* ファイル情報の初期化 */ |
---|
469 | function lfInitFile() { |
---|
470 | $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
---|
471 | $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT); |
---|
472 | $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
---|
473 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
474 | $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT); |
---|
475 | $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT); |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | /* 商品の登録 */ |
---|
480 | function lfRegistProduct($arrList) { |
---|
481 | $objQuery = new SC_Query(); |
---|
482 | $objDb = new SC_Helper_DB_Ex(); |
---|
483 | $objQuery->begin(); |
---|
484 | |
---|
485 | // 配列の添字を定義 |
---|
486 | $checkArray = array("name", "status", |
---|
487 | "main_list_comment", "main_comment", |
---|
488 | "deliv_fee", "comment1", "comment2", "comment3", |
---|
489 | "comment4", "comment5", "comment6", "main_list_comment", |
---|
490 | "sale_limit", "deliv_date_id", "maker_id", "note"); |
---|
491 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
---|
492 | |
---|
493 | // INSERTする値を作成する。 |
---|
494 | $sqlval['name'] = $arrList['name']; |
---|
495 | $sqlval['status'] = $arrList['status']; |
---|
496 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
497 | $sqlval['main_comment'] = $arrList['main_comment']; |
---|
498 | $sqlval['comment1'] = $arrList['comment1']; |
---|
499 | $sqlval['comment2'] = $arrList['comment2']; |
---|
500 | $sqlval['comment3'] = $arrList['comment3']; |
---|
501 | $sqlval['comment4'] = $arrList['comment4']; |
---|
502 | $sqlval['comment5'] = $arrList['comment5']; |
---|
503 | $sqlval['comment6'] = $arrList['comment6']; |
---|
504 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
505 | $sqlval['deliv_date_id'] = $arrList['deliv_date_id']; |
---|
506 | $sqlval['maker_id'] = $arrList['maker_id']; |
---|
507 | $sqlval['note'] = $arrList['note']; |
---|
508 | $sqlval['update_date'] = "Now()"; |
---|
509 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
510 | $arrRet = $this->objUpFile->getDBFileList(); |
---|
511 | $sqlval = array_merge($sqlval, $arrRet); |
---|
512 | |
---|
513 | $arrList['category_id'] = unserialize($arrList['category_id']); |
---|
514 | |
---|
515 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
516 | $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt]; |
---|
517 | $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt]; |
---|
518 | } |
---|
519 | |
---|
520 | // 新規登録(複製時を含む) |
---|
521 | if ($arrList['product_id'] == "") { |
---|
522 | $product_id = $objQuery->nextVal("dtb_products_product_id"); |
---|
523 | $sqlval['product_id'] = $product_id; |
---|
524 | |
---|
525 | // INSERTの実行 |
---|
526 | $sqlval['create_date'] = "Now()"; |
---|
527 | $objQuery->insert("dtb_products", $sqlval); |
---|
528 | |
---|
529 | $arrList['product_id'] = $product_id; |
---|
530 | |
---|
531 | // カテゴリを更新 |
---|
532 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
533 | |
---|
534 | // 複製商品の場合には規格も複製する |
---|
535 | if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){ |
---|
536 | |
---|
537 | if($this->tpl_nonclass) |
---|
538 | { |
---|
539 | //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う |
---|
540 | $this->lfCopyProductClass($arrList, $objQuery); |
---|
541 | } |
---|
542 | else |
---|
543 | { |
---|
544 | //規格がある場合の複製は複製元の内容で追加登録を行う |
---|
545 | // dtb_products_class のカラムを取得 |
---|
546 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
547 | $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery); |
---|
548 | $arrColList_tmp = array_flip($arrColList); |
---|
549 | |
---|
550 | // 複製しない列 |
---|
551 | unset($arrColList[$arrColList_tmp["product_class_id"]]); //規格ID |
---|
552 | unset($arrColList[$arrColList_tmp["product_id"]]); //商品ID |
---|
553 | unset($arrColList[$arrColList_tmp["create_date"]]); |
---|
554 | |
---|
555 | $col = SC_Utils_Ex::sfGetCommaList($arrColList); |
---|
556 | $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
557 | $objQuery->query("INSERT INTO dtb_products_class (product_class_id, product_id, create_date, ". $col .") SELECT ?, now(), " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_class_id, $product_id, $_POST["copy_product_id"])); |
---|
558 | } |
---|
559 | } |
---|
560 | } |
---|
561 | // 更新 |
---|
562 | else { |
---|
563 | $product_id = $arrList['product_id']; |
---|
564 | // 削除要求のあった既存ファイルの削除 |
---|
565 | $arrRet = $this->lfGetProduct($arrList['product_id']); |
---|
566 | // TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要 |
---|
567 | $objImage = new SC_Image($this->objUpFile->temp_dir); |
---|
568 | $arrKeyName = $this->objUpFile->keyname; |
---|
569 | $arrSaveFile = $this->objUpFile->save_file; |
---|
570 | $arrImageKey = array(); |
---|
571 | foreach ($arrKeyName as $key => $keyname) { |
---|
572 | if ($arrRet[$keyname] && !$arrSaveFile[$key]) { |
---|
573 | $arrImageKey[] = $keyname; |
---|
574 | $has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]); |
---|
575 | if (!$has_same_image) { |
---|
576 | $objImage->deleteImage($arrRet[$keyname], $this->objUpFile->save_dir); |
---|
577 | } |
---|
578 | } |
---|
579 | } |
---|
580 | $this->objDownFile->deleteDBDownFile($arrRet); |
---|
581 | |
---|
582 | // UPDATEの実行 |
---|
583 | $where = "product_id = ?"; |
---|
584 | $objQuery->update("dtb_products", $sqlval, $where, array($product_id)); |
---|
585 | |
---|
586 | // カテゴリを更新 |
---|
587 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
588 | } |
---|
589 | |
---|
590 | //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。 |
---|
591 | if( $_POST["copy_product_id"] == "" ){ |
---|
592 | // 規格登録 |
---|
593 | $this->lfInsertDummyProductClass($arrList); |
---|
594 | } |
---|
595 | |
---|
596 | // ステータス設定 |
---|
597 | $objProduct = new SC_Product(); |
---|
598 | $objProduct->setProductStatus($product_id, $arrList['product_status']); |
---|
599 | |
---|
600 | // 関連商品登録 |
---|
601 | $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id); |
---|
602 | |
---|
603 | $objQuery->commit(); |
---|
604 | return $product_id; |
---|
605 | } |
---|
606 | |
---|
607 | |
---|
608 | /* 取得文字列の変換 */ |
---|
609 | function lfConvertParam($array) { |
---|
610 | /* |
---|
611 | * 文字列の変換 |
---|
612 | * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 |
---|
613 | * C : 「全角ひら仮名」を「全角かた仮名」に変換 |
---|
614 | * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します |
---|
615 | * n : 「全角」数字を「半角(ハンカク)」に変換 |
---|
616 | */ |
---|
617 | |
---|
618 | // スポット商品 |
---|
619 | $arrConvList['name'] = "KVa"; |
---|
620 | $arrConvList['main_list_comment'] = "KVa"; |
---|
621 | $arrConvList['main_comment'] = "KVa"; |
---|
622 | $arrConvList['price01'] = "n"; |
---|
623 | $arrConvList['price02'] = "n"; |
---|
624 | $arrConvList['stock'] = "n"; |
---|
625 | $arrConvList['sale_limit'] = "n"; |
---|
626 | $arrConvList['point_rate'] = "n"; |
---|
627 | $arrConvList['product_code'] = "KVna"; |
---|
628 | $arrConvList['comment1'] = "a"; |
---|
629 | $arrConvList['deliv_fee'] = "n"; |
---|
630 | |
---|
631 | // 詳細-サブ |
---|
632 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
633 | $arrConvList["sub_title$cnt"] = "KVa"; |
---|
634 | } |
---|
635 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
636 | $arrConvList["sub_comment$cnt"] = "KVa"; |
---|
637 | } |
---|
638 | |
---|
639 | // 関連商品 |
---|
640 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
641 | $arrConvList["recommend_comment$cnt"] = "KVa"; |
---|
642 | } |
---|
643 | |
---|
644 | // 文字変換 |
---|
645 | foreach ($arrConvList as $key => $val) { |
---|
646 | // POSTされてきた値のみ変換する。 |
---|
647 | if(isset($array[$key])) { |
---|
648 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
649 | } |
---|
650 | } |
---|
651 | |
---|
652 | if (!isset($array['product_flag'])) $array['product_flag'] = ""; |
---|
653 | $max = max(array_keys($this->arrSTATUS)); |
---|
654 | $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], $max); |
---|
655 | |
---|
656 | return $array; |
---|
657 | } |
---|
658 | |
---|
659 | // 入力エラーチェック |
---|
660 | function lfErrorCheck($array) { |
---|
661 | |
---|
662 | $objErr = new SC_CheckError($array); |
---|
663 | $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
664 | $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
665 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
666 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
667 | $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
668 | $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
669 | $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
670 | $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
671 | $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK")); |
---|
672 | $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK")); |
---|
673 | $objErr->doFunc(array("メーカー", 'maker_id', INT_LEN), array("NUM_CHECK")); |
---|
674 | |
---|
675 | if($this->tpl_nonclass) { |
---|
676 | $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
677 | $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01", PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
678 | $objErr->doFunc(array(SALE_PRICE_TITLE, "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
679 | |
---|
680 | if(!isset($array['stock_unlimited']) && $array['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) { |
---|
681 | $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
682 | } |
---|
683 | |
---|
684 | //ダウンロード商品チェック |
---|
685 | if($array['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) { |
---|
686 | $objErr->doFunc(array("ダウンロードファイル名", "down_filename", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
687 | if($array['down_realfilename'] == "") { |
---|
688 | $objErr->arrErr['down_realfilename'] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />"; |
---|
689 | } |
---|
690 | } |
---|
691 | //実商品チェック |
---|
692 | if($array['product_type_id'] == PRODUCT_TYPE_NORMAL) { |
---|
693 | if($array['down_filename'] != "") { |
---|
694 | $objErr->arrErr['down_filename'] = "※ 通常商品の場合はダウンロードファイル名を設定できません。<br />"; |
---|
695 | } |
---|
696 | if($array['down_realfilename'] != "") { |
---|
697 | $objErr->arrErr['down_realfilename'] = "※ 通常商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />"; |
---|
698 | } |
---|
699 | } |
---|
700 | } |
---|
701 | |
---|
702 | $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
703 | |
---|
704 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
705 | $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
706 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
707 | $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
708 | } |
---|
709 | |
---|
710 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
711 | |
---|
712 | if (!isset($_POST["recommend_delete$cnt"])) $_POST["recommend_delete$cnt"] = ""; |
---|
713 | |
---|
714 | if(isset($_POST["recommend_id$cnt"]) |
---|
715 | && $_POST["recommend_id$cnt"] != "" |
---|
716 | && $_POST["recommend_delete$cnt"] != 1) { |
---|
717 | $objErr->doFunc(array("関連商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
718 | } |
---|
719 | } |
---|
720 | |
---|
721 | // カテゴリID のチェック |
---|
722 | if (empty($array['category_id'])) { |
---|
723 | $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />"; |
---|
724 | } else { |
---|
725 | $arrCategory_id = array(); |
---|
726 | for ($i = 0; $i < count($array['category_id']); $i++) { |
---|
727 | $arrCategory_id['category_id' . $i] = $array['category_id'][$i]; |
---|
728 | } |
---|
729 | $objCheckCategory = new SC_CheckError($arrCategory_id); |
---|
730 | for ($i = 0; $i < count($array['category_id']); $i++) { |
---|
731 | $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
732 | } |
---|
733 | if (!empty($objCheckCategory->arrErr)) { |
---|
734 | $objErr->arrErr = array_merge($objErr->arrErr, |
---|
735 | $objCheckCategory->arrErr); |
---|
736 | } |
---|
737 | } |
---|
738 | return $objErr->arrErr; |
---|
739 | } |
---|
740 | |
---|
741 | /* 確認ページ表示用 */ |
---|
742 | function lfProductConfirmPage() { |
---|
743 | $this->tpl_mainpage = 'products/confirm.tpl'; |
---|
744 | $this->arrForm['mode'] = 'complete'; |
---|
745 | |
---|
746 | $objDb = new SC_Helper_DB_Ex(); |
---|
747 | |
---|
748 | // カテゴリ表示 |
---|
749 | $this->arrCategory_id = $this->arrForm['category_id']; |
---|
750 | $this->arrCatList = array(); |
---|
751 | list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
752 | for ($i = 0; $i < count($arrCatVal); $i++) { |
---|
753 | $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i]; |
---|
754 | } |
---|
755 | |
---|
756 | // hidden に渡す値は serialize する |
---|
757 | $this->arrForm['category_id'] = serialize($this->arrForm['category_id']); |
---|
758 | |
---|
759 | // Form用配列を渡す。 |
---|
760 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
761 | $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile(); |
---|
762 | } |
---|
763 | |
---|
764 | // 縮小した画像をセットする |
---|
765 | function lfSetScaleImage(){ |
---|
766 | |
---|
767 | $subno = str_replace("sub_large_image", "", $_POST['image_key']); |
---|
768 | switch ($_POST['image_key']){ |
---|
769 | case "main_large_image": |
---|
770 | // 詳細メイン画像 |
---|
771 | $this->lfMakeScaleImage($_POST['image_key'], "main_image"); |
---|
772 | case "main_image": |
---|
773 | // 一覧メイン画像 |
---|
774 | $this->lfMakeScaleImage($_POST['image_key'], "main_list_image"); |
---|
775 | break; |
---|
776 | case "sub_large_image" . $subno: |
---|
777 | // サブメイン画像 |
---|
778 | $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno); |
---|
779 | break; |
---|
780 | default: |
---|
781 | break; |
---|
782 | } |
---|
783 | } |
---|
784 | |
---|
785 | // 縮小画像生成 |
---|
786 | function lfMakeScaleImage($from_key, $to_key, $forced = false){ |
---|
787 | $arrImageKey = array_flip($this->objUpFile->keyname); |
---|
788 | |
---|
789 | if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){ |
---|
790 | $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]]; |
---|
791 | }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){ |
---|
792 | $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]]; |
---|
793 | }else{ |
---|
794 | return ""; |
---|
795 | } |
---|
796 | |
---|
797 | if(file_exists($from_path)){ |
---|
798 | // 生成先の画像サイズを取得 |
---|
799 | $to_w = $this->objUpFile->width[$arrImageKey[$to_key]]; |
---|
800 | $to_h = $this->objUpFile->height[$arrImageKey[$to_key]]; |
---|
801 | |
---|
802 | if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = ""; |
---|
803 | |
---|
804 | if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) && |
---|
805 | empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) { |
---|
806 | |
---|
807 | // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける |
---|
808 | $dst_file = $this->objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $this->objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key); |
---|
809 | $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file); |
---|
810 | $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path); |
---|
811 | } |
---|
812 | }else{ |
---|
813 | return ""; |
---|
814 | } |
---|
815 | } |
---|
816 | |
---|
817 | /** |
---|
818 | * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける |
---|
819 | */ |
---|
820 | function lfGetAddSuffix($to_key){ |
---|
821 | if( IMAGE_RENAME === true ){ return ; } |
---|
822 | |
---|
823 | // 自動生成される画像名 |
---|
824 | $dist_name = ""; |
---|
825 | switch($to_key){ |
---|
826 | case "main_list_image": |
---|
827 | $dist_name = '_s'; |
---|
828 | break; |
---|
829 | case "main_image": |
---|
830 | $dist_name = '_m'; |
---|
831 | break; |
---|
832 | default: |
---|
833 | $arrRet = explode('sub_image', $to_key); |
---|
834 | $dist_name = '_sub' .$arrRet[1]; |
---|
835 | break; |
---|
836 | } |
---|
837 | return $dist_name; |
---|
838 | } |
---|
839 | |
---|
840 | /** |
---|
841 | * dtb_products_classの複製 |
---|
842 | * 複製後、価格や商品コードを更新する |
---|
843 | * |
---|
844 | * @param array $arrList |
---|
845 | * @param array $objQuery |
---|
846 | * @return bool |
---|
847 | */ |
---|
848 | function lfCopyProductClass($arrList,$objQuery) |
---|
849 | { |
---|
850 | // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得) |
---|
851 | $col = "*"; |
---|
852 | $table = "dtb_products_class"; |
---|
853 | $where = "product_id = ?"; |
---|
854 | $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"])); |
---|
855 | |
---|
856 | //トランザクション開始 |
---|
857 | $objQuery->begin(); |
---|
858 | $err_flag = false; |
---|
859 | //非編集項目は複製、編集項目は上書きして登録 |
---|
860 | foreach($arrProductClass as $records) |
---|
861 | { |
---|
862 | foreach($records as $key => $value) |
---|
863 | { |
---|
864 | if(isset($arrList[$key])) |
---|
865 | { |
---|
866 | $records[$key] = $arrList[$key]; |
---|
867 | } |
---|
868 | } |
---|
869 | |
---|
870 | $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
871 | $records["update_date"] = 'now()'; |
---|
872 | $records["create_date"] = "Now()"; |
---|
873 | $objQuery->insert($table, $records); |
---|
874 | //エラー発生時は中断 |
---|
875 | if($objQuery->isError()) |
---|
876 | { |
---|
877 | $err_flag = true; |
---|
878 | continue; |
---|
879 | } |
---|
880 | } |
---|
881 | //トランザクション終了 |
---|
882 | if($err_flag) |
---|
883 | { |
---|
884 | $objQuery->rollback(); |
---|
885 | } |
---|
886 | else |
---|
887 | { |
---|
888 | $objQuery->commit(); |
---|
889 | } |
---|
890 | return !$err_flag; |
---|
891 | } |
---|
892 | |
---|
893 | /** |
---|
894 | * 規格を設定していない商品を商品規格テーブルに登録 |
---|
895 | * |
---|
896 | * @param array $arrList |
---|
897 | * @return void |
---|
898 | */ |
---|
899 | function lfInsertDummyProductClass($arrList) { |
---|
900 | $objQuery = new SC_Query(); |
---|
901 | $objDb = new SC_Helper_DB_Ex(); |
---|
902 | |
---|
903 | $product_id = $arrList['product_id']; |
---|
904 | // 規格登録してある商品の場合、処理しない |
---|
905 | if ($objDb->sfHasProductClass($product_id)) return; |
---|
906 | |
---|
907 | // 配列の添字を定義 |
---|
908 | $checkArray = array('product_class_id', 'product_id', 'product_code', 'stock', 'stock_unlimited', 'price01', 'price02', 'sale_limit', 'deliv_fee', 'point_rate' ,'product_type_id', 'down_filename', 'down_realfilename'); |
---|
909 | $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray); |
---|
910 | $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray); |
---|
911 | |
---|
912 | $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? UNLIMITED_FLG_UNLIMITED : UNLIMITED_FLG_LIMITED; |
---|
913 | $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0'; |
---|
914 | |
---|
915 | if (strlen($sqlval['product_class_id']) == 0) { |
---|
916 | $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
917 | $sqlval['create_date'] = 'now()'; |
---|
918 | $sqlval['update_date'] = 'now()'; |
---|
919 | // INSERTの実行 |
---|
920 | $objQuery->insert('dtb_products_class', $sqlval); |
---|
921 | } else { |
---|
922 | $sqlval['update_date'] = 'now()'; |
---|
923 | // UPDATEの実行 |
---|
924 | $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id'])); |
---|
925 | |
---|
926 | } |
---|
927 | } |
---|
928 | |
---|
929 | /* ダウンロードファイル情報の初期化 */ |
---|
930 | function lfInitDownFile() { |
---|
931 | $this->objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0); |
---|
932 | } |
---|
933 | |
---|
934 | /** |
---|
935 | * 同名画像ファイル登録の有無を確認する. |
---|
936 | * |
---|
937 | * 画像ファイルの削除可否判定用。 |
---|
938 | * 同名ファイルの登録がある場合には画像ファイルの削除を行わない。 |
---|
939 | * 戻り値: 同名ファイル有り(true) 同名ファイル無し(false) |
---|
940 | * |
---|
941 | * @param string $product_id 商品ID |
---|
942 | * @param string $arrImageKey 対象としない画像カラム名 |
---|
943 | * @param string $image_file_name 画像ファイル名 |
---|
944 | * @return boolean |
---|
945 | */ |
---|
946 | function lfHasSameProductImage($product_id, $arrImageKey, $image_file_name) { |
---|
947 | if (!SC_Utils_Ex::sfIsInt($product_id)) return false; |
---|
948 | if (!$arrImageKey) return false; |
---|
949 | if (!$image_file_name) return false; |
---|
950 | |
---|
951 | $arrWhere = array(); |
---|
952 | $sqlval = array('0', $product_id); |
---|
953 | foreach ($arrImageKey as $image_key) { |
---|
954 | $arrWhere[] = "{$image_key} = ?"; |
---|
955 | $sqlval[] = $image_file_name; |
---|
956 | } |
---|
957 | $where = implode(" OR ", $arrWhere); |
---|
958 | $where = "del_flg = ? AND ((product_id <> ? AND ({$where}))"; |
---|
959 | |
---|
960 | $arrKeyName = $this->objUpFile->keyname; |
---|
961 | foreach ($arrKeyName as $key => $keyname) { |
---|
962 | if (in_array($keyname, $arrImageKey)) continue; |
---|
963 | $where .= " OR {$keyname} = ?"; |
---|
964 | $sqlval[] = $image_file_name; |
---|
965 | } |
---|
966 | $where .= ")"; |
---|
967 | |
---|
968 | $objQuery = new SC_Query(); |
---|
969 | $count = $objQuery->count('dtb_products', $where, $sqlval); |
---|
970 | if (!$count) return false; |
---|
971 | return true; |
---|
972 | } |
---|
973 | } |
---|
974 | ?> |
---|