1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2011 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_EX_REALDIR . 'page_extends/admin/products/LC_Page_Admin_Products_Ex.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_Products_Ex { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'products/product.tpl'; |
---|
47 | $this->tpl_mainno = 'products'; |
---|
48 | $this->tpl_subno = 'product'; |
---|
49 | $this->tpl_maintitle = '商品管理'; |
---|
50 | $this->tpl_subtitle = '商品登録'; |
---|
51 | |
---|
52 | $masterData = new SC_DB_MasterData_Ex(); |
---|
53 | $this->arrProductType = $masterData->getMasterData("mtb_product_type"); |
---|
54 | $this->arrDISP = $masterData->getMasterData("mtb_disp"); |
---|
55 | $this->arrCLASS = $masterData->getMasterData("mtb_class"); |
---|
56 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
57 | $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); |
---|
58 | $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); |
---|
59 | $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList("dtb_maker", "maker_id", 'name'); |
---|
60 | $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag"); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Page のプロセス. |
---|
65 | * |
---|
66 | * @return void |
---|
67 | */ |
---|
68 | function process() { |
---|
69 | $this->action(); |
---|
70 | $this->sendResponse(); |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Page のアクション. |
---|
75 | * |
---|
76 | * @return void |
---|
77 | */ |
---|
78 | function action() { |
---|
79 | $objFormParam = new SC_FormParam_Ex(); |
---|
80 | |
---|
81 | // アップロードファイル情報の初期化 |
---|
82 | $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
83 | $this->lfInitFile($objUpFile); |
---|
84 | $objUpFile->setHiddenFileList($_POST); |
---|
85 | |
---|
86 | // ダウンロード販売ファイル情報の初期化 |
---|
87 | $objDownFile = new SC_UploadFile_Ex(DOWN_TEMP_REALDIR, DOWN_SAVE_REALDIR); |
---|
88 | $this->lfInitDownFile($objDownFile); |
---|
89 | $objDownFile->setHiddenFileList($_POST); |
---|
90 | |
---|
91 | // 検索パラメーター引き継ぎ |
---|
92 | $this->arrSearchHidden = $this->lfGetSearchParam($_POST); |
---|
93 | |
---|
94 | $mode = $this->getMode(); |
---|
95 | switch($mode) { |
---|
96 | case 'pre_edit': |
---|
97 | case 'copy' : |
---|
98 | // パラメーター初期化(商品ID) |
---|
99 | $this->lfInitFormParam_PreEdit($objFormParam, $_POST); |
---|
100 | // エラーチェック |
---|
101 | $this->arrErr = $objFormParam->checkError(); |
---|
102 | if(count($this->arrErr) > 0) { |
---|
103 | SC_Utils_Ex::sfDispException(); |
---|
104 | } |
---|
105 | |
---|
106 | // 商品ID取得 |
---|
107 | $product_id = $objFormParam->getValue('product_id'); |
---|
108 | // 商品データ取得 |
---|
109 | $arrForm = $this->lfGetFormParam_PreEdit($objUpFile, $objDownFile, $product_id); |
---|
110 | // ページ表示用パラメーター設定 |
---|
111 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
112 | |
---|
113 | // 商品複製の場合、画像ファイルコピー |
---|
114 | if($mode == 'copy') { |
---|
115 | $this->arrForm["copy_product_id"] = $this->arrForm["product_id"]; |
---|
116 | $this->arrForm["product_id"] = ""; |
---|
117 | // 画像ファイルのコピー |
---|
118 | $this->lfCopyProductImageFiles($objUpFile); |
---|
119 | } |
---|
120 | |
---|
121 | // ページonload時のJavaScript設定 |
---|
122 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); |
---|
123 | break; |
---|
124 | |
---|
125 | case 'edit': |
---|
126 | // パラメーター初期化, 取得 |
---|
127 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
128 | $arrForm = $objFormParam->getHashArray(); |
---|
129 | // エラーチェック |
---|
130 | $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm); |
---|
131 | if(count($this->arrErr) == 0) { |
---|
132 | // 確認画面表示設定 |
---|
133 | $this->tpl_mainpage = 'products/confirm.tpl'; |
---|
134 | $this->arrCatList = $this->lfGetCategoryList_Edit(); |
---|
135 | $this->arrForm = $this->lfSetViewParam_ConfirmPage($objUpFile, $objDownFile, $arrForm); |
---|
136 | } else { |
---|
137 | // 入力画面表示設定 |
---|
138 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
139 | // ページonload時のJavaScript設定 |
---|
140 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); |
---|
141 | } |
---|
142 | break; |
---|
143 | |
---|
144 | case 'complete': |
---|
145 | // パラメーター初期化, 取得 |
---|
146 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
147 | $arrForm = $this->lfGetFormParam_Complete($objFormParam); |
---|
148 | // エラーチェック |
---|
149 | $this->arrErr = $this->lfCheckError_Edit($objFormParam, $objUpFile, $objDownFile, $arrForm); |
---|
150 | if(count($this->arrErr) == 0) { |
---|
151 | // DBへデータ登録 |
---|
152 | $product_id = $this->lfRegistProduct($objUpFile, $objDownFile, $arrForm); |
---|
153 | |
---|
154 | // 件数カウントバッチ実行 |
---|
155 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
156 | $objDb = new SC_Helper_DB_Ex(); |
---|
157 | $objDb->sfCountCategory($objQuery); |
---|
158 | $objDb->sfCountMaker($objQuery); |
---|
159 | |
---|
160 | // 一時ファイルを本番ディレクトリに移動する |
---|
161 | $this->lfSaveUploadFiles($objUpFile, $objDownFile, $product_id); |
---|
162 | |
---|
163 | $this->tpl_mainpage = 'products/complete.tpl'; |
---|
164 | $this->arrForm['product_id'] = $product_id; |
---|
165 | } else { |
---|
166 | // 入力画面表示設定 |
---|
167 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
168 | // ページonload時のJavaScript設定 |
---|
169 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); |
---|
170 | } |
---|
171 | break; |
---|
172 | |
---|
173 | // 画像のアップロード |
---|
174 | case 'upload_image': |
---|
175 | case 'delete_image': |
---|
176 | // パラメーター初期化 |
---|
177 | $this->lfInitFormParam_UploadImage($objFormParam); |
---|
178 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
179 | $arrForm = $objFormParam->getHashArray(); |
---|
180 | |
---|
181 | switch($mode) { |
---|
182 | case 'upload_image': |
---|
183 | // ファイルを一時ディレクトリにアップロード |
---|
184 | $this->arrErr[$arrForm['image_key']] = $objUpFile->makeTempFile($arrForm['image_key'], IMAGE_RENAME); |
---|
185 | if($this->arrErr[$arrForm['image_key']] == "") { |
---|
186 | // 縮小画像作成 |
---|
187 | $this->lfSetScaleImage($objUpFile, $arrForm['image_key']); |
---|
188 | } |
---|
189 | break; |
---|
190 | case 'delete_image': |
---|
191 | // ファイル削除 |
---|
192 | $this->lfDeleteTempFile($objUpFile, $arrForm['image_key']); |
---|
193 | break; |
---|
194 | } |
---|
195 | |
---|
196 | // 入力画面表示設定 |
---|
197 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
198 | // ページonload時のJavaScript設定 |
---|
199 | $anchor_hash = $this->getAnchorHash($arrForm['image_key']); |
---|
200 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); |
---|
201 | break; |
---|
202 | |
---|
203 | // ダウンロード商品ファイルアップロード |
---|
204 | case 'upload_down': |
---|
205 | case 'delete_down': |
---|
206 | // パラメーター初期化 |
---|
207 | $this->lfInitFormParam_UploadDown($objFormParam); |
---|
208 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
209 | $arrForm = $objFormParam->getHashArray(); |
---|
210 | |
---|
211 | switch($mode) { |
---|
212 | case 'upload_down': |
---|
213 | // ファイルを一時ディレクトリにアップロード |
---|
214 | $this->arrErr[$arrForm['down_key']] = $objDownFile->makeTempDownFile(); |
---|
215 | break; |
---|
216 | case 'delete_down': |
---|
217 | // ファイル削除 |
---|
218 | $objDownFile->deleteFile($arrForm['down_key']); |
---|
219 | break; |
---|
220 | } |
---|
221 | |
---|
222 | // 入力画面表示設定 |
---|
223 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
224 | // ページonload時のJavaScript設定 |
---|
225 | $anchor_hash = $this->getAnchorHash($arrForm['down_key']); |
---|
226 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); |
---|
227 | break; |
---|
228 | |
---|
229 | // 関連商品選択 |
---|
230 | case 'recommend_select' : |
---|
231 | // パラメーター初期化 |
---|
232 | $this->lfInitFormParam_RecommendSelect($objFormParam); |
---|
233 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
234 | $arrForm = $objFormParam->getHashArray(); |
---|
235 | // 入力画面表示設定 |
---|
236 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
237 | |
---|
238 | // 選択された関連商品IDがすでに登録している関連商品と重複していないかチェック |
---|
239 | $this->lfCheckError_RecommendSelect($this->arrForm, $this->arrErr); |
---|
240 | |
---|
241 | // ページonload時のJavaScript設定 |
---|
242 | $anchor_hash = $this->getAnchorHash($this->arrForm['anchor_key']); |
---|
243 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage($anchor_hash); |
---|
244 | break; |
---|
245 | |
---|
246 | // 確認ページからの戻り |
---|
247 | case 'confirm_return': |
---|
248 | // パラメーター初期化 |
---|
249 | $this->lfInitFormParam($objFormParam, $_POST); |
---|
250 | $arrForm = $objFormParam->getHashArray(); |
---|
251 | // 入力画面表示設定 |
---|
252 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
253 | // ページonload時のJavaScript設定 |
---|
254 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); |
---|
255 | break; |
---|
256 | |
---|
257 | default: |
---|
258 | // 入力画面表示設定 |
---|
259 | $arrForm = array(); |
---|
260 | $this->arrForm = $this->lfSetViewParam_InputPage($objUpFile, $objDownFile, $arrForm); |
---|
261 | // ページonload時のJavaScript設定 |
---|
262 | $this->tpl_onload = $this->lfSetOnloadJavaScript_InputPage(); |
---|
263 | break; |
---|
264 | } |
---|
265 | |
---|
266 | // 関連商品の読み込み |
---|
267 | $this->arrRecommend = $this->lfGetRecommendProducts($this->arrForm); |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * デストラクタ. |
---|
272 | * |
---|
273 | * @return void |
---|
274 | */ |
---|
275 | function destroy() { |
---|
276 | parent::destroy(); |
---|
277 | } |
---|
278 | |
---|
279 | /** |
---|
280 | * パラメーター情報の初期化 |
---|
281 | * - 編集/複製モード |
---|
282 | * |
---|
283 | * @param object $objFormParam SC_FormParamインスタンス |
---|
284 | * @param array $arrPost $_POSTデータ |
---|
285 | * @return void |
---|
286 | */ |
---|
287 | function lfInitFormParam_PreEdit(&$objFormParam, $arrPost) { |
---|
288 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
289 | $objFormParam->setParam($arrPost); |
---|
290 | $objFormParam->convParam(); |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * パラメーター情報の初期化 |
---|
295 | * |
---|
296 | * @param object $objFormParam SC_FormParamインスタンス |
---|
297 | * @param array $arrPost $_POSTデータ |
---|
298 | * @return void |
---|
299 | */ |
---|
300 | function lfInitFormParam(&$objFormParam, $arrPost) { |
---|
301 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
302 | $objFormParam->addParam("商品名", 'name', STEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
303 | $objFormParam->addParam("商品カテゴリ", "category_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
304 | $objFormParam->addParam("公開・非公開", 'status', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
305 | $objFormParam->addParam("商品ステータス", "product_status", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
306 | |
---|
307 | if($this->lfGetProductClassFlag($arrPost['has_product_class']) == false) { |
---|
308 | // 新規登録, 規格なし商品の編集の場合 |
---|
309 | $objFormParam->addParam("商品種別", "product_type_id", INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
310 | $objFormParam->addParam("ダウンロード商品ファイル名", "down_filename", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
311 | $objFormParam->addParam("ダウンロード商品実ファイル名", "down_realfilename", MTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
312 | $objFormParam->addParam("temp_down_file", "temp_down_file", '', "", array()); |
---|
313 | $objFormParam->addParam("save_down_file", "save_down_file", '', "", array()); |
---|
314 | $objFormParam->addParam("商品コード", "product_code", STEXT_LEN, 'KVna', array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
315 | $objFormParam->addParam(NORMAL_PRICE_TITLE, "price01", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
316 | $objFormParam->addParam(SALE_PRICE_TITLE, "price02", PRICE_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
317 | $objFormParam->addParam("在庫数", 'stock', AMOUNT_LEN, 'n', array("SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
318 | $objFormParam->addParam("在庫無制限", "stock_unlimited", INT_LEN, 'n', array("SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
319 | } |
---|
320 | $objFormParam->addParam("商品送料", "deliv_fee", PRICE_LEN, 'n', array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
321 | $objFormParam->addParam("ポイント付与率", "point_rate", PERCENTAGE_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
322 | $objFormParam->addParam("発送日目安", "deliv_date_id", INT_LEN, 'n', array("NUM_CHECK")); |
---|
323 | $objFormParam->addParam("購入制限", "sale_limit", AMOUNT_LEN, 'n', array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
324 | $objFormParam->addParam("メーカー", "maker_id", INT_LEN, 'n', array("NUM_CHECK")); |
---|
325 | $objFormParam->addParam("メーカーURL", "comment1", URL_LEN, 'a', array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK")); |
---|
326 | $objFormParam->addParam("検索ワード", "comment3", LLTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
327 | $objFormParam->addParam("備考欄(SHOP専用)", 'note', LLTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
328 | $objFormParam->addParam("一覧-メインコメント", "main_list_comment", MTEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
329 | $objFormParam->addParam("詳細-メインコメント", "main_comment", LLTEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
330 | $objFormParam->addParam("save_main_list_image", "save_main_list_image", '', "", array()); |
---|
331 | $objFormParam->addParam("save_main_image", "save_main_image", '', "", array()); |
---|
332 | $objFormParam->addParam("save_main_large_image", "save_main_large_image", '', "", array()); |
---|
333 | $objFormParam->addParam("temp_main_list_image", "temp_main_list_image", '', "", array()); |
---|
334 | $objFormParam->addParam("temp_main_image", "temp_main_image", '', "", array()); |
---|
335 | $objFormParam->addParam("temp_main_large_image", "temp_main_large_image", '', "", array()); |
---|
336 | |
---|
337 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
338 | $objFormParam->addParam("詳細-サブタイトル" . $cnt, "sub_title" . $cnt, STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
339 | $objFormParam->addParam("詳細-サブコメント" . $cnt, "sub_comment" . $cnt, LLTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
340 | $objFormParam->addParam("save_sub_image" . $cnt, "save_sub_image" . $cnt, '', "", array()); |
---|
341 | $objFormParam->addParam("save_sub_large_image" . $cnt, "save_sub_large_image" . $cnt, '', "", array()); |
---|
342 | $objFormParam->addParam("temp_sub_image" . $cnt, "temp_sub_image" . $cnt, '', "", array()); |
---|
343 | $objFormParam->addParam("temp_sub_large_image" . $cnt, "temp_sub_large_image" . $cnt, '', "", array()); |
---|
344 | } |
---|
345 | |
---|
346 | for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) { |
---|
347 | $objFormParam->addParam("関連商品コメント" . $cnt, "recommend_comment" . $cnt, LTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
348 | $objFormParam->addParam("関連商品ID" . $cnt, "recommend_id" . $cnt, INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
349 | $objFormParam->addParam("recommend_delete" . $cnt, "recommend_delete" . $cnt, '', 'n', array()); |
---|
350 | } |
---|
351 | |
---|
352 | $objFormParam->addParam("商品ID", "copy_product_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
353 | |
---|
354 | $objFormParam->addParam("has_product_class", "has_product_class", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
355 | $objFormParam->addParam("product_class_id", "product_class_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
356 | |
---|
357 | $objFormParam->setParam($arrPost); |
---|
358 | $objFormParam->convParam(); |
---|
359 | } |
---|
360 | |
---|
361 | /** |
---|
362 | * パラメーター情報の初期化 |
---|
363 | * - 画像ファイルアップロードモード |
---|
364 | * |
---|
365 | * @param object $objFormParam SC_FormParamインスタンス |
---|
366 | * @return void |
---|
367 | */ |
---|
368 | function lfInitFormParam_UploadImage(&$objFormParam) { |
---|
369 | $objFormParam->addParam("image_key", "image_key", "", "", array()); |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | * パラメーター情報の初期化 |
---|
374 | * - ダウンロード商品ファイルアップロードモード |
---|
375 | * |
---|
376 | * @param object $objFormParam SC_FormParamインスタンス |
---|
377 | * @return void |
---|
378 | */ |
---|
379 | function lfInitFormParam_UploadDown(&$objFormParam) { |
---|
380 | $objFormParam->addParam("down_key", "down_key", "", "", array()); |
---|
381 | } |
---|
382 | |
---|
383 | /** |
---|
384 | * パラメーター情報の初期化 |
---|
385 | * - 関連商品追加モード |
---|
386 | * |
---|
387 | * @param object $objFormParam SC_FormParamインスタンス |
---|
388 | * @return void |
---|
389 | */ |
---|
390 | function lfInitFormParam_RecommendSelect(&$objFormParam) { |
---|
391 | $objFormParam->addParam("anchor_key", "anchor_key", "", "", array()); |
---|
392 | $objFormParam->addParam("select_recommend_no", "select_recommend_no", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
393 | } |
---|
394 | |
---|
395 | /** |
---|
396 | * アップロードファイルパラメーター情報の初期化 |
---|
397 | * - 画像ファイル用 |
---|
398 | * |
---|
399 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
400 | * @return void |
---|
401 | */ |
---|
402 | function lfInitFile(&$objUpFile) { |
---|
403 | $objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); |
---|
404 | $objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT); |
---|
405 | $objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT); |
---|
406 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
407 | $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT); |
---|
408 | $objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | /** |
---|
413 | * アップロードファイルパラメーター情報の初期化 |
---|
414 | * - ダウンロード商品ファイル用 |
---|
415 | * |
---|
416 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
417 | * @return void |
---|
418 | */ |
---|
419 | function lfInitDownFile(&$objDownFile) { |
---|
420 | $objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0); |
---|
421 | } |
---|
422 | |
---|
423 | /** |
---|
424 | * フォーム入力パラメーターのエラーチェック |
---|
425 | * |
---|
426 | * @param object $objFormParam SC_FormParamインスタンス |
---|
427 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
428 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
429 | * @param array $arrForm フォーム入力パラメーター配列 |
---|
430 | * @return array エラー情報を格納した連想配列 |
---|
431 | */ |
---|
432 | function lfCheckError_Edit(&$objFormParam, &$objUpFile, &$objDownFile, $arrForm) { |
---|
433 | $objErr = new SC_CheckError_Ex($arrForm); |
---|
434 | $arrErr = array(); |
---|
435 | |
---|
436 | // 入力パラメーターチェック |
---|
437 | $arrErr = $objFormParam->checkError(); |
---|
438 | |
---|
439 | // アップロードファイル必須チェック |
---|
440 | $arrErr = array_merge((array)$arrErr, (array)$objUpFile->checkEXISTS()); |
---|
441 | |
---|
442 | // HTMLタグ許可チェック |
---|
443 | $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
444 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
445 | $objErr->doFunc(array("詳細-サブコメント" . $cnt, "sub_comment" . $cnt, $this->arrAllowedTag), array("HTML_TAG_CHECK")); |
---|
446 | } |
---|
447 | |
---|
448 | // 規格情報がない商品の場合のチェック |
---|
449 | if($arrForm['has_product_class'] != true) { |
---|
450 | // 在庫必須チェック(在庫無制限ではない場合) |
---|
451 | if(!isset($arrForm['stock_unlimited']) && $arrForm['stock_unlimited'] != UNLIMITED_FLG_UNLIMITED) { |
---|
452 | $objErr->doFunc(array("在庫数", 'stock'), array("EXIST_CHECK")); |
---|
453 | } |
---|
454 | // ダウンロード商品ファイル必須チェック(ダウンロード商品の場合) |
---|
455 | if($arrForm['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) { |
---|
456 | $arrErr = array_merge((array)$arrErr, (array)$objDownFile->checkEXISTS()); |
---|
457 | } |
---|
458 | } |
---|
459 | |
---|
460 | $arrErr = array_merge((array)$arrErr, (array)$objErr->arrErr); |
---|
461 | return $arrErr; |
---|
462 | } |
---|
463 | |
---|
464 | /** |
---|
465 | * 関連商品の重複登録チェック、エラーチェック |
---|
466 | * |
---|
467 | * 関連商品の重複があった場合はエラーメッセージを格納し、該当の商品IDをリセットする |
---|
468 | * |
---|
469 | * @param array $arrForm 入力値の配列 |
---|
470 | * @param array $arrErr エラーメッセージの配列 |
---|
471 | * @return void |
---|
472 | */ |
---|
473 | function lfCheckError_RecommendSelect(&$arrForm, &$arrErr) { |
---|
474 | $select_recommend_no = $arrForm['select_recommend_no']; |
---|
475 | $select_recommend_id = $arrForm['recommend_id' . $select_recommend_no]; |
---|
476 | |
---|
477 | foreach(array_keys($arrForm) as $key) { |
---|
478 | if(preg_match('/^recommend_id/', $key)) { |
---|
479 | if($select_recommend_no == preg_replace('/^recommend_id/', '', $key)) { |
---|
480 | continue; |
---|
481 | } |
---|
482 | |
---|
483 | if($select_recommend_id == $arrForm[$key]) { |
---|
484 | // 重複した場合、選択されたデータをリセットする |
---|
485 | $arrForm['recommend_id' . $select_recommend_no] = ''; |
---|
486 | $arrErr['recommend_comment' . $select_recommend_no] = '※ すでに登録されている関連商品です。<br />'; |
---|
487 | break; |
---|
488 | } |
---|
489 | } |
---|
490 | } |
---|
491 | } |
---|
492 | |
---|
493 | /** |
---|
494 | * 検索パラメーター引き継ぎ用配列取得 |
---|
495 | * |
---|
496 | * @param array $arrPost $_POSTデータ |
---|
497 | * @return array 検索パラメーター配列 |
---|
498 | */ |
---|
499 | function lfGetSearchParam($arrPost) { |
---|
500 | $arrSearchParam = array(); |
---|
501 | $objFormParam = new SC_FormParam_Ex(); |
---|
502 | |
---|
503 | parent::lfInitParam($objFormParam); |
---|
504 | $objFormParam->setParam($arrPost); |
---|
505 | $arrSearchParam = $objFormParam->getSearchArray(); |
---|
506 | |
---|
507 | return $arrSearchParam; |
---|
508 | } |
---|
509 | |
---|
510 | /** |
---|
511 | * フォームパラメーター取得 |
---|
512 | * - 編集/複製モード |
---|
513 | * |
---|
514 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
515 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
516 | * @param integer $product_id 商品ID |
---|
517 | * @return array フォームパラメーター配列 |
---|
518 | */ |
---|
519 | function lfGetFormParam_PreEdit(&$objUpFile, &$objDownFile, $product_id) { |
---|
520 | $arrForm = array(); |
---|
521 | |
---|
522 | // DBから商品データ取得 |
---|
523 | $arrForm = $this->lfGetProductData_FromDB($product_id); |
---|
524 | // DBデータから画像ファイル名の読込 |
---|
525 | $objUpFile->setDBFileList($arrForm); |
---|
526 | // DBデータからダウンロードファイル名の読込 |
---|
527 | $objDownFile->setDBDownFile($arrForm); |
---|
528 | |
---|
529 | return $arrForm; |
---|
530 | } |
---|
531 | |
---|
532 | /** |
---|
533 | * フォームパラメーター取得 |
---|
534 | * - 登録モード |
---|
535 | * |
---|
536 | * @param object $objFormParam SC_FormParamインスタンス |
---|
537 | * @return array フォームパラメーター配列 |
---|
538 | */ |
---|
539 | function lfGetFormParam_Complete(&$objFormParam) { |
---|
540 | $arrForm = $objFormParam->getHashArray(); |
---|
541 | $arrForm['category_id'] = unserialize($arrForm['category_id']); |
---|
542 | $objFormParam->setValue('category_id', $arrForm['category_id']); |
---|
543 | |
---|
544 | return $arrForm; |
---|
545 | } |
---|
546 | |
---|
547 | /** |
---|
548 | * 表示用フォームパラメーター取得 |
---|
549 | * - 入力画面 |
---|
550 | * |
---|
551 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
552 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
553 | * @param array $arrForm フォーム入力パラメーター配列 |
---|
554 | * @return array 表示用フォームパラメーター配列 |
---|
555 | */ |
---|
556 | function lfSetViewParam_InputPage(&$objUpFile, &$objDownFile, &$arrForm) { |
---|
557 | // カテゴリマスターデータ取得 |
---|
558 | $objDb = new SC_Helper_DB_Ex(); |
---|
559 | list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
560 | |
---|
561 | if (isset($arrForm['category_id']) && !is_array($arrForm['category_id'])) { |
---|
562 | $arrForm['category_id'] = unserialize($arrForm['category_id']); |
---|
563 | } |
---|
564 | if($arrForm['status'] == "") { |
---|
565 | $arrForm['status'] = DEFAULT_PRODUCT_DISP; |
---|
566 | } |
---|
567 | if($arrForm['product_type_id'] == "") { |
---|
568 | $arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN; |
---|
569 | } |
---|
570 | // アップロードファイル情報取得(Hidden用) |
---|
571 | $arrHidden = $objUpFile->getHiddenFileList(); |
---|
572 | $arrForm['arrHidden'] = array_merge((array)$arrHidden, (array)$objDownFile->getHiddenFileList()); |
---|
573 | |
---|
574 | // 画像ファイル表示用データ取得 |
---|
575 | $arrForm['arrFile'] = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
576 | |
---|
577 | // ダウンロード商品実ファイル名取得 |
---|
578 | $arrForm['down_realfilename'] = $objDownFile->getFormDownFile(); |
---|
579 | |
---|
580 | // 基本情報(デフォルトポイントレート用) |
---|
581 | $arrForm['arrInfo'] = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
582 | |
---|
583 | // サブ情報ありなしフラグ |
---|
584 | $arrForm['sub_find'] = $this->hasSubProductData($arrForm); |
---|
585 | |
---|
586 | return $arrForm; |
---|
587 | } |
---|
588 | |
---|
589 | /** |
---|
590 | * 表示用フォームパラメーター取得 |
---|
591 | * - 確認画面 |
---|
592 | * |
---|
593 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
594 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
595 | * @param array $arrForm フォーム入力パラメーター配列 |
---|
596 | * @return array 表示用フォームパラメーター配列 |
---|
597 | */ |
---|
598 | function lfSetViewParam_ConfirmPage(&$objUpFile, &$objDownFile, &$arrForm) { |
---|
599 | // カテゴリ表示用 |
---|
600 | $arrForm['arrCategoryId'] = $arrForm['category_id']; |
---|
601 | // hidden に渡す値は serialize する |
---|
602 | $arrForm['category_id'] = serialize($arrForm['category_id']); |
---|
603 | // 画像ファイル用データ取得 |
---|
604 | $arrForm['arrFile'] = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
605 | // ダウンロード商品実ファイル名取得 |
---|
606 | $arrForm['down_realfilename'] = $objDownFile->getFormDownFile(); |
---|
607 | |
---|
608 | return $arrForm; |
---|
609 | } |
---|
610 | |
---|
611 | /** |
---|
612 | * 縮小した画像をセットする |
---|
613 | * |
---|
614 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
615 | * @param string $image_key 画像ファイルキー |
---|
616 | * @return void |
---|
617 | */ |
---|
618 | function lfSetScaleImage(&$objUpFile, $image_key){ |
---|
619 | $subno = str_replace("sub_large_image", "", $image_key); |
---|
620 | switch ($image_key){ |
---|
621 | case "main_large_image": |
---|
622 | // 詳細メイン画像 |
---|
623 | $this->lfMakeScaleImage($objUpFile, $image_key, "main_image"); |
---|
624 | case "main_image": |
---|
625 | // 一覧メイン画像 |
---|
626 | $this->lfMakeScaleImage($objUpFile, $image_key, "main_list_image"); |
---|
627 | break; |
---|
628 | case "sub_large_image" . $subno: |
---|
629 | // サブメイン画像 |
---|
630 | $this->lfMakeScaleImage($objUpFile, $_POST['image_key'], "sub_image" . $subno); |
---|
631 | break; |
---|
632 | default: |
---|
633 | break; |
---|
634 | } |
---|
635 | } |
---|
636 | |
---|
637 | /** |
---|
638 | * 画像ファイルのコピー |
---|
639 | * |
---|
640 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
641 | * @return void |
---|
642 | */ |
---|
643 | function lfCopyProductImageFiles(&$objUpFile) { |
---|
644 | $arrKey = $objUpFile->keyname; |
---|
645 | $arrSaveFile = $objUpFile->save_file; |
---|
646 | |
---|
647 | foreach($arrSaveFile as $key => $val){ |
---|
648 | $this->lfMakeScaleImage($objUpFile, $arrKey[$key], $arrKey[$key], true); |
---|
649 | } |
---|
650 | } |
---|
651 | |
---|
652 | /** |
---|
653 | * 縮小画像生成 |
---|
654 | * |
---|
655 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
656 | * @param string $from_key 元画像ファイルキー |
---|
657 | * @param string $to_key 縮小画像ファイルキー |
---|
658 | * @param boolean $forced |
---|
659 | * @return void |
---|
660 | */ |
---|
661 | function lfMakeScaleImage(&$objUpFile, $from_key, $to_key, $forced = false){ |
---|
662 | $arrImageKey = array_flip($objUpFile->keyname); |
---|
663 | $from_path = ""; |
---|
664 | |
---|
665 | if($objUpFile->temp_file[$arrImageKey[$from_key]]) { |
---|
666 | $from_path = $objUpFile->temp_dir . $objUpFile->temp_file[$arrImageKey[$from_key]]; |
---|
667 | } elseif($objUpFile->save_file[$arrImageKey[$from_key]]){ |
---|
668 | $from_path = $objUpFile->save_dir . $objUpFile->save_file[$arrImageKey[$from_key]]; |
---|
669 | } |
---|
670 | |
---|
671 | if(file_exists($from_path)) { |
---|
672 | // 生成先の画像サイズを取得 |
---|
673 | $to_w = $objUpFile->width[$arrImageKey[$to_key]]; |
---|
674 | $to_h = $objUpFile->height[$arrImageKey[$to_key]]; |
---|
675 | |
---|
676 | if($forced) $objUpFile->save_file[$arrImageKey[$to_key]] = ""; |
---|
677 | |
---|
678 | if(empty($objUpFile->temp_file[$arrImageKey[$to_key]]) |
---|
679 | && empty($objUpFile->save_file[$arrImageKey[$to_key]])) { |
---|
680 | // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける |
---|
681 | $dst_file = $objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key); |
---|
682 | $path = $objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file); |
---|
683 | $objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path); |
---|
684 | } |
---|
685 | } |
---|
686 | } |
---|
687 | |
---|
688 | /** |
---|
689 | * アップロードファイルパラメーター情報から削除 |
---|
690 | * 一時ディレクトリに保存されている実ファイルも削除する |
---|
691 | * |
---|
692 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
693 | * @param string $image_key 画像ファイルキー |
---|
694 | * @return void |
---|
695 | */ |
---|
696 | function lfDeleteTempFile(&$objUpFile, $image_key) { |
---|
697 | // TODO: SC_UploadFile::deleteFileの画像削除条件見直し要 |
---|
698 | $arrTempFile = $objUpFile->temp_file; |
---|
699 | $arrKeyName = $objUpFile->keyname; |
---|
700 | |
---|
701 | foreach($arrKeyName as $key => $keyname) { |
---|
702 | if($keyname != $image_key) continue; |
---|
703 | |
---|
704 | if(!empty($arrTempFile[$key])) { |
---|
705 | $temp_file = $arrTempFile[$key]; |
---|
706 | $arrTempFile[$key] = ''; |
---|
707 | |
---|
708 | if(!in_array($temp_file, $arrTempFile)) { |
---|
709 | $objUpFile->deleteFile($image_key); |
---|
710 | } else { |
---|
711 | $objUpFile->temp_file[$key] = ''; |
---|
712 | $objUpFile->save_file[$key] = ''; |
---|
713 | } |
---|
714 | } else { |
---|
715 | $objUpFile->temp_file[$key] = ''; |
---|
716 | $objUpFile->save_file[$key] = ''; |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | |
---|
721 | /** |
---|
722 | * アップロードファイルを保存する |
---|
723 | * |
---|
724 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
725 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
726 | * @param integer $product_id 商品ID |
---|
727 | * @return void |
---|
728 | */ |
---|
729 | function lfSaveUploadFiles(&$objUpFile, &$objDownFile, $product_id) { |
---|
730 | // TODO: SC_UploadFile::moveTempFileの画像削除条件見直し要 |
---|
731 | $objImage = new SC_Image_Ex($objUpFile->temp_dir); |
---|
732 | $arrKeyName = $objUpFile->keyname; |
---|
733 | $arrTempFile = $objUpFile->temp_file; |
---|
734 | $arrSaveFile = $objUpFile->save_file; |
---|
735 | $arrImageKey = array(); |
---|
736 | foreach($arrTempFile as $key => $temp_file) { |
---|
737 | if($temp_file) { |
---|
738 | $objImage->moveTempImage($temp_file, $objUpFile->save_dir); |
---|
739 | $arrImageKey[] = $arrKeyName[$key]; |
---|
740 | if(!empty($arrSaveFile[$key]) |
---|
741 | && !$this->lfHasSameProductImage($product_id, $arrImageKey, $arrSaveFile[$key]) |
---|
742 | && !in_array($temp_file, $arrSaveFile)) { |
---|
743 | $objImage->deleteImage($arrSaveFile[$key], $objUpFile->save_dir); |
---|
744 | } |
---|
745 | } |
---|
746 | } |
---|
747 | $objDownFile->moveTempDownFile(); |
---|
748 | } |
---|
749 | |
---|
750 | /** |
---|
751 | * 同名画像ファイル登録の有無を確認する. |
---|
752 | * |
---|
753 | * 画像ファイルの削除可否判定用。 |
---|
754 | * 同名ファイルの登録がある場合には画像ファイルの削除を行わない。 |
---|
755 | * 戻り値: 同名ファイル有り(true) 同名ファイル無し(false) |
---|
756 | * |
---|
757 | * @param string $product_id 商品ID |
---|
758 | * @param string $arrImageKey 対象としない画像カラム名 |
---|
759 | * @param string $image_file_name 画像ファイル名 |
---|
760 | * @return boolean |
---|
761 | */ |
---|
762 | function lfHasSameProductImage($product_id, $arrImageKey, $image_file_name) { |
---|
763 | if (!SC_Utils_Ex::sfIsInt($product_id)) return false; |
---|
764 | if (!$arrImageKey) return false; |
---|
765 | if (!$image_file_name) return false; |
---|
766 | |
---|
767 | $arrWhere = array(); |
---|
768 | $sqlval = array('0', $product_id); |
---|
769 | foreach ($arrImageKey as $image_key) { |
---|
770 | $arrWhere[] = "{$image_key} = ?"; |
---|
771 | $sqlval[] = $image_file_name; |
---|
772 | } |
---|
773 | $where = implode(" OR ", $arrWhere); |
---|
774 | $where = "del_flg = ? AND ((product_id <> ? AND ({$where}))"; |
---|
775 | |
---|
776 | $arrKeyName = $this->objUpFile->keyname; |
---|
777 | foreach ($arrKeyName as $key => $keyname) { |
---|
778 | if (in_array($keyname, $arrImageKey)) continue; |
---|
779 | $where .= " OR {$keyname} = ?"; |
---|
780 | $sqlval[] = $image_file_name; |
---|
781 | } |
---|
782 | $where .= ")"; |
---|
783 | |
---|
784 | $objQuery = new SC_Query_Ex(); |
---|
785 | $count = $objQuery->count('dtb_products', $where, $sqlval); |
---|
786 | if (!$count) return false; |
---|
787 | return true; |
---|
788 | } |
---|
789 | |
---|
790 | /** |
---|
791 | * DBから商品データを取得する |
---|
792 | * |
---|
793 | * @param integer $product_id 商品ID |
---|
794 | * @return array 商品データ配列 |
---|
795 | */ |
---|
796 | function lfGetProductData_FromDB($product_id) { |
---|
797 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
798 | $arrProduct = array(); |
---|
799 | |
---|
800 | // 商品データ取得 |
---|
801 | $col = "*"; |
---|
802 | $table = <<< __EOF__ |
---|
803 | dtb_products AS T1 |
---|
804 | LEFT JOIN ( |
---|
805 | SELECT product_id AS product_id_sub, |
---|
806 | product_code, |
---|
807 | price01, |
---|
808 | price02, |
---|
809 | deliv_fee, |
---|
810 | stock, |
---|
811 | stock_unlimited, |
---|
812 | sale_limit, |
---|
813 | point_rate, |
---|
814 | product_type_id, |
---|
815 | down_filename, |
---|
816 | down_realfilename |
---|
817 | FROM dtb_products_class |
---|
818 | ) AS T2 |
---|
819 | ON T1.product_id = T2.product_id_sub |
---|
820 | __EOF__; |
---|
821 | $where = "product_id = ?"; |
---|
822 | $objQuery->setLimit('1'); |
---|
823 | $arrProduct = $objQuery->select($col, $table, $where, array($product_id)); |
---|
824 | |
---|
825 | // カテゴリID取得 |
---|
826 | $col = "category_id"; |
---|
827 | $table = "dtb_product_categories"; |
---|
828 | $where = "product_id = ?"; |
---|
829 | $objQuery->setOption(''); |
---|
830 | $arrProduct[0]['category_id'] = $objQuery->getCol($col, $table, $where, array($product_id)); |
---|
831 | |
---|
832 | // 規格情報ありなしフラグ取得 |
---|
833 | $objDb = new SC_Helper_DB_Ex(); |
---|
834 | $arrProduct[0]['has_product_class'] = $objDb->sfHasProductClass($product_id); |
---|
835 | |
---|
836 | // 規格が登録されていなければ規格ID取得 |
---|
837 | if ($arrProduct[0]['has_product_class'] == false) { |
---|
838 | $arrProduct[0]['product_class_id'] = SC_Utils_Ex::sfGetProductClassId($product_id,"0","0"); |
---|
839 | } |
---|
840 | |
---|
841 | // 商品ステータス取得 |
---|
842 | $objProduct = new SC_Product_Ex(); |
---|
843 | $productStatus = $objProduct->getProductStatus(array($product_id)); |
---|
844 | $arrProduct[0]['product_status'] = $productStatus[$product_id]; |
---|
845 | |
---|
846 | // 関連商品データ取得 |
---|
847 | $arrRecommend = $this->lfGetRecommendProductsData_FromDB($product_id); |
---|
848 | $arrProduct[0] = array_merge($arrProduct[0], $arrRecommend); |
---|
849 | |
---|
850 | return $arrProduct[0]; |
---|
851 | } |
---|
852 | |
---|
853 | /** |
---|
854 | * DBから関連商品データを取得する |
---|
855 | * |
---|
856 | * @param integer $product_id 商品ID |
---|
857 | * @return array 関連商品データ配列 |
---|
858 | */ |
---|
859 | function lfGetRecommendProductsData_FromDB($product_id) { |
---|
860 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
861 | $arrRecommendProducts = array(); |
---|
862 | |
---|
863 | $col = 'recommend_product_id,'; |
---|
864 | $col.= 'comment'; |
---|
865 | $table = 'dtb_recommend_products'; |
---|
866 | $where = 'product_id = ?'; |
---|
867 | $objQuery->setOrder("rank DESC"); |
---|
868 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
869 | |
---|
870 | $no = 1; |
---|
871 | foreach ($arrRet as $arrVal) { |
---|
872 | $arrRecommendProducts['recommend_id' . $no] = $arrVal['recommend_product_id']; |
---|
873 | $arrRecommendProducts['recommend_comment' . $no] = $arrVal['comment']; |
---|
874 | $no++; |
---|
875 | } |
---|
876 | |
---|
877 | return $arrRecommendProducts; |
---|
878 | } |
---|
879 | |
---|
880 | /** |
---|
881 | * 関連商品データ表示用配列を取得する |
---|
882 | * |
---|
883 | * @param string $arrForm フォーム入力パラメーター配列 |
---|
884 | * @return array 関連商品データ配列 |
---|
885 | */ |
---|
886 | function lfGetRecommendProducts(&$arrForm) { |
---|
887 | $arrRecommend = array(); |
---|
888 | |
---|
889 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
890 | $keyname = "recommend_id" . $i; |
---|
891 | $delkey = "recommend_delete" . $i; |
---|
892 | $commentkey = "recommend_comment" . $i; |
---|
893 | |
---|
894 | if (!isset($arrForm[$delkey])) $arrForm[$delkey] = null; |
---|
895 | |
---|
896 | if((isset($arrForm[$keyname]) && !empty($arrForm[$keyname])) && $arrForm[$delkey] != 1) { |
---|
897 | $objProduct = new SC_Product_Ex(); |
---|
898 | $arrRecommend[$i] = $objProduct->getDetail($arrForm[$keyname]); |
---|
899 | $arrRecommend[$i]['product_id'] = $arrForm[$keyname]; |
---|
900 | $arrRecommend[$i]['comment'] = $arrForm[$commentkey]; |
---|
901 | } |
---|
902 | } |
---|
903 | return $arrRecommend; |
---|
904 | } |
---|
905 | |
---|
906 | /** |
---|
907 | * 表示用カテゴリマスターデータ配列を取得する |
---|
908 | * - 編集モード |
---|
909 | * |
---|
910 | * @param void |
---|
911 | * @return array カテゴリマスターデータ配列 |
---|
912 | */ |
---|
913 | function lfGetCategoryList_Edit() { |
---|
914 | $objDb = new SC_Helper_DB_Ex(); |
---|
915 | $arrCategoryList = array(); |
---|
916 | |
---|
917 | list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false); |
---|
918 | for ($i = 0; $i < count($arrCatVal); $i++) { |
---|
919 | $arrCategoryList[$arrCatVal[$i]] = $arrCatOut[$i]; |
---|
920 | } |
---|
921 | |
---|
922 | return $arrCategoryList; |
---|
923 | } |
---|
924 | |
---|
925 | /** |
---|
926 | * 入力フォームパラメーターの規格ありなしフラグを判定 |
---|
927 | * |
---|
928 | * @param string $has_product_class 入力フォームパラメーターの規格ありなしフラグ |
---|
929 | * @return boolean true: 規格あり, false: 規格なし |
---|
930 | */ |
---|
931 | function lfGetProductClassFlag($has_product_class) { |
---|
932 | if($has_product_class == '1') { |
---|
933 | return true; |
---|
934 | } else { |
---|
935 | return false; |
---|
936 | } |
---|
937 | } |
---|
938 | |
---|
939 | /** |
---|
940 | * ページonload用JavaScriptを取得する |
---|
941 | * - 入力画面 |
---|
942 | * |
---|
943 | * @param string $anchor_hash アンカー用ハッシュ文字列(省略可) |
---|
944 | * @return string ページonload用JavaScript |
---|
945 | */ |
---|
946 | function lfSetOnloadJavaScript_InputPage($anchor_hash = "") { |
---|
947 | return "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash; |
---|
948 | } |
---|
949 | |
---|
950 | /** |
---|
951 | * DBに商品データを登録する |
---|
952 | * |
---|
953 | * @param object $objUpFile SC_UploadFileインスタンス |
---|
954 | * @param object $objDownFile SC_UploadFileインスタンス |
---|
955 | * @param array $arrList フォーム入力パラメーター配列 |
---|
956 | * @return integer 登録商品ID |
---|
957 | */ |
---|
958 | function lfRegistProduct(&$objUpFile, &$objDownFile, $arrList) { |
---|
959 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
960 | $objDb = new SC_Helper_DB_Ex(); |
---|
961 | |
---|
962 | // 配列の添字を定義 |
---|
963 | $checkArray = array('name', 'status', |
---|
964 | "main_list_comment", "main_comment", |
---|
965 | "deliv_fee", "comment1", "comment2", "comment3", |
---|
966 | "comment4", "comment5", "comment6", "main_list_comment", |
---|
967 | "sale_limit", "deliv_date_id", "maker_id", 'note'); |
---|
968 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
---|
969 | |
---|
970 | // INSERTする値を作成する。 |
---|
971 | $sqlval['name'] = $arrList['name']; |
---|
972 | $sqlval['status'] = $arrList['status']; |
---|
973 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
974 | $sqlval['main_comment'] = $arrList['main_comment']; |
---|
975 | $sqlval['comment1'] = $arrList['comment1']; |
---|
976 | $sqlval['comment2'] = $arrList['comment2']; |
---|
977 | $sqlval['comment3'] = $arrList['comment3']; |
---|
978 | $sqlval['comment4'] = $arrList['comment4']; |
---|
979 | $sqlval['comment5'] = $arrList['comment5']; |
---|
980 | $sqlval['comment6'] = $arrList['comment6']; |
---|
981 | $sqlval['main_list_comment'] = $arrList['main_list_comment']; |
---|
982 | $sqlval['deliv_date_id'] = $arrList['deliv_date_id']; |
---|
983 | $sqlval['maker_id'] = $arrList['maker_id']; |
---|
984 | $sqlval['note'] = $arrList['note']; |
---|
985 | $sqlval['update_date'] = "Now()"; |
---|
986 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
987 | $arrRet = $objUpFile->getDBFileList(); |
---|
988 | $sqlval = array_merge($sqlval, $arrRet); |
---|
989 | |
---|
990 | for($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
991 | $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt]; |
---|
992 | $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt]; |
---|
993 | } |
---|
994 | |
---|
995 | $objQuery->begin(); |
---|
996 | |
---|
997 | // 新規登録(複製時を含む) |
---|
998 | if($arrList['product_id'] == "") { |
---|
999 | $product_id = $objQuery->nextVal("dtb_products_product_id"); |
---|
1000 | $sqlval['product_id'] = $product_id; |
---|
1001 | |
---|
1002 | // INSERTの実行 |
---|
1003 | $sqlval['create_date'] = "Now()"; |
---|
1004 | $objQuery->insert("dtb_products", $sqlval); |
---|
1005 | |
---|
1006 | $arrList['product_id'] = $product_id; |
---|
1007 | |
---|
1008 | // カテゴリを更新 |
---|
1009 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
1010 | |
---|
1011 | // 複製商品の場合には規格も複製する |
---|
1012 | if($arrList["copy_product_id"] != "" && SC_Utils_Ex::sfIsInt($arrList["copy_product_id"])) { |
---|
1013 | if($this->lfGetProductClassFlag($arrList["has_product_class"]) == false) { |
---|
1014 | //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う |
---|
1015 | $this->lfCopyProductClass($arrList, $objQuery); |
---|
1016 | } else { |
---|
1017 | //規格がある場合の複製は複製元の内容で追加登録を行う |
---|
1018 | // dtb_products_class のカラムを取得 |
---|
1019 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
1020 | $arrColList = $objQuery->listTableFields('dtb_products_class'); |
---|
1021 | $arrColList_tmp = array_flip($arrColList); |
---|
1022 | |
---|
1023 | // 複製しない列 |
---|
1024 | unset($arrColList[$arrColList_tmp["product_class_id"]]); //規格ID |
---|
1025 | unset($arrColList[$arrColList_tmp["product_id"]]); //商品ID |
---|
1026 | unset($arrColList[$arrColList_tmp["create_date"]]); |
---|
1027 | |
---|
1028 | // 複製元商品の規格データ取得 |
---|
1029 | $col = SC_Utils_Ex::sfGetCommaList($arrColList); |
---|
1030 | $table = 'dtb_products_class'; |
---|
1031 | $where = 'product_id = ?'; |
---|
1032 | $objQuery->setOrder('product_class_id'); |
---|
1033 | $arrProductsClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"])); |
---|
1034 | |
---|
1035 | // 複製元商品の規格組み合わせデータ登録 |
---|
1036 | // 登録した組み合わせIDを取得 |
---|
1037 | $arrRetCombinationId = $this->lfRegistClassCombination($arrProductsClass); |
---|
1038 | |
---|
1039 | // 規格データ登録 |
---|
1040 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
1041 | foreach($arrProductsClass as $arrData) { |
---|
1042 | $sqlval = array(); |
---|
1043 | $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
1044 | $sqlval['product_id'] = $product_id; |
---|
1045 | $sqlval['create_date'] = 'now()'; |
---|
1046 | $sqlval['class_combination_id'] = $arrRetCombinationId[$arrData['class_combination_id']]; |
---|
1047 | $sqlval['product_type_id'] = $arrData['product_type_id']; |
---|
1048 | $sqlval['product_code'] = $arrData['product_code']; |
---|
1049 | $sqlval['stock'] = $arrData['stock']; |
---|
1050 | $sqlval['stock_unlimited'] = $arrData['stock_unlimited']; |
---|
1051 | $sqlval['sale_limit'] = $arrData['sale_limit']; |
---|
1052 | $sqlval['price01'] = $arrData['price01']; |
---|
1053 | $sqlval['price02'] = $arrData['price02']; |
---|
1054 | $sqlval['deliv_fee'] = $arrData['deliv_fee']; |
---|
1055 | $sqlval['point_rate'] = $arrData['point_rate']; |
---|
1056 | $sqlval['creator_id'] = $arrData['creator_id']; |
---|
1057 | $sqlval['update_date'] = 'now()'; |
---|
1058 | $sqlval['down_filename'] = $arrData['down_filename']; |
---|
1059 | $sqlval['down_realfilename'] = $arrData['down_realfilename']; |
---|
1060 | $sqlval['del_flg'] = $arrData['del_flg']; |
---|
1061 | $objQuery->insert($table, $sqlval); |
---|
1062 | } |
---|
1063 | } |
---|
1064 | } |
---|
1065 | // 更新 |
---|
1066 | } else { |
---|
1067 | $product_id = $arrList['product_id']; |
---|
1068 | // 削除要求のあった既存ファイルの削除 |
---|
1069 | $arrRet = $this->lfGetProductData_FromDB($arrList['product_id']); |
---|
1070 | // TODO: SC_UploadFile::deleteDBFileの画像削除条件見直し要 |
---|
1071 | $objImage = new SC_Image_Ex($objUpFile->temp_dir); |
---|
1072 | $arrKeyName = $objUpFile->keyname; |
---|
1073 | $arrSaveFile = $objUpFile->save_file; |
---|
1074 | $arrImageKey = array(); |
---|
1075 | foreach ($arrKeyName as $key => $keyname) { |
---|
1076 | if ($arrRet[$keyname] && !$arrSaveFile[$key]) { |
---|
1077 | $arrImageKey[] = $keyname; |
---|
1078 | $has_same_image = $this->lfHasSameProductImage($arrList['product_id'], $arrImageKey, $arrRet[$keyname]); |
---|
1079 | if (!$has_same_image) { |
---|
1080 | $objImage->deleteImage($arrRet[$keyname], $objUpFile->save_dir); |
---|
1081 | } |
---|
1082 | } |
---|
1083 | } |
---|
1084 | $objDownFile->deleteDBDownFile($arrRet); |
---|
1085 | // UPDATEの実行 |
---|
1086 | $where = "product_id = ?"; |
---|
1087 | $objQuery->update("dtb_products", $sqlval, $where, array($product_id)); |
---|
1088 | |
---|
1089 | // カテゴリを更新 |
---|
1090 | $objDb->updateProductCategories($arrList['category_id'], $product_id); |
---|
1091 | } |
---|
1092 | |
---|
1093 | // 商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。 |
---|
1094 | if($arrList["copy_product_id"] == "") { |
---|
1095 | // 規格登録 |
---|
1096 | if ($objDb->sfHasProductClass($product_id)) { |
---|
1097 | // 規格あり商品(商品規格テーブルのうち、商品登録フォームで設定するパラメーターのみ更新) |
---|
1098 | $this->lfUpdateProductClass($arrList); |
---|
1099 | } else { |
---|
1100 | // 規格なし商品(商品規格テーブルの更新) |
---|
1101 | $this->lfInsertDummyProductClass($arrList); |
---|
1102 | } |
---|
1103 | } |
---|
1104 | |
---|
1105 | // ステータス設定 |
---|
1106 | $objProduct = new SC_Product_Ex(); |
---|
1107 | $objProduct->setProductStatus($product_id, $arrList['product_status']); |
---|
1108 | |
---|
1109 | // 関連商品登録 |
---|
1110 | $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id); |
---|
1111 | |
---|
1112 | $objQuery->commit(); |
---|
1113 | return $product_id; |
---|
1114 | } |
---|
1115 | |
---|
1116 | /** |
---|
1117 | * 規格を設定していない商品を商品規格テーブルに登録 |
---|
1118 | * |
---|
1119 | * @param array $arrList |
---|
1120 | * @return void |
---|
1121 | */ |
---|
1122 | function lfInsertDummyProductClass($arrList) { |
---|
1123 | $objQuery = new SC_Query_Ex(); |
---|
1124 | $objDb = new SC_Helper_DB_Ex(); |
---|
1125 | |
---|
1126 | $product_id = $arrList['product_id']; |
---|
1127 | |
---|
1128 | // 配列の添字を定義 |
---|
1129 | $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'); |
---|
1130 | $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray); |
---|
1131 | $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray); |
---|
1132 | |
---|
1133 | $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? UNLIMITED_FLG_UNLIMITED : UNLIMITED_FLG_LIMITED; |
---|
1134 | $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0'; |
---|
1135 | |
---|
1136 | if (strlen($sqlval['product_class_id']) == 0) { |
---|
1137 | $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
1138 | $sqlval['create_date'] = 'now()'; |
---|
1139 | $sqlval['update_date'] = 'now()'; |
---|
1140 | // INSERTの実行 |
---|
1141 | $objQuery->insert('dtb_products_class', $sqlval); |
---|
1142 | } else { |
---|
1143 | $sqlval['update_date'] = 'now()'; |
---|
1144 | // UPDATEの実行 |
---|
1145 | $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id'])); |
---|
1146 | |
---|
1147 | } |
---|
1148 | } |
---|
1149 | |
---|
1150 | /** |
---|
1151 | * 規格を設定している商品の商品規格テーブルを更新 |
---|
1152 | * (deliv_fee, point_rate, sale_limit) |
---|
1153 | * |
---|
1154 | * @param array $arrList |
---|
1155 | * @return void |
---|
1156 | */ |
---|
1157 | function lfUpdateProductClass($arrList) { |
---|
1158 | $objQuery = new SC_Query_Ex(); |
---|
1159 | $sqlval = array(); |
---|
1160 | |
---|
1161 | $sqlval['deliv_fee'] = $arrList['deliv_fee']; |
---|
1162 | $sqlval['point_rate'] = $arrList['point_rate']; |
---|
1163 | $sqlval['sale_limit'] = $arrList['sale_limit']; |
---|
1164 | $where = 'product_id = ?'; |
---|
1165 | $objQuery->update('dtb_products_class', $sqlval, $where, array($arrList['product_id'])); |
---|
1166 | } |
---|
1167 | |
---|
1168 | /** |
---|
1169 | * DBに関連商品データを登録する |
---|
1170 | * |
---|
1171 | * @param object $objQuery SC_Queryインスタンス |
---|
1172 | * @param string $arrList フォーム入力パラメーター配列 |
---|
1173 | * @param integer $product_id 登録する商品ID |
---|
1174 | * @return void |
---|
1175 | */ |
---|
1176 | function lfInsertRecommendProducts(&$objQuery, $arrList, $product_id) { |
---|
1177 | // 一旦関連商品をすべて削除する |
---|
1178 | $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id)); |
---|
1179 | $sqlval['product_id'] = $product_id; |
---|
1180 | $rank = RECOMMEND_PRODUCT_MAX; |
---|
1181 | for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { |
---|
1182 | $keyname = "recommend_id" . $i; |
---|
1183 | $commentkey = "recommend_comment" . $i; |
---|
1184 | $deletekey = "recommend_delete" . $i; |
---|
1185 | |
---|
1186 | if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null; |
---|
1187 | |
---|
1188 | if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') { |
---|
1189 | $sqlval['recommend_product_id'] = $arrList[$keyname]; |
---|
1190 | $sqlval['comment'] = $arrList[$commentkey]; |
---|
1191 | $sqlval['rank'] = $rank; |
---|
1192 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
1193 | $sqlval['create_date'] = "now()"; |
---|
1194 | $sqlval['update_date'] = "now()"; |
---|
1195 | $objQuery->insert("dtb_recommend_products", $sqlval); |
---|
1196 | $rank--; |
---|
1197 | } |
---|
1198 | } |
---|
1199 | } |
---|
1200 | |
---|
1201 | /** |
---|
1202 | * 規格データをコピーする |
---|
1203 | * |
---|
1204 | * @param array $arrList フォーム入力パラメーター配列 |
---|
1205 | * @param object $objQuery SC_Queryインスタンス |
---|
1206 | * @return boolean エラーフラグ |
---|
1207 | */ |
---|
1208 | function lfCopyProductClass($arrList, &$objQuery) { |
---|
1209 | // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得) |
---|
1210 | $col = "*"; |
---|
1211 | $table = "dtb_products_class"; |
---|
1212 | $where = "product_id = ?"; |
---|
1213 | $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"])); |
---|
1214 | |
---|
1215 | //トランザクション開始 |
---|
1216 | $objQuery->begin(); |
---|
1217 | $err_flag = false; |
---|
1218 | //非編集項目は複製、編集項目は上書きして登録 |
---|
1219 | foreach($arrProductClass as $records) { |
---|
1220 | foreach($records as $key => $value) { |
---|
1221 | if(isset($arrList[$key])) { |
---|
1222 | switch($key) { |
---|
1223 | case 'stock_unlimited': |
---|
1224 | $records[$key] = (int)$arrList[$key]; |
---|
1225 | break; |
---|
1226 | default: |
---|
1227 | $records[$key] = $arrList[$key]; |
---|
1228 | break; |
---|
1229 | } |
---|
1230 | } |
---|
1231 | } |
---|
1232 | |
---|
1233 | $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
1234 | $records["update_date"] = 'now()'; |
---|
1235 | $records["create_date"] = "Now()"; |
---|
1236 | $objQuery->insert($table, $records); |
---|
1237 | //エラー発生時は中断 |
---|
1238 | if($objQuery->isError()) { |
---|
1239 | $err_flag = true; |
---|
1240 | continue; |
---|
1241 | } |
---|
1242 | } |
---|
1243 | //トランザクション終了 |
---|
1244 | if($err_flag) { |
---|
1245 | $objQuery->rollback(); |
---|
1246 | } else { |
---|
1247 | $objQuery->commit(); |
---|
1248 | } |
---|
1249 | return !$err_flag; |
---|
1250 | } |
---|
1251 | |
---|
1252 | /** |
---|
1253 | * 商品規格データを元に、規格組み合わせデータを複製登録する |
---|
1254 | * |
---|
1255 | * @param array $arrProductsClass 商品規格データ配列 |
---|
1256 | * @return array 登録した規格組み合わせID配列 |
---|
1257 | */ |
---|
1258 | function lfRegistClassCombination($arrProductsClass) { |
---|
1259 | $arrRetCombinationId = array(); |
---|
1260 | |
---|
1261 | // 規格組み合わせデータを取得 |
---|
1262 | $arrClassCombination = $this->lfGetClassCombination($arrProductsClass); |
---|
1263 | |
---|
1264 | // 規格2を持っているかチェック |
---|
1265 | $has_class2 = $this->lfHasClass2($arrClassCombination); |
---|
1266 | |
---|
1267 | // 規格組み合わせデータを複製登録 |
---|
1268 | if($has_class2 == true) { |
---|
1269 | // 規格2を持っている場合、規格1の組み合わせデータも取得 |
---|
1270 | $arrClassCombinationParent = $this->lfGetClassCombination($arrClassCombination, true); |
---|
1271 | |
---|
1272 | // 親組み合わせデータを複製登録 |
---|
1273 | $arrRetCombinationId = $this->lfInsertClassCombination($arrClassCombinationParent); |
---|
1274 | // 子組み合わせデータを複製登録 |
---|
1275 | $arrRetCombinationId = $this->lfInsertClassCombination($arrClassCombination, $arrRetCombinationId); |
---|
1276 | } else { |
---|
1277 | // 規格1のみの場合、複製登録 |
---|
1278 | $arrRetCombinationId = $this->lfInsertClassCombination($arrClassCombination); |
---|
1279 | } |
---|
1280 | |
---|
1281 | return $arrRetCombinationId; |
---|
1282 | } |
---|
1283 | |
---|
1284 | /** |
---|
1285 | * 規格2を持っている規格組み合わせデータであるか判定する |
---|
1286 | * |
---|
1287 | * @param array $arrClassCombination 規格組み合わせデータ配列 |
---|
1288 | * @return boolean true: 規格2を持っている, false: 規格1のみ |
---|
1289 | */ |
---|
1290 | function lfHasClass2($arrClassCombination) { |
---|
1291 | $has_class2 = false; |
---|
1292 | |
---|
1293 | foreach($arrClassCombination as $arrVal) { |
---|
1294 | if($arrVal['level'] == '2') { |
---|
1295 | $has_class2 = true; |
---|
1296 | break; |
---|
1297 | } |
---|
1298 | } |
---|
1299 | |
---|
1300 | return $has_class2; |
---|
1301 | } |
---|
1302 | |
---|
1303 | /** |
---|
1304 | * 規格組み合わせデータを取得する |
---|
1305 | * |
---|
1306 | * @param array $arrData 組み合わせIDを含むデータ配列 |
---|
1307 | * @param boolean $is_parent 親規格IDから抽出するフラグ(省略時: false) |
---|
1308 | * @return array 規格組み合わせデータ配列 |
---|
1309 | */ |
---|
1310 | function lfGetClassCombination($arrData, $is_parent = false) { |
---|
1311 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
1312 | $key = 'class_combination_id'; |
---|
1313 | if($is_parent == true) { |
---|
1314 | $key = 'parent_class_combination_id'; |
---|
1315 | } |
---|
1316 | |
---|
1317 | $where = 'class_combination_id IN ('; |
---|
1318 | $arrParam = array(); |
---|
1319 | foreach($arrData as $arrVal) { |
---|
1320 | if(SC_Utils_Ex::isBlank($arrVal[$key]) == true) { |
---|
1321 | continue; |
---|
1322 | } |
---|
1323 | $where .= '?,'; |
---|
1324 | $arrParam[] = $arrVal[$key]; |
---|
1325 | } |
---|
1326 | $where = preg_replace('/,$/', ')', $where); |
---|
1327 | $arrClassCombination = $objQuery->select('*', 'dtb_class_combination', $where, $arrParam); |
---|
1328 | |
---|
1329 | return $arrClassCombination; |
---|
1330 | } |
---|
1331 | |
---|
1332 | /** |
---|
1333 | * 規格組み合わせデータを複製登録する |
---|
1334 | * |
---|
1335 | * @param array $arrClassCombination 複製元の規格組み合わせデータ配列 |
---|
1336 | * @param array $arrParentCombinationId 登録する親組み合わせID配列 (省略可) |
---|
1337 | * @return array 登録した規格組み合わせID配列 |
---|
1338 | */ |
---|
1339 | function lfInsertClassCombination($arrClassCombination, $arrParentCombinationId = array()) { |
---|
1340 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
1341 | $arrRetCombinationId = array(); |
---|
1342 | |
---|
1343 | // 親組み合わせIDの指定がある場合、指定された親組み合わせIDで複製登録 |
---|
1344 | if(count($arrParentCombinationId) > 0) { |
---|
1345 | foreach($arrClassCombination as $key => $arrVal) { |
---|
1346 | $arrClassCombination[$key]['parent_class_combination_id'] = $arrParentCombinationId[$arrVal['parent_class_combination_id']]; |
---|
1347 | } |
---|
1348 | } |
---|
1349 | |
---|
1350 | foreach($arrClassCombination as $arrVal) { |
---|
1351 | $sqlval = array(); |
---|
1352 | $sqlval['class_combination_id'] = $objQuery->nextVal('dtb_class_combination_class_combination_id'); |
---|
1353 | $sqlval['parent_class_combination_id'] = $arrVal['parent_class_combination_id']; |
---|
1354 | $sqlval['classcategory_id'] = $arrVal['classcategory_id']; |
---|
1355 | $sqlval['level'] = $arrVal['level']; |
---|
1356 | $objQuery->insert('dtb_class_combination', $sqlval); |
---|
1357 | |
---|
1358 | $arrRetCombinationId[$arrVal['class_combination_id']] = $sqlval['class_combination_id']; |
---|
1359 | } |
---|
1360 | |
---|
1361 | return $arrRetCombinationId; |
---|
1362 | } |
---|
1363 | |
---|
1364 | /** |
---|
1365 | * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける |
---|
1366 | * |
---|
1367 | * @param string $to_key |
---|
1368 | * @return string |
---|
1369 | */ |
---|
1370 | function lfGetAddSuffix($to_key){ |
---|
1371 | if( IMAGE_RENAME === true ) return ; |
---|
1372 | |
---|
1373 | // 自動生成される画像名 |
---|
1374 | $dist_name = ""; |
---|
1375 | switch($to_key) { |
---|
1376 | case "main_list_image": |
---|
1377 | $dist_name = '_s'; |
---|
1378 | break; |
---|
1379 | case "main_image": |
---|
1380 | $dist_name = '_m'; |
---|
1381 | break; |
---|
1382 | default: |
---|
1383 | $arrRet = explode('sub_image', $to_key); |
---|
1384 | $dist_name = '_sub' .$arrRet[1]; |
---|
1385 | break; |
---|
1386 | } |
---|
1387 | return $dist_name; |
---|
1388 | } |
---|
1389 | |
---|
1390 | /** |
---|
1391 | * サブ情報の登録があるかを取得する |
---|
1392 | * タイトル, コメント, 画像のいずれかに登録があれば「あり」と判定する |
---|
1393 | * |
---|
1394 | * @param array $arrSubProductData サブ情報配列 |
---|
1395 | * @return boolean true: サブ情報あり, false: サブ情報なし |
---|
1396 | */ |
---|
1397 | function hasSubProductData($arrSubProductData) { |
---|
1398 | $has_subproduct_data = false; |
---|
1399 | |
---|
1400 | for($i = 1; $i <= PRODUCTSUB_MAX; $i++) { |
---|
1401 | if(SC_Utils_Ex::isBlank($arrSubProductData['sub_title'.$i]) == false |
---|
1402 | || SC_Utils_Ex::isBlank($arrSubProductData['sub_comment'.$i]) == false |
---|
1403 | || SC_Utils_Ex::isBlank($arrSubProductData['sub_image'.$i]) == false |
---|
1404 | || SC_Utils_Ex::isBlank($arrSubProductData['sub_large_image'.$i]) == false |
---|
1405 | || SC_Utils_Ex::isBlank($arrSubProductData['temp_sub_image'.$i]) == false |
---|
1406 | || SC_Utils_Ex::isBlank($arrSubProductData['temp_sub_large_image'.$i]) == false) { |
---|
1407 | $has_subproduct_data = true; |
---|
1408 | break; |
---|
1409 | } |
---|
1410 | } |
---|
1411 | |
---|
1412 | return $has_subproduct_data; |
---|
1413 | } |
---|
1414 | |
---|
1415 | /** |
---|
1416 | * アンカーハッシュ文字列を取得する |
---|
1417 | * アンカーキーをサニタイジングする |
---|
1418 | * |
---|
1419 | * @param string $anchor_key フォーム入力パラメーターで受け取ったアンカーキー |
---|
1420 | * @return <type> |
---|
1421 | */ |
---|
1422 | function getAnchorHash($anchor_key) { |
---|
1423 | if($anchor_key != "") { |
---|
1424 | return "location.hash='#" . htmlspecialchars($anchor_key) . "'"; |
---|
1425 | } else { |
---|
1426 | return ""; |
---|
1427 | } |
---|
1428 | } |
---|
1429 | } |
---|
1430 | ?> |
---|