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_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * 商品登録(商品規格)のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Products_ProductClass extends LC_Page_Admin_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_class.tpl'; |
---|
47 | $this->tpl_subnavi = 'products/subnavi.tpl'; |
---|
48 | $this->tpl_mainno = 'products'; |
---|
49 | $this->tpl_subno = 'product'; |
---|
50 | $this->tpl_subtitle = '商品登録(商品規格)'; |
---|
51 | $masterData = new SC_DB_MasterData_Ex(); |
---|
52 | $this->arrProductType = $masterData->getMasterData("mtb_product_type"); |
---|
53 | // 規格プルダウンのリスト |
---|
54 | $this->arrClass = $this->getAllClass(); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Page のプロセス. |
---|
59 | * |
---|
60 | * @return void |
---|
61 | */ |
---|
62 | function process() { |
---|
63 | $this->action(); |
---|
64 | $this->sendResponse(); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Page のアクション. |
---|
69 | * |
---|
70 | * @return void |
---|
71 | */ |
---|
72 | function action() { |
---|
73 | // 商品マスタの検索条件パラメータを初期化 |
---|
74 | $objFormParam = new SC_FormParam_Ex(); |
---|
75 | $this->initParam($objFormParam); |
---|
76 | |
---|
77 | $objFormParam->setParam($_POST); |
---|
78 | $objFormParam->convParam(); |
---|
79 | |
---|
80 | $this->arrSearchHidden = $objFormParam->getSearchArray(); |
---|
81 | |
---|
82 | switch ($this->getMode()) { |
---|
83 | |
---|
84 | // 編集実行 |
---|
85 | case 'edit': |
---|
86 | $this->arrErr = $this->lfCheckProductsClass($objFormParam); |
---|
87 | |
---|
88 | // エラーの無い場合は確認画面を表示 |
---|
89 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
90 | $this->tpl_mainpage = 'products/product_class_confirm.tpl'; |
---|
91 | $this->doDisp($objFormParam); |
---|
92 | $objFormParam->setParam($_POST); |
---|
93 | $objFormParam->convParam(); |
---|
94 | } |
---|
95 | // エラーが発生した場合 |
---|
96 | else { |
---|
97 | $objFormParam->setParam($_POST); |
---|
98 | $objFormParam->convParam(); |
---|
99 | } |
---|
100 | break; |
---|
101 | |
---|
102 | // 削除 |
---|
103 | case 'delete': |
---|
104 | $this->doDelete($objFormParam->getValue('product_id')); |
---|
105 | $objFormParam->setValue('check', array()); |
---|
106 | break; |
---|
107 | |
---|
108 | // 初期表示 |
---|
109 | case 'pre_edit': |
---|
110 | $this->doPreEdit($objFormParam); |
---|
111 | break; |
---|
112 | |
---|
113 | // 「表示する」ボタン押下時 |
---|
114 | case 'disp': |
---|
115 | $this->arrErr = $this->lfCheckSelectClass(); |
---|
116 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
117 | $this->doDisp($objFormParam); |
---|
118 | // 登録チェックボックスはすべて初期化 |
---|
119 | $objFormParam->setValue('check', ''); |
---|
120 | } |
---|
121 | break; |
---|
122 | |
---|
123 | // ダウンロード商品ファイルアップロード |
---|
124 | case 'file_upload': |
---|
125 | $this->doFileUpload($objFormParam); |
---|
126 | break; |
---|
127 | |
---|
128 | // ダウンロードファイルの削除 |
---|
129 | case 'file_delete': |
---|
130 | $this->doFileDelete($objFormParam); |
---|
131 | break; |
---|
132 | |
---|
133 | // 確認画面からの戻り |
---|
134 | case 'confirm_return': |
---|
135 | $this->doPreEdit($objFormParam); |
---|
136 | $objFormParam->setParam($_POST); |
---|
137 | $objFormParam->convParam(); |
---|
138 | break; |
---|
139 | |
---|
140 | case 'complete': |
---|
141 | $this->tpl_mainpage = 'products/product_class_complete.tpl'; |
---|
142 | $this->doUploadComplete($objFormParam); |
---|
143 | $this->registerProductClass($objFormParam->getHashArray(), |
---|
144 | $objFormParam->getValue('product_id'), |
---|
145 | $objFormParam->getValue('total')); |
---|
146 | break; |
---|
147 | |
---|
148 | default: |
---|
149 | } |
---|
150 | |
---|
151 | // 登録対象の商品名を取得 |
---|
152 | $objFormParam->setValue('product_name', |
---|
153 | $this->getProductName($objFormParam->getValue('product_id'))); |
---|
154 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * デストラクタ. |
---|
159 | * |
---|
160 | * @return void |
---|
161 | */ |
---|
162 | function destroy() { |
---|
163 | parent::destroy(); |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * パラメータ初期化 |
---|
168 | * |
---|
169 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
170 | * @return void |
---|
171 | */ |
---|
172 | function initParam(&$objFormParam) { |
---|
173 | // 商品マスタ検索パラメータ引き継ぎ |
---|
174 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
175 | $objFormParam->addParam("カテゴリID", "category_id", STEXT_LEN, 'n', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
176 | $objFormParam->addParam("ページ送り番号","search_pageno", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
177 | $objFormParam->addParam("表示件数", "search_page_max", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
178 | $objFormParam->addParam("商品ID", "search_product_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
179 | $objFormParam->addParam("商品コード", "search_product_code", STEXT_LEN, 'KVna', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
180 | $objFormParam->addParam("商品名", "search_name", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
181 | $objFormParam->addParam("カテゴリ", "search_category_id", STEXT_LEN, 'n', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
182 | $objFormParam->addParam("種別", "search_status", INT_LEN, 'n', array("MAX_LENGTH_CHECK")); |
---|
183 | $objFormParam->addParam("開始年", "search_startyear", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
184 | $objFormParam->addParam("開始月", "search_startmonth", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
185 | $objFormParam->addParam("開始日", "search_startday", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
186 | $objFormParam->addParam("終了年", "search_endyear", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
187 | $objFormParam->addParam("終了月", "search_endmonth", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
188 | $objFormParam->addParam("終了日", "search_endday", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
189 | $objFormParam->addParam("ステータス", "search_product_flag", INT_LEN, 'n', array("MAX_LENGTH_CHECK")); |
---|
190 | |
---|
191 | // 規格プルダウン |
---|
192 | $objFormParam->addParam("規格1", "class_id1", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
193 | $objFormParam->addParam("規格2", "class_id2", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
194 | |
---|
195 | // 商品規格 |
---|
196 | $objFormParam->addParam("商品規格数", "total", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
197 | $objFormParam->addParam("商品名", "product_name", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
198 | $objFormParam->addParam("商品コード", "product_code", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
199 | $objFormParam->addParam("規格ID1", "classcategory_id1", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
200 | $objFormParam->addParam("規格ID2", "classcategory_id2", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
201 | $objFormParam->addParam("規格名1", "classcategory_name1", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
202 | $objFormParam->addParam("規格名2", "classcategory_name2", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
203 | $objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
204 | $objFormParam->addParam("在庫数", "stock", AMOUNT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
205 | $objFormParam->addParam("在庫数", "stock_unlimited", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
206 | $objFormParam->addParam(NORMAL_PRICE_TITLE, "price01", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
207 | $objFormParam->addParam(SALE_PRICE_TITLE, "price02", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
208 | $objFormParam->addParam("商品種別", "product_type_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
209 | $objFormParam->addParam("削除フラグ", "del_flg", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
210 | $objFormParam->addParam("ダウンロード販売用ファイル名", "down_filename", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
211 | $objFormParam->addParam("ダウンロード販売用ファイル名", "down_realfilename", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
212 | $objFormParam->addParam("チェックボックス", "check", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
213 | $objFormParam->addParam("ファイルアップロード用キー", "upload_index", STEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | * 規格の登録または更新を行う. |
---|
218 | * |
---|
219 | * TODO dtb_class_combination は, dtb_product_categories に倣って, |
---|
220 | * DELETE to INSERT だが, UPDATE を検討する. |
---|
221 | * |
---|
222 | * @param array $arrList 入力フォームの内容 |
---|
223 | * @param integer $product_id 登録を行う商品ID |
---|
224 | */ |
---|
225 | function registerProductClass($arrList, $product_id, $total) { |
---|
226 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
227 | $objDb = new SC_Helper_DB_Ex(); |
---|
228 | |
---|
229 | $objQuery->begin(); |
---|
230 | |
---|
231 | $arrProductsClass = $objQuery->select("*", "dtb_products_class", "product_id = ?", array($product_id)); |
---|
232 | $arrExists = array(); |
---|
233 | foreach ($arrProductsClass as $val) { |
---|
234 | $arrExists[$val['product_class_id']] = $val; |
---|
235 | } |
---|
236 | |
---|
237 | // デフォルト値として設定する値を取得しておく |
---|
238 | $arrDefault = $this->getProductsClass($product_id); |
---|
239 | |
---|
240 | for ($i = 0; $i < $total; $i++) { |
---|
241 | $del_flg = SC_Utils_Ex::isBlank($arrList['check'][$i]) ? 1 : 0; |
---|
242 | $stock_unlimited = SC_Utils_Ex::isBlank($arrList['stock_unlimited'][$i]) ? 0 : 1; |
---|
243 | $price02 = SC_Utils_Ex::isBlank($arrList['price02'][$i]) ? 0 : $arrList['price02'][$i]; |
---|
244 | // dtb_products_class 登録/更新用 |
---|
245 | $registerKeys = array('product_code', 'stock', |
---|
246 | 'price01', 'product_type_id', |
---|
247 | 'down_filename', 'down_realfilename'); |
---|
248 | |
---|
249 | $arrPC = array(); |
---|
250 | foreach ($registerKeys as $key) { |
---|
251 | if ($del_flg === 0) { |
---|
252 | $arrPC[$key] = $arrList[$key][$i]; |
---|
253 | } |
---|
254 | } |
---|
255 | $arrPC['product_id'] = $product_id; |
---|
256 | $arrPC['sale_limit'] = $arrDefault['sale_limit']; |
---|
257 | $arrPC['deliv_fee'] = $arrDefault['deliv_fee']; |
---|
258 | $arrPC['point_rate'] = $arrDefault['point_rate']; |
---|
259 | $arrPC['stock_unlimited'] = $stock_unlimited; |
---|
260 | $arrPC['price02'] = $price02; |
---|
261 | |
---|
262 | // 該当関数が無いため, セッションの値を直接代入 |
---|
263 | $arrPC['creator_id'] = $_SESSION['member_id']; |
---|
264 | $arrPC['update_date'] = 'now()'; |
---|
265 | $arrPC['del_flg'] = $del_flg; |
---|
266 | |
---|
267 | // 登録 or 更新 |
---|
268 | $is_update = false; |
---|
269 | if (!SC_Utils_Ex::isBlank($arrList['product_class_id'][$i])) { |
---|
270 | $is_update = true; |
---|
271 | |
---|
272 | // 更新の場合は規格組み合わせを検索し, 削除しておく |
---|
273 | $class_combination_id = $arrExists[$arrList['product_class_id'][$i]]['class_combination_id']; |
---|
274 | $existsCombi = $objQuery->getRow( |
---|
275 | '*', |
---|
276 | 'dtb_class_combination', |
---|
277 | 'class_combination_id = ?', |
---|
278 | array($class_combination_id)); |
---|
279 | |
---|
280 | $objQuery->delete('dtb_class_combination', |
---|
281 | 'class_combination_id IN (?, ?)', |
---|
282 | array($existsCombi['class_combination_id'], |
---|
283 | $existsCombi['parent_class_combination_id'])); |
---|
284 | } |
---|
285 | |
---|
286 | // 規格組み合わせを登録 |
---|
287 | $arrComb1['class_combination_id'] = $objQuery->nextVal('dtb_class_combination_class_combination_id'); |
---|
288 | $arrComb1['classcategory_id'] = $arrList['classcategory_id1'][$i]; |
---|
289 | $arrComb1['level'] = 1; |
---|
290 | $objQuery->insert('dtb_class_combination', $arrComb1); |
---|
291 | |
---|
292 | // 規格2も登録する場合 |
---|
293 | if (!SC_Utils_Ex::isBlank($arrList['classcategory_id2'][$i])) { |
---|
294 | $arrComb2['class_combination_id'] = $objQuery->nextVal('dtb_class_combination_class_combination_id'); |
---|
295 | $arrComb2['classcategory_id'] = $arrList['classcategory_id2'][$i]; |
---|
296 | $arrComb2['parent_class_combination_id'] = $arrComb1['class_combination_id']; |
---|
297 | $arrComb2['level'] = 2; |
---|
298 | $objQuery->insert('dtb_class_combination', $arrComb2); |
---|
299 | |
---|
300 | $arrPC['class_combination_id'] = $arrComb2['class_combination_id']; |
---|
301 | } else { |
---|
302 | $arrPC['class_combination_id'] = $arrComb1['class_combination_id']; |
---|
303 | } |
---|
304 | |
---|
305 | // 更新 |
---|
306 | if ($is_update) { |
---|
307 | $arrPC['product_class_id'] = $arrList['product_class_id'][$i]; |
---|
308 | $objQuery->update("dtb_products_class", $arrPC, |
---|
309 | "product_class_id = ?", |
---|
310 | array($arrPC['product_class_id'])); |
---|
311 | } |
---|
312 | // 新規登録 |
---|
313 | else { |
---|
314 | $arrPC['create_date'] = "now()"; |
---|
315 | $arrPC['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id'); |
---|
316 | /* |
---|
317 | * チェックを入れない商品は product_type_id が NULL になるので, 0 を入れる |
---|
318 | */ |
---|
319 | $arrPC['product_type_id'] = SC_Utils_Ex::isBlank($arrPC['product_type_id']) ? 0 : $arrPC['product_type_id']; |
---|
320 | $objQuery->insert("dtb_products_class", $arrPC); |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | // 規格無し用の商品規格を非表示に |
---|
325 | $arrBlank['del_flg'] = 1; |
---|
326 | $arrBlank['update_date'] = 'now()'; |
---|
327 | $objQuery->update("dtb_products_class", $arrBlank, |
---|
328 | "product_id = ? AND class_combination_id IS NULL", |
---|
329 | array($product_id)); |
---|
330 | |
---|
331 | // 件数カウントバッチ実行 |
---|
332 | $objDb->sfCountCategory($objQuery); |
---|
333 | $objQuery->commit(); |
---|
334 | } |
---|
335 | |
---|
336 | /** |
---|
337 | * 規格選択エラーチェックを行う |
---|
338 | * |
---|
339 | * ※SC_FormParamで対応していないエラーチェックのため, SC_CheckErrorを使用している. |
---|
340 | * |
---|
341 | * @return array エラーの配列 |
---|
342 | */ |
---|
343 | function lfCheckSelectClass() { |
---|
344 | $objErr = new SC_CheckError_Ex(); |
---|
345 | $objErr->doFunc(array("規格1", "class_id1"), array("EXIST_CHECK")); |
---|
346 | $objErr->doFunc(array("規格", "class_id1", "select_class_id2"), array("TOP_EXIST_CHECK")); |
---|
347 | $objErr->doFunc(array("規格1", "規格2", "class_id1", "class_id2"), array("DIFFERENT_CHECK")); |
---|
348 | return $objErr->arrErr; |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | * 商品規格エラーチェック. |
---|
353 | * |
---|
354 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
355 | * @return array エラー結果の配列 |
---|
356 | */ |
---|
357 | function lfCheckProductsClass(&$objFormParam) { |
---|
358 | $arrValues = $objFormParam->getHashArray(); |
---|
359 | $arrErr = $objFormParam->checkError(); |
---|
360 | $total = $objFormParam->getValue('total'); |
---|
361 | |
---|
362 | if (SC_Utils_Ex::isBlank($arrValues['check'])) { |
---|
363 | $arrErr['check_empty'] = '※ 商品種別が選択されていません。<br />'; |
---|
364 | } |
---|
365 | |
---|
366 | for ($i = 0; $i < $total; $i++) { |
---|
367 | |
---|
368 | /* |
---|
369 | * チェックボックスの入っている項目のみ, 必須チェックを行う. |
---|
370 | * エラーを配列で返す必要があるため, SC_CheckError を使用しない. |
---|
371 | */ |
---|
372 | if (!SC_Utils_Ex::isBlank($arrValues['check'][$i])) { |
---|
373 | |
---|
374 | /* |
---|
375 | * 販売価格の必須チェック |
---|
376 | */ |
---|
377 | if (SC_Utils_Ex::isBlank($arrValues['price02'][$i])) { |
---|
378 | $arrErr['price02'][$i] = '※ ' . SALE_PRICE_TITLE . 'が入力されていません。<br />'; |
---|
379 | } |
---|
380 | /* |
---|
381 | * 在庫数の必須チェック |
---|
382 | */ |
---|
383 | if ((SC_Utils_Ex::isBlank($arrValues['stock_unlimited'][$i]) |
---|
384 | || $arrValues['stock_unlimited'][$i] != 1) |
---|
385 | |
---|
386 | && SC_Utils_Ex::isBlank($arrValues['stock'][$i])) { |
---|
387 | $arrErr['stock'][$i] = '※ 在庫数が入力されていません。<br />'; |
---|
388 | } |
---|
389 | /* |
---|
390 | * 商品種別の必須チェック |
---|
391 | */ |
---|
392 | if (SC_Utils_Ex::isBlank($arrValues['product_type_id'][$i])) { |
---|
393 | $arrErr['product_type_id'][$i] = "※ 商品種別は、いずれかを選択してください。<br />"; |
---|
394 | } |
---|
395 | /* |
---|
396 | * ダウンロード商品の必須チェック |
---|
397 | */ |
---|
398 | if($arrValues['product_type_id'][$i] == PRODUCT_TYPE_DOWNLOAD) { |
---|
399 | if (SC_Utils_Ex::isBlank($arrValues['down_filename'][$i])) { |
---|
400 | $arrErr['down_filename'][$i] = "※ ダウンロード商品の場合はダウンロードファイル名を入力してください。<br />"; |
---|
401 | } |
---|
402 | if (SC_Utils_Ex::isBlank($arrValues['down_realfilename'][$i])) { |
---|
403 | $arrErr['down_realfilename'][$i] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />"; |
---|
404 | } |
---|
405 | } |
---|
406 | /* |
---|
407 | * 通常商品チェック |
---|
408 | */ |
---|
409 | else if ($arrValues['product_type_id'][$i] == PRODUCT_TYPE_NORMAL) { |
---|
410 | if (!SC_Utils_Ex::isBlank($arrValues['down_filename'][$i])) { |
---|
411 | $arrErr['down_filename'][$i] = "※ 通常商品の場合はダウンロードファイル名を設定できません。<br />"; |
---|
412 | } |
---|
413 | if (!SC_Utils_Ex::isBlank($arrValues['down_realfilename'][$i])) { |
---|
414 | $arrErr['down_realfilename'][$i] = "※ 実商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />"; |
---|
415 | } |
---|
416 | } |
---|
417 | } |
---|
418 | } |
---|
419 | return $arrErr; |
---|
420 | } |
---|
421 | |
---|
422 | /** |
---|
423 | * 規格の組み合わせ一覧を表示する. |
---|
424 | * |
---|
425 | * 規格1, 規格2における規格分類のすべての組み合わせを取得し, |
---|
426 | * 該当商品の商品規格の内容を取得後, フォームに設定する. |
---|
427 | * |
---|
428 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
429 | * @return void |
---|
430 | */ |
---|
431 | function doDisp(&$objFormParam) { |
---|
432 | $product_id = $objFormParam->getValue('product_id'); |
---|
433 | $class_id1 = $objFormParam->getValue('class_id1'); |
---|
434 | $class_id2 = $objFormParam->getValue('class_id2'); |
---|
435 | |
---|
436 | // すべての組み合わせを取得し, フォームに設定 |
---|
437 | $arrClassCat = $this->getAllClassCategory($class_id1, $class_id2); |
---|
438 | $total = count($arrClassCat); |
---|
439 | $objFormParam->setValue('total', $total); |
---|
440 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrClassCat)); |
---|
441 | |
---|
442 | // class_id1, class_id2 を, 入力値で上書き |
---|
443 | $objFormParam->setValue('class_id1', $class_id1); |
---|
444 | $objFormParam->setValue('class_id2', $class_id2); |
---|
445 | |
---|
446 | // 商品情報を取得し, フォームに設定 |
---|
447 | $arrProductsClass = $this->getProductsClass($product_id); |
---|
448 | |
---|
449 | foreach ($arrProductsClass as $key => $val) { |
---|
450 | // 組み合わせ数分の値の配列を生成する |
---|
451 | $arrValues = array(); |
---|
452 | for ($i = 0; $i < $total; $i++) { |
---|
453 | $arrValues[] = $val; |
---|
454 | } |
---|
455 | $objFormParam->setValue($key, $arrValues); |
---|
456 | } |
---|
457 | |
---|
458 | // 商品種別を 1 に初期化 |
---|
459 | $objFormParam->setValue('product_type_id', array_pad(array(), $total, 1)); |
---|
460 | } |
---|
461 | |
---|
462 | /** |
---|
463 | * 規格編集画面を表示する |
---|
464 | * |
---|
465 | * @param integer $product_id 商品ID |
---|
466 | * @param bool $existsValue |
---|
467 | * @param bool $usepostValue |
---|
468 | */ |
---|
469 | function doPreEdit(&$objFormParam) { |
---|
470 | $product_id = $objFormParam->getValue('product_id'); |
---|
471 | $objProduct = new SC_Product_Ex(); |
---|
472 | $existsProductsClass = $objProduct->getProductsClassFullByProductId($product_id, true); |
---|
473 | |
---|
474 | $class_id1 = $existsProductsClass[0]['class_id1']; |
---|
475 | $class_id2 = $existsProductsClass[0]['class_id2']; |
---|
476 | $objFormParam->setValue('class_id1', $class_id1); |
---|
477 | $objFormParam->setValue('class_id2', $class_id2); |
---|
478 | $this->doDisp($objFormParam); |
---|
479 | |
---|
480 | // 登録済みのデータで上書き |
---|
481 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($existsProductsClass)); |
---|
482 | |
---|
483 | // $existsProductsClass で product_id が配列になってしまうため数値で上書き |
---|
484 | $objFormParam->setValue('product_id', $product_id); |
---|
485 | |
---|
486 | // check を設定 |
---|
487 | $arrChecks = array(); |
---|
488 | $index = 0; |
---|
489 | foreach ($objFormParam->getValue('del_flg') as $key => $val) { |
---|
490 | if ($val == 0) { |
---|
491 | $arrChecks[$index] = 1; |
---|
492 | } |
---|
493 | $index++; |
---|
494 | } |
---|
495 | $objFormParam->setValue('check', $arrChecks); |
---|
496 | |
---|
497 | // class_id1, class_id2 を取得値で上書き |
---|
498 | $objFormParam->setValue('class_id1', $class_id1); |
---|
499 | $objFormParam->setValue('class_id2', $class_id2); |
---|
500 | } |
---|
501 | |
---|
502 | /** |
---|
503 | * 規格の削除を実行する |
---|
504 | * |
---|
505 | * @param $product_id |
---|
506 | * @return void |
---|
507 | */ |
---|
508 | function doDelete($product_id) { |
---|
509 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
510 | |
---|
511 | $objQuery->begin(); |
---|
512 | $objQuery->update("dtb_products_class", array('del_flg' => 0), |
---|
513 | "product_id = ? AND class_combination_id IS NULL", array($product_id)); |
---|
514 | $objQuery->update("dtb_products_class", array('del_flg' => 1), |
---|
515 | "product_id = ? AND class_combination_id IS NOT NULL", array($product_id)); |
---|
516 | $objQuery->commit(); |
---|
517 | |
---|
518 | // 在庫無し商品の非表示対応 |
---|
519 | if (NOSTOCK_HIDDEN === true) { |
---|
520 | // 件数カウントバッチ実行 |
---|
521 | $objDb = new SC_Helper_DB_Ex(); |
---|
522 | $objDb->sfCountCategory($objQuery); |
---|
523 | } |
---|
524 | } |
---|
525 | |
---|
526 | /** |
---|
527 | * ファイルアップロードを行う. |
---|
528 | * |
---|
529 | * 以下のチェックを行い, ファイルを一時領域へアップロードする. |
---|
530 | * 1. ファイルサイズチェック |
---|
531 | * 2. 拡張子チェック |
---|
532 | * |
---|
533 | * TODO |
---|
534 | * SC_CheckError クラスや, SC_UploadFile クラスが多次元配列に対応して |
---|
535 | * いないため, 独自のロジックを使用している. |
---|
536 | * |
---|
537 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
538 | * @return void |
---|
539 | */ |
---|
540 | function doFileUpload(&$objFormParam) { |
---|
541 | $index = $objFormParam->getValue('upload_index'); |
---|
542 | $arrDownRealFiles = $objFormParam->getValue('down_realfilename'); |
---|
543 | |
---|
544 | if ($_FILES['down_realfilename']['size'][$index] <= 0) { |
---|
545 | $this->arrErr['down_realfilename'][$index] = '※ ファイルがアップロードされていません'; |
---|
546 | } else if ($_FILES['down_realfilename']['size'][$index] > DOWN_SIZE * 1024 ) { |
---|
547 | $size = DOWN_SIZE; |
---|
548 | $byte = 'KB'; |
---|
549 | if ($size >= 1000) { |
---|
550 | $size = $size / 1000; |
---|
551 | $byte = 'MB'; |
---|
552 | } |
---|
553 | $this->arrErr['down_realfilename'][$index] = "※ ダウンロード販売用ファイル名のファイルサイズは" . $size . $byte . "以下のものを使用してください。<br />"; |
---|
554 | } else { |
---|
555 | $array_ext = explode(".", $_FILES['down_realfilename']['name'][$index]); |
---|
556 | $is_error = true; |
---|
557 | $strExt = ""; |
---|
558 | |
---|
559 | foreach (explode(",", DOWNLOAD_EXTENSION) as $checkExt ) { |
---|
560 | $ext = ""; |
---|
561 | // チェック拡張子のピリオドの数を取得('tar.gz'の場合1個、'jpg'のように通常は0個) |
---|
562 | $count_period = substr_count($checkExt, "."); |
---|
563 | if($count_period > 0) { |
---|
564 | for ($i = max(array_keys($array_ext)) - $count_period; $i < count($array_ext); $i++) { |
---|
565 | $ext .= $array_ext[$i] . "."; |
---|
566 | } |
---|
567 | $ext = preg_replace("/.$/", "" ,$ext); |
---|
568 | } else { |
---|
569 | $ext = $array_ext[ count ( $array_ext ) - 1 ]; |
---|
570 | } |
---|
571 | $ext = strtolower($ext); |
---|
572 | |
---|
573 | if ($ext == $checkExt) { |
---|
574 | $is_error = false; |
---|
575 | } |
---|
576 | if($strExt == "") { |
---|
577 | $strExt .= $checkExt; |
---|
578 | } else { |
---|
579 | $strExt .= "・$checkExt"; |
---|
580 | } |
---|
581 | } |
---|
582 | if ($is_error) { |
---|
583 | $this->arrErr['down_realfilename'][$index] = "※ ダウンロード販売用ファイル名で許可されている形式は、" . $strExt . "です。<br />"; |
---|
584 | } |
---|
585 | |
---|
586 | $uniqname = date('mdHi') . "_" . uniqid("")."."; |
---|
587 | $temp_file = preg_replace("/^.*\./", $uniqname, $_FILES['down_realfilename']['name'][$index]); |
---|
588 | |
---|
589 | if (move_uploaded_file($_FILES['down_realfilename']['tmp_name'][$index], DOWN_TEMP_REALDIR . $temp_file)) { |
---|
590 | $arrDownRealFiles[$index] = $temp_file; |
---|
591 | $objFormParam->setValue('down_realfilename', $arrDownRealFiles); |
---|
592 | GC_Utils_Ex::gfPrintLog($_FILES['down_realfilename']['name'][$index] ." -> ". realpath(DOWN_TEMP_REALDIR . $temp_file)); |
---|
593 | } else { |
---|
594 | $objErr->arrErr[$keyname] = '※ ファイルのアップロードに失敗しました。<br />'; |
---|
595 | GC_Utils_Ex::gfPrintLog('File Upload Error!: ' . $_FILES['down_realfilename']['name'][$index] . " -> " . DOWN_TEMP_REALDIR . $temp_file); |
---|
596 | } |
---|
597 | } |
---|
598 | } |
---|
599 | |
---|
600 | /** |
---|
601 | * アップロードしたファイルを削除する. |
---|
602 | * |
---|
603 | * TODO 一時ファイルの削除 |
---|
604 | * |
---|
605 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
606 | * @return void |
---|
607 | */ |
---|
608 | function doFileDelete(&$objFormParam) { |
---|
609 | $objImage = new SC_Image_Ex(DOWN_TEMP_REALDIR); |
---|
610 | $arrRealFileName = $objFormParam->getValue('down_realfilename'); |
---|
611 | $index = $objFormParam->getValue('upload_index'); |
---|
612 | $objImage->deleteImage($arrRealFileName[$index], DOWN_SAVE_REALDIR); |
---|
613 | $arrRealFileName[$index] = ''; |
---|
614 | $objFormParam->setValue('down_realfilename', $arrRealFileName); |
---|
615 | } |
---|
616 | |
---|
617 | /** |
---|
618 | * アップロードした一時ファイルを保存する. |
---|
619 | * |
---|
620 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
621 | * @return void |
---|
622 | */ |
---|
623 | function doUploadComplete(&$objFormParam) { |
---|
624 | $objImage = new SC_Image_Ex(DOWN_TEMP_REALDIR); |
---|
625 | $arrRealFileName = $objFormParam->getValue('down_realfilename'); |
---|
626 | foreach ($arrRealFileName as $real_file_name) { |
---|
627 | $objImage->moveTempImage($real_file_name, DOWN_SAVE_REALDIR); |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | /** |
---|
632 | * 規格ID1, 規格ID2の規格分類すべてを取得する. |
---|
633 | * |
---|
634 | * @param integer $class_id1 規格ID1 |
---|
635 | * @param integer $class_id2 規格ID2 |
---|
636 | * @return array 規格と規格分類の配列 |
---|
637 | */ |
---|
638 | function getAllClassCategory($class_id1, $class_id2 = null) { |
---|
639 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
640 | |
---|
641 | $col = <<< __EOF__ |
---|
642 | T1.class_id AS class_id1, |
---|
643 | T1.classcategory_id AS classcategory_id1, |
---|
644 | T1.name AS classcategory_name1, |
---|
645 | T1.rank AS rank1 |
---|
646 | __EOF__; |
---|
647 | $table = ''; |
---|
648 | $arrParams = array(); |
---|
649 | if(SC_Utils_Ex::isBlank($class_id2)) { |
---|
650 | $table = "dtb_classcategory T1 "; |
---|
651 | $objQuery->setWhere("T1.class_id = ?"); |
---|
652 | $objQuery->setOrder("T1.rank DESC"); |
---|
653 | $arrParams = array($class_id1); |
---|
654 | } else { |
---|
655 | $col .= <<< __EOF__ |
---|
656 | , |
---|
657 | T2.class_id AS class_id2, |
---|
658 | T2.classcategory_id AS classcategory_id2, |
---|
659 | T2.name AS classcategory_name2, |
---|
660 | T2.rank AS rank2 |
---|
661 | __EOF__; |
---|
662 | $table = "dtb_classcategory AS T1, dtb_classcategory AS T2"; |
---|
663 | $objQuery->setWhere("T1.class_id = ? AND T2.class_id = ?"); |
---|
664 | $objQuery->setOrder("T1.rank DESC, T2.rank DESC"); |
---|
665 | $arrParams = array($class_id1, $class_id2); |
---|
666 | } |
---|
667 | return $objQuery->select($col, $table, "", $arrParams); |
---|
668 | } |
---|
669 | |
---|
670 | /** |
---|
671 | * 商品名を取得する. |
---|
672 | * |
---|
673 | * @access private |
---|
674 | * @param integer $product_id 商品ID |
---|
675 | * @return string 商品名の文字列 |
---|
676 | */ |
---|
677 | function getProductName($product_id) { |
---|
678 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
679 | return $objQuery->get('name', 'dtb_products', 'product_id = ?', array($product_id)); |
---|
680 | } |
---|
681 | |
---|
682 | /** |
---|
683 | * 規格分類の登録された, すべての規格を取得する. |
---|
684 | * |
---|
685 | * @access private |
---|
686 | * @return array 規格分類の登録された, すべての規格 |
---|
687 | */ |
---|
688 | function getAllClass() { |
---|
689 | $arrClass = SC_Helper_DB_Ex::sfGetIDValueList("dtb_class", 'class_id', 'name'); |
---|
690 | |
---|
691 | // 規格分類が登録されていない規格は表示しないようにする。 |
---|
692 | $arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount(); |
---|
693 | |
---|
694 | $results = array(); |
---|
695 | if (!SC_Utils_Ex::isBlank($arrClass)) { |
---|
696 | foreach($arrClass as $key => $val) { |
---|
697 | if($arrClassCatCount[$key] > 0) { |
---|
698 | $results[$key] = $arrClass[$key]; |
---|
699 | } |
---|
700 | } |
---|
701 | } |
---|
702 | return $results; |
---|
703 | } |
---|
704 | |
---|
705 | /** |
---|
706 | * 商品IDをキーにして, 商品規格の初期値を取得する. |
---|
707 | * |
---|
708 | * 商品IDをキーにし, デフォルトに設定されている商品規格を取得する. |
---|
709 | * |
---|
710 | * @param integer $product_id 商品ID |
---|
711 | * @return array 商品規格の配列 |
---|
712 | */ |
---|
713 | function getProductsClass($product_id) { |
---|
714 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
715 | $col = "product_code, price01, price02, stock, stock_unlimited, sale_limit, deliv_fee, point_rate"; |
---|
716 | return $objQuery->getRow($col, "dtb_products_class", "product_id = ? AND class_combination_id IS NULL", array($product_id)); |
---|
717 | } |
---|
718 | } |
---|