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/order/LC_Page_Admin_Order_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * 受注修正 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Order_Edit extends LC_Page_Admin_Order_Ex { |
---|
35 | |
---|
36 | var $arrShippingKeys = array( |
---|
37 | 'shipping_id', |
---|
38 | 'shipping_name01', |
---|
39 | 'shipping_name02', |
---|
40 | 'shipping_kana01', |
---|
41 | 'shipping_kana02', |
---|
42 | 'shipping_tel01', |
---|
43 | 'shipping_tel02', |
---|
44 | 'shipping_tel03', |
---|
45 | 'shipping_fax01', |
---|
46 | 'shipping_fax02', |
---|
47 | 'shipping_fax03', |
---|
48 | 'shipping_pref', |
---|
49 | 'shipping_zip01', |
---|
50 | 'shipping_zip02', |
---|
51 | 'shipping_addr01', |
---|
52 | 'shipping_addr02', |
---|
53 | 'shipping_date_year', |
---|
54 | 'shipping_date_month', |
---|
55 | 'shipping_date_day', |
---|
56 | 'time_id', |
---|
57 | ); |
---|
58 | |
---|
59 | var $arrShipmentItemKeys = array( |
---|
60 | 'shipment_product_class_id', |
---|
61 | 'shipment_product_code', |
---|
62 | 'shipment_product_name', |
---|
63 | 'shipment_classcategory_name1', |
---|
64 | 'shipment_classcategory_name2', |
---|
65 | 'shipment_price', |
---|
66 | 'shipment_quantity', |
---|
67 | ); |
---|
68 | |
---|
69 | // }}} |
---|
70 | // {{{ functions |
---|
71 | |
---|
72 | /** |
---|
73 | * Page を初期化する. |
---|
74 | * |
---|
75 | * @return void |
---|
76 | */ |
---|
77 | function init() { |
---|
78 | parent::init(); |
---|
79 | $this->tpl_mainpage = 'order/edit.tpl'; |
---|
80 | $this->tpl_mainno = 'order'; |
---|
81 | $this->tpl_maintitle = '受注管理'; |
---|
82 | $this->tpl_subtitle = '受注登録'; |
---|
83 | |
---|
84 | $masterData = new SC_DB_MasterData_Ex(); |
---|
85 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
86 | $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status"); |
---|
87 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
88 | |
---|
89 | $objDate = new SC_Date_Ex(RELEASE_YEAR); |
---|
90 | $this->arrYearShippingDate = $objDate->getYear('', date('Y'), ''); |
---|
91 | $this->arrMonthShippingDate = $objDate->getMonth(true); |
---|
92 | $this->arrDayShippingDate = $objDate->getDay(true); |
---|
93 | |
---|
94 | // 支払い方法の取得 |
---|
95 | $this->arrPayment = SC_Helper_DB_Ex::sfGetIDValueList("dtb_payment", "payment_id", "payment_method"); |
---|
96 | |
---|
97 | // 配送業者の取得 |
---|
98 | $this->arrDeliv = SC_Helper_DB_Ex::sfGetIDValueList("dtb_deliv", "deliv_id", 'name'); |
---|
99 | |
---|
100 | $this->httpCacheControl('nocache'); |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * Page のプロセス. |
---|
105 | * |
---|
106 | * @return void |
---|
107 | */ |
---|
108 | function process() { |
---|
109 | $this->action(); |
---|
110 | $this->sendResponse(); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * Page のアクション. |
---|
115 | * |
---|
116 | * @return void |
---|
117 | */ |
---|
118 | function action() { |
---|
119 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
120 | $objFormParam = new SC_FormParam_Ex(); |
---|
121 | |
---|
122 | // パラメーター情報の初期化 |
---|
123 | $this->lfInitParam($objFormParam); |
---|
124 | $objFormParam->setParam($_REQUEST); |
---|
125 | $objFormParam->convParam(); |
---|
126 | $order_id = $objFormParam->getValue('order_id'); |
---|
127 | $arrValuesBefore = array(); |
---|
128 | |
---|
129 | // DBから受注情報を読み込む |
---|
130 | if (!SC_Utils_Ex::isBlank($order_id)) { |
---|
131 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
132 | $this->tpl_subno = 'index'; |
---|
133 | $arrValuesBefore['payment_id'] = $objFormParam->getValue('payment_id'); |
---|
134 | $arrValuesBefore['payment_method'] = $objFormParam->getValue('payment_method'); |
---|
135 | } else { |
---|
136 | $this->tpl_subno = 'add'; |
---|
137 | $this->tpl_mode = 'add'; |
---|
138 | $arrValuesBefore['payment_id'] = NULL; |
---|
139 | $arrValuesBefore['payment_method'] = NULL; |
---|
140 | // お届け先情報を空情報で表示 |
---|
141 | $arrShippingIds[] = null; |
---|
142 | $objFormParam->setValue('shipping_id', $arrShippingIds); |
---|
143 | |
---|
144 | // 新規受注登録で入力エラーがあった場合の画面表示用に、会員の現在ポイントを取得 |
---|
145 | if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) { |
---|
146 | $customer_id = $objFormParam->getValue('customer_id'); |
---|
147 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
148 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | $this->arrSearchHidden = $objFormParam->getSearchArray(); |
---|
153 | |
---|
154 | switch($this->getMode()) { |
---|
155 | case 'pre_edit': |
---|
156 | case 'order_id': |
---|
157 | break; |
---|
158 | |
---|
159 | case 'edit': |
---|
160 | $objFormParam->setParam($_POST); |
---|
161 | $objFormParam->convParam(); |
---|
162 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
163 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
164 | $message = '受注を編集しました。'; |
---|
165 | $order_id = $this->doRegister($order_id, $objPurchase, $objFormParam, $message, $arrValuesBefore); |
---|
166 | if ($order_id >= 0) { |
---|
167 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
168 | } |
---|
169 | $this->tpl_onload = "window.alert('" . $message . "');"; |
---|
170 | } |
---|
171 | break; |
---|
172 | |
---|
173 | case 'add': |
---|
174 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
---|
175 | $objFormParam->setParam($_POST); |
---|
176 | $objFormParam->convParam(); |
---|
177 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
178 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
179 | $message = '受注を登録しました。'; |
---|
180 | $order_id = $this->doRegister(null, $objPurchase, $objFormParam, $message, $arrValuesBefore); |
---|
181 | if ($order_id >= 0) { |
---|
182 | $this->tpl_mode = 'edit'; |
---|
183 | $objFormParam->setValue('order_id', $order_id); |
---|
184 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
185 | } |
---|
186 | $this->tpl_onload = "window.alert('" . $message . "');"; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | break; |
---|
191 | |
---|
192 | // 再計算 |
---|
193 | case 'recalculate': |
---|
194 | //支払い方法の選択 |
---|
195 | case 'payment': |
---|
196 | // 配送業者の選択 |
---|
197 | case 'deliv': |
---|
198 | $objFormParam->setParam($_POST); |
---|
199 | $objFormParam->convParam(); |
---|
200 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
201 | break; |
---|
202 | |
---|
203 | // 商品削除 |
---|
204 | case 'delete_product': |
---|
205 | $objFormParam->setParam($_POST); |
---|
206 | $objFormParam->convParam(); |
---|
207 | $delete_no = $objFormParam->getValue('delete_no'); |
---|
208 | $this->doDeleteProduct($delete_no, $objFormParam); |
---|
209 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
210 | break; |
---|
211 | |
---|
212 | // 商品追加ポップアップより商品選択 |
---|
213 | case 'select_product_detail': |
---|
214 | $objFormParam->setParam($_POST); |
---|
215 | $objFormParam->convParam(); |
---|
216 | $this->doRegisterProduct($objFormParam); |
---|
217 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
218 | break; |
---|
219 | |
---|
220 | // 会員検索ポップアップより会員指定 |
---|
221 | case 'search_customer': |
---|
222 | $objFormParam->setParam($_POST); |
---|
223 | $objFormParam->convParam(); |
---|
224 | $this->setCustomerTo($objFormParam->getValue('edit_customer_id'), |
---|
225 | $objFormParam); |
---|
226 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
227 | break; |
---|
228 | |
---|
229 | // 複数配送設定表示 |
---|
230 | case 'multiple': |
---|
231 | $objFormParam->setParam($_POST); |
---|
232 | $objFormParam->convParam(); |
---|
233 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
234 | break; |
---|
235 | |
---|
236 | // 複数配送設定を反映 |
---|
237 | case 'multiple_set_to': |
---|
238 | $this->lfInitMultipleParam($objFormParam); |
---|
239 | $objFormParam->setParam($_POST); |
---|
240 | $objFormParam->convParam(); |
---|
241 | $this->setMultipleItemTo($objFormParam); |
---|
242 | break; |
---|
243 | |
---|
244 | // お届け先の追加 |
---|
245 | case 'append_shipping': |
---|
246 | $objFormParam->setParam($_POST); |
---|
247 | $objFormParam->convParam(); |
---|
248 | $this->addShipping($objFormParam); |
---|
249 | break; |
---|
250 | |
---|
251 | default: |
---|
252 | } |
---|
253 | |
---|
254 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
255 | $this->arrAllShipping = $objFormParam->getSwapArray(array_merge($this->arrShippingKeys, $this->arrShipmentItemKeys)); |
---|
256 | $this->arrDelivTime = $objPurchase->getDelivTime($objFormParam->getValue('deliv_id')); |
---|
257 | $this->tpl_onload .= $this->getAnchorKey($objFormParam); |
---|
258 | $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
259 | if ($arrValuesBefore['payment_id']) |
---|
260 | $this->arrPayment[$arrValuesBefore['payment_id']] = $arrValuesBefore['payment_method']; |
---|
261 | |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | * デストラクタ. |
---|
266 | * |
---|
267 | * @return void |
---|
268 | */ |
---|
269 | function destroy() { |
---|
270 | parent::destroy(); |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | * パラメーター情報の初期化を行う. |
---|
275 | * |
---|
276 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
277 | * @return void |
---|
278 | */ |
---|
279 | function lfInitParam(&$objFormParam) { |
---|
280 | // 検索条件のパラメーターを初期化 |
---|
281 | parent::lfInitParam($objFormParam); |
---|
282 | |
---|
283 | // お客様情報 |
---|
284 | $objFormParam->addParam("注文者 お名前(姓)", "order_name01", STEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
285 | $objFormParam->addParam("注文者 お名前(名)", "order_name02", STEXT_LEN, 'KVa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
286 | $objFormParam->addParam("注文者 お名前(フリガナ・姓)", "order_kana01", STEXT_LEN, 'KVCa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
287 | $objFormParam->addParam("注文者 お名前(フリガナ・名)", "order_kana02", STEXT_LEN, 'KVCa', array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
288 | $objFormParam->addParam("メールアドレス", "order_email", null, 'KVCa', array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK")); |
---|
289 | $objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, 'n', array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
290 | $objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, 'n', array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
291 | $objFormParam->addParam("都道府県", "order_pref", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
292 | $objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
293 | $objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
294 | $objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
295 | $objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
296 | $objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
297 | |
---|
298 | // 受注商品情報 |
---|
299 | $objFormParam->addParam("値引き", 'discount', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
300 | $objFormParam->addParam("送料", "deliv_fee", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
301 | $objFormParam->addParam("手数料", 'charge', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
302 | |
---|
303 | // ポイント機能ON時のみ |
---|
304 | if (USE_POINT !== false) { |
---|
305 | $objFormParam->addParam("利用ポイント", "use_point", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
306 | } |
---|
307 | |
---|
308 | $objFormParam->addParam("配送業者", "deliv_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
309 | $objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
310 | $objFormParam->addParam("対応状況", 'status', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
311 | $objFormParam->addParam("お支払方法名称", "payment_method"); |
---|
312 | |
---|
313 | // 受注詳細情報 |
---|
314 | $objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
315 | $objFormParam->addParam("単価", 'price', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
316 | $objFormParam->addParam("数量", 'quantity', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
317 | $objFormParam->addParam("商品ID", "product_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
318 | $objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
319 | $objFormParam->addParam("ポイント付与率", "point_rate"); |
---|
320 | $objFormParam->addParam("商品コード", "product_code"); |
---|
321 | $objFormParam->addParam("商品名", "product_name"); |
---|
322 | $objFormParam->addParam("規格名1", "classcategory_name1"); |
---|
323 | $objFormParam->addParam("規格名2", "classcategory_name2"); |
---|
324 | $objFormParam->addParam("メモ", 'note', MTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK")); |
---|
325 | $objFormParam->addParam("削除用項番", "delete_no", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
326 | |
---|
327 | // DB読込用 |
---|
328 | $objFormParam->addParam("小計", 'subtotal'); |
---|
329 | $objFormParam->addParam("合計", 'total'); |
---|
330 | $objFormParam->addParam("支払い合計", "payment_total"); |
---|
331 | $objFormParam->addParam("加算ポイント", "add_point"); |
---|
332 | $objFormParam->addParam("お誕生日ポイント", "birth_point"); |
---|
333 | $objFormParam->addParam("消費税合計", 'tax'); |
---|
334 | $objFormParam->addParam("最終保持ポイント", "total_point"); |
---|
335 | $objFormParam->addParam("会員ID", "customer_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
336 | $objFormParam->addParam("会員ID", "edit_customer_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
337 | $objFormParam->addParam("現在のポイント", "customer_point"); |
---|
338 | $objFormParam->addParam("受注前ポイント", 'point'); |
---|
339 | $objFormParam->addParam("注文番号", "order_id"); |
---|
340 | $objFormParam->addParam("受注日", "create_date"); |
---|
341 | $objFormParam->addParam("発送日", "commit_date"); |
---|
342 | $objFormParam->addParam("備考", 'message'); |
---|
343 | $objFormParam->addParam("入金日", "payment_date"); |
---|
344 | $objFormParam->addParam("端末種別", "device_type_id"); |
---|
345 | |
---|
346 | // 複数情報 |
---|
347 | $objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
348 | $objFormParam->addParam("配送ID", "shipping_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), 0); |
---|
349 | $objFormParam->addParam("お名前(姓)", "shipping_name01", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
350 | $objFormParam->addParam("お名前(名)", "shipping_name02", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
351 | $objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01", STEXT_LEN, 'KVCa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
352 | $objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02", STEXT_LEN, 'KVCa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
353 | $objFormParam->addParam("郵便番号1", "shipping_zip01", ZIP01_LEN, 'n', array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
354 | $objFormParam->addParam("郵便番号2", "shipping_zip02", ZIP02_LEN, 'n', array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
355 | $objFormParam->addParam("都道府県", "shipping_pref", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
356 | $objFormParam->addParam("住所1", "shipping_addr01", MTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
357 | $objFormParam->addParam("住所2", "shipping_addr02", MTEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
358 | $objFormParam->addParam("電話番号1", "shipping_tel01", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
359 | $objFormParam->addParam("電話番号2", "shipping_tel02", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
360 | $objFormParam->addParam("電話番号3", "shipping_tel03", TEL_ITEM_LEN, 'n', array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
361 | $objFormParam->addParam("お届け時間ID", "time_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
362 | $objFormParam->addParam("お届け日(年)", "shipping_date_year", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
363 | $objFormParam->addParam("お届け日(月)", "shipping_date_month", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
364 | $objFormParam->addParam("お届け日(日)", "shipping_date_day", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
365 | $objFormParam->addParam("お届け日", "shipping_date", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
366 | $objFormParam->addParam("配送商品数量", "shipping_product_quantity", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
367 | |
---|
368 | $objFormParam->addParam("商品規格ID", "shipment_product_class_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
369 | $objFormParam->addParam("商品コード", "shipment_product_code"); |
---|
370 | $objFormParam->addParam("商品名", "shipment_product_name"); |
---|
371 | $objFormParam->addParam("規格名1", "shipment_classcategory_name1"); |
---|
372 | $objFormParam->addParam("規格名2", "shipment_classcategory_name2"); |
---|
373 | $objFormParam->addParam("単価", "shipment_price", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
374 | $objFormParam->addParam("数量", "shipment_quantity", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
375 | |
---|
376 | $objFormParam->addParam("商品項番", 'no', INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
377 | $objFormParam->addParam("追加商品規格ID", "add_product_class_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
378 | $objFormParam->addParam("修正商品規格ID", "edit_product_class_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
379 | $objFormParam->addParam("アンカーキー", "anchor_key", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
380 | } |
---|
381 | |
---|
382 | /** |
---|
383 | * 複数配送用フォームの初期化を行う. |
---|
384 | * |
---|
385 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
386 | * @return void |
---|
387 | */ |
---|
388 | function lfInitMultipleParam(&$objFormParam) { |
---|
389 | $objFormParam->addParam("商品規格ID", "multiple_product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
390 | $objFormParam->addParam("商品コード", "multiple_product_code", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
391 | $objFormParam->addParam("商品名", "multiple_product_name", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
392 | $objFormParam->addParam("規格1", "multiple_classcategory_name1", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
393 | $objFormParam->addParam("規格2", "multiple_classcategory_name2", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
394 | $objFormParam->addParam("単価", "multiple_price", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
395 | $objFormParam->addParam("数量", "multiple_quantity", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
396 | $objFormParam->addParam("配送先住所", "multiple_shipping_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
397 | } |
---|
398 | |
---|
399 | /** |
---|
400 | * 複数配送入力フォームで入力された値を SC_FormParam へ設定する. |
---|
401 | * |
---|
402 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
403 | * @return void |
---|
404 | */ |
---|
405 | function setMultipleItemTo(&$objFormParam) { |
---|
406 | $arrMultipleKey = array('multiple_shipping_id', |
---|
407 | 'multiple_product_class_id', |
---|
408 | 'multiple_product_name', |
---|
409 | 'multiple_product_code', |
---|
410 | 'multiple_classcategory_name1', |
---|
411 | 'multiple_classcategory_name2', |
---|
412 | 'multiple_price', |
---|
413 | 'multiple_quantity'); |
---|
414 | $arrMultipleParams = $objFormParam->getSwapArray($arrMultipleKey); |
---|
415 | |
---|
416 | /* |
---|
417 | * 複数配送フォームの入力値を shipping_id ごとにマージ |
---|
418 | * |
---|
419 | * $arrShipmentItem[配送先ID][商品規格ID]['shipment_(key)'] = 値 |
---|
420 | */ |
---|
421 | $arrShipmentItem = array(); |
---|
422 | foreach ($arrMultipleParams as $arrMultiple) { |
---|
423 | $shipping_id = $arrMultiple['multiple_shipping_id']; |
---|
424 | $product_class_id = $arrMultiple['multiple_product_class_id']; |
---|
425 | foreach ($arrMultiple as $key => $val) { |
---|
426 | if ($key == 'multiple_quantity') { |
---|
427 | $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] += $val; |
---|
428 | } else { |
---|
429 | $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] = $val; |
---|
430 | } |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | /* |
---|
435 | * フォームの配送先ごとの配列を生成 |
---|
436 | * |
---|
437 | * $arrShipmentForm['(key)'][$shipping_id][$item_index] = 値 |
---|
438 | * $arrProductQuantity[$shipping_id] = 配送先ごとの配送商品数量 |
---|
439 | */ |
---|
440 | $arrShipmentForm = array(); |
---|
441 | $arrProductQuantity = array(); |
---|
442 | $arrShippingIds = $objFormParam->getValue('shipping_id'); |
---|
443 | foreach ($arrShippingIds as $shipping_id) { |
---|
444 | $item_index = 0; |
---|
445 | foreach ($arrShipmentItem[$shipping_id] as $product_class_id => $shipment_item) { |
---|
446 | foreach ($shipment_item as $key => $val) { |
---|
447 | $arrShipmentForm[$key][$shipping_id][$item_index] = $val; |
---|
448 | } |
---|
449 | // 受注商品の数量を設定 |
---|
450 | $arrQuantity[$product_class_id] += $shipment_item['shipment_quantity']; |
---|
451 | $item_index++; |
---|
452 | } |
---|
453 | // 配送先ごとの配送商品数量を設定 |
---|
454 | $arrProductQuantity[$shipping_id] = count($arrShipmentItem[$shipping_id]); |
---|
455 | } |
---|
456 | |
---|
457 | $objFormParam->setParam($arrShipmentForm); |
---|
458 | $objFormParam->setValue('shipping_product_quantity', $arrProductQuantity); |
---|
459 | |
---|
460 | // 受注商品の数量を変更 |
---|
461 | $arrDest = array(); |
---|
462 | foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) { |
---|
463 | $arrDest['quantity'][$n] = 0; |
---|
464 | } |
---|
465 | foreach ($arrQuantity as $product_class_id => $quantity) { |
---|
466 | foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) { |
---|
467 | if ($product_class_id == $order_product_class_id) { |
---|
468 | $arrDest['quantity'][$n] = $quantity; |
---|
469 | } |
---|
470 | } |
---|
471 | } |
---|
472 | $objFormParam->setParam($arrDest); |
---|
473 | } |
---|
474 | |
---|
475 | /** |
---|
476 | * 受注データを取得して, SC_FormParam へ設定する. |
---|
477 | * |
---|
478 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
479 | * @param integer $order_id 取得元の受注ID |
---|
480 | * @return void |
---|
481 | */ |
---|
482 | function setOrderToFormParam(&$objFormParam, $order_id) { |
---|
483 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
484 | |
---|
485 | // 受注詳細を設定 |
---|
486 | $arrOrderDetail = $objPurchase->getOrderDetail($order_id, false); |
---|
487 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrOrderDetail)); |
---|
488 | |
---|
489 | $arrShippingsTmp = $objPurchase->getShippings($order_id); |
---|
490 | $arrShippings = array(); |
---|
491 | foreach ($arrShippingsTmp as $row) { |
---|
492 | // お届け日の処理 |
---|
493 | if (!SC_Utils_Ex::isBlank($row["shipping_date"])) { |
---|
494 | $ts = strtotime($row["shipping_date"]); |
---|
495 | $row['shipping_date_year'] = date('Y', $ts); |
---|
496 | $row['shipping_date_month'] = date('n', $ts); |
---|
497 | $row['shipping_date_day'] = date('j', $ts); |
---|
498 | } |
---|
499 | $arrShippings[$row['shipping_id']] = $row; |
---|
500 | } |
---|
501 | $objFormParam->setValue('shipping_quantity', count($arrShippings)); |
---|
502 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrShippings)); |
---|
503 | |
---|
504 | /* |
---|
505 | * 配送商品を設定 |
---|
506 | * |
---|
507 | * $arrShipmentItem['shipment_(key)'][$shipping_id][$item_index] = 値 |
---|
508 | * $arrProductQuantity[$shipping_id] = 配送先ごとの配送商品数量 |
---|
509 | */ |
---|
510 | $arrProductQuantity = array(); |
---|
511 | $arrShipmentItem = array(); |
---|
512 | foreach ($arrShippings as $shipping_id => $arrShipping) { |
---|
513 | $arrProductQuantity[$shipping_id] = count($arrShipping['shipment_item']); |
---|
514 | foreach ($arrShipping['shipment_item'] as $item_index => $arrItem) { |
---|
515 | foreach ($arrItem as $item_key => $item_val) { |
---|
516 | $arrShipmentItem['shipment_' . $item_key][$shipping_id][$item_index] = $item_val; |
---|
517 | } |
---|
518 | } |
---|
519 | } |
---|
520 | $objFormParam->setValue('shipping_product_quantity', $arrProductQuantity); |
---|
521 | $objFormParam->setParam($arrShipmentItem); |
---|
522 | |
---|
523 | /* |
---|
524 | * 受注情報を設定 |
---|
525 | * $arrOrderDetail と項目が重複しており, $arrOrderDetail は連想配列の値 |
---|
526 | * が渡ってくるため, $arrOrder で上書きする. |
---|
527 | */ |
---|
528 | $arrOrder = $objPurchase->getOrder($order_id); |
---|
529 | $objFormParam->setParam($arrOrder); |
---|
530 | |
---|
531 | // ポイントを設定 |
---|
532 | list($db_point, $rollback_point) = SC_Helper_DB_Ex::sfGetRollbackPoint( |
---|
533 | $order_id, $arrOrder['use_point'], $arrOrder['add_point'], $arrOrder['status'] |
---|
534 | ); |
---|
535 | $objFormParam->setValue('total_point', $db_point); |
---|
536 | $objFormParam->setValue('point', $rollback_point); |
---|
537 | |
---|
538 | if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) { |
---|
539 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($objFormParam->getValue('customer_id')); |
---|
540 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | /** |
---|
545 | * 入力内容のチェックを行う. |
---|
546 | * |
---|
547 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
548 | * @return array エラーメッセージの配列 |
---|
549 | */ |
---|
550 | function lfCheckError(&$objFormParam) { |
---|
551 | $objProduct = new SC_Product_Ex(); |
---|
552 | |
---|
553 | $arrErr = $objFormParam->checkError(); |
---|
554 | |
---|
555 | if (!SC_Utils_Ex::isBlank($objErr->arrErr)) { |
---|
556 | return $arrErr; |
---|
557 | } |
---|
558 | |
---|
559 | $arrValues = $objFormParam->getHashArray(); |
---|
560 | |
---|
561 | // 商品の種類数 |
---|
562 | $max = count($arrValues['quantity']); |
---|
563 | $subtotal = 0; |
---|
564 | $totalpoint = 0; |
---|
565 | $totaltax = 0; |
---|
566 | for($i = 0; $i < $max; $i++) { |
---|
567 | // 小計の計算 |
---|
568 | $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; |
---|
569 | // 小計の計算 |
---|
570 | $totaltax += SC_Helper_DB_Ex::sfTax($arrValues['price'][$i]) * $arrValues['quantity'][$i]; |
---|
571 | // 加算ポイントの計算 |
---|
572 | $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i]; |
---|
573 | |
---|
574 | // 在庫数のチェック |
---|
575 | $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]); |
---|
576 | |
---|
577 | // 編集前の値と比較するため受注詳細を取得 |
---|
578 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
579 | $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false)); |
---|
580 | |
---|
581 | if ($arrProduct['stock_unlimited'] != '1' |
---|
582 | && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) { |
---|
583 | $class_name1 = $arrValues['classcategory_name1'][$i]; |
---|
584 | $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? 'なし' : $class_name1; |
---|
585 | $class_name2 = $arrValues['classcategory_name2'][$i]; |
---|
586 | $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? 'なし' : $class_name2; |
---|
587 | $arrErr['quantity'][$i] .= $arrValues['product_name'][$i] |
---|
588 | . '/(' . $class_name1 . ')/(' . $class_name2 . ') の在庫が不足しています。 設定できる数量は「' |
---|
589 | . ($arrOrderDetail['quantity'][$i] + $arrProduct['stock']) . '」までです。<br />'; |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | // 消費税 |
---|
594 | $arrValues['tax'] = $totaltax; |
---|
595 | // 小計 |
---|
596 | $arrValues['subtotal'] = $subtotal; |
---|
597 | // 合計 |
---|
598 | $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge']; |
---|
599 | // お支払い合計 |
---|
600 | $arrValues['payment_total'] = $arrValues['total'] - ($arrValues['use_point'] * POINT_VALUE); |
---|
601 | |
---|
602 | // 加算ポイント |
---|
603 | $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']); |
---|
604 | |
---|
605 | // 最終保持ポイント |
---|
606 | $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point']; |
---|
607 | |
---|
608 | if ($arrValues['total'] < 0) { |
---|
609 | $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
610 | } |
---|
611 | |
---|
612 | if ($arrValues['payment_total'] < 0) { |
---|
613 | $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
614 | } |
---|
615 | |
---|
616 | if ($arrValues['total_point'] < 0) { |
---|
617 | $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; |
---|
618 | } |
---|
619 | |
---|
620 | $objFormParam->setParam($arrValues); |
---|
621 | return $arrErr; |
---|
622 | } |
---|
623 | |
---|
624 | /** |
---|
625 | * DB更新処理 |
---|
626 | * |
---|
627 | * @param integer $order_id 受注ID |
---|
628 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
629 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
630 | * @param string $message 通知メッセージ |
---|
631 | * @param array $arrValuesBefore 更新前の受注情報 |
---|
632 | * @return integer $order_id 受注ID |
---|
633 | * |
---|
634 | * エラー発生時は負数を返す。 |
---|
635 | */ |
---|
636 | function doRegister($order_id, &$objPurchase, &$objFormParam, &$message, &$arrValuesBefore) { |
---|
637 | |
---|
638 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
639 | $arrValues = $objFormParam->getDbArray(); |
---|
640 | |
---|
641 | $where = "order_id = ?"; |
---|
642 | |
---|
643 | $objQuery->begin(); |
---|
644 | |
---|
645 | // 支払い方法が変更されたら、支払い方法名称も更新 |
---|
646 | if ($arrValues['payment_id'] != $arrValuesBefore['payment_id']) { |
---|
647 | $arrValues['payment_method'] = $this->arrPayment[$arrValues['payment_id']]; |
---|
648 | $arrValuesBefore['payment_id'] = NULL; |
---|
649 | } |
---|
650 | |
---|
651 | // 受注テーブルの更新 |
---|
652 | $order_id = $objPurchase->registerOrder($order_id, $arrValues); |
---|
653 | |
---|
654 | $arrDetail = $objFormParam->getSwapArray(array("product_id", |
---|
655 | "product_class_id", |
---|
656 | "product_code", |
---|
657 | "product_name", |
---|
658 | 'price', 'quantity', |
---|
659 | "point_rate", |
---|
660 | "classcategory_name1", |
---|
661 | "classcategory_name2")); |
---|
662 | |
---|
663 | // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算 |
---|
664 | $max = count($arrDetail); |
---|
665 | $k = 0; |
---|
666 | $arrStockData = array(); |
---|
667 | for($i = 0; $i < $max; $i++) { |
---|
668 | if (!empty($arrDetail[$i]['product_id'])) { |
---|
669 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
670 | if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) { |
---|
671 | // 数量が変更された商品 |
---|
672 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
673 | $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity']; |
---|
674 | ++$k; |
---|
675 | } elseif (empty($arrPreDetail)) { |
---|
676 | // 新しく追加された商品 もしくは 違う商品に変更された商品 |
---|
677 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
678 | $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity']; |
---|
679 | ++$k; |
---|
680 | } |
---|
681 | $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
682 | } |
---|
683 | } |
---|
684 | |
---|
685 | // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品 |
---|
686 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id)); |
---|
687 | foreach ($arrPreDetail AS $key=>$val) { |
---|
688 | $arrStockData[$k]['product_class_id'] = $val['product_class_id']; |
---|
689 | $arrStockData[$k]['quantity'] = $val['quantity']; |
---|
690 | ++$k; |
---|
691 | } |
---|
692 | |
---|
693 | // 受注詳細データの更新 |
---|
694 | $objPurchase->registerOrderDetail($order_id, $arrDetail); |
---|
695 | |
---|
696 | // 在庫数調整 |
---|
697 | if (ORDER_DELIV != $arrValues['status'] |
---|
698 | && ORDER_CANCEL != $arrValues['status']) { |
---|
699 | foreach ($arrStockData AS $stock) { |
---|
700 | $objQuery->update('dtb_products_class', array(), |
---|
701 | 'product_class_id = ?', |
---|
702 | array($stock['product_class_id']), |
---|
703 | array('stock' => 'stock + ?'), |
---|
704 | array($stock['quantity'])); |
---|
705 | } |
---|
706 | } |
---|
707 | |
---|
708 | $arrAllShipping = $objFormParam->getSwapArray($this->arrShippingKeys); |
---|
709 | $arrAllShipmentItem = $objFormParam->getSwapArray($this->arrShipmentItemKeys); |
---|
710 | |
---|
711 | $arrDelivTime = $objPurchase->getDelivTime($objFormParam->getValue('deliv_id')); |
---|
712 | |
---|
713 | $arrShippingValues = array(); |
---|
714 | foreach ($arrAllShipping as $shipping_index => $arrShipping) { |
---|
715 | $shipping_id = $arrShipping['shipping_id']; |
---|
716 | $arrShippingValues[$shipping_index] = $arrShipping; |
---|
717 | |
---|
718 | $arrShippingValues[$shipping_index]['shipping_date'] |
---|
719 | = SC_Utils_Ex::sfGetTimestamp($arrShipping['shipping_date_year'], |
---|
720 | $arrShipping['shipping_date_month'], |
---|
721 | $arrShipping['shipping_date_day']); |
---|
722 | |
---|
723 | // 配送業者IDを取得 |
---|
724 | $arrShippingValues[$shipping_index]['deliv_id'] = $objFormParam->getValue('deliv_id'); |
---|
725 | |
---|
726 | // お届け時間名称を取得 |
---|
727 | $arrShippingValues[$shipping_index]['shipping_time'] = $arrDelivTime[$arrShipping['time_id']]; |
---|
728 | |
---|
729 | // 複数配送の場合は配送商品を登録 |
---|
730 | if (!SC_Utils_Ex::isBlank($arrAllShipmentItem)) { |
---|
731 | $arrShipmentValues = array(); |
---|
732 | |
---|
733 | foreach ($arrAllShipmentItem[$shipping_index] as $key => $arrItem) { |
---|
734 | $i = 0; |
---|
735 | foreach ($arrItem as $item) { |
---|
736 | $arrShipmentValues[$shipping_index][$i][str_replace('shipment_', '', $key)] = $item; |
---|
737 | $i++; |
---|
738 | } |
---|
739 | } |
---|
740 | $objPurchase->registerShipmentItem($order_id, $shipping_id, |
---|
741 | $arrShipmentValues[$shipping_index]); |
---|
742 | } |
---|
743 | } |
---|
744 | $objPurchase->registerShipping($order_id, $arrShippingValues, false); |
---|
745 | $objQuery->commit(); |
---|
746 | return $order_id; |
---|
747 | } |
---|
748 | |
---|
749 | /** |
---|
750 | * 受注商品の追加/更新を行う. |
---|
751 | * |
---|
752 | * 小画面で選択した受注商品をフォームに反映させる. |
---|
753 | * |
---|
754 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
755 | * @return void |
---|
756 | */ |
---|
757 | function doRegisterProduct(&$objFormParam) { |
---|
758 | $product_class_id = $objFormParam->getValue('add_product_class_id'); |
---|
759 | if (SC_Utils_Ex::isBlank($product_class_id)) { |
---|
760 | $product_class_id = $objFormParam->getValue('edit_product_class_id'); |
---|
761 | $changed_no = $objFormParam->getValue('no'); |
---|
762 | } |
---|
763 | // FXIME バリデーションを通さず $objFormParam の値で DB 問い合わせしている。(管理機能ため、さほど問題は無いと思うものの…) |
---|
764 | |
---|
765 | // 商品規格IDが指定されていない場合、例外エラーを発生 |
---|
766 | if (strlen($product_class_id) === 0) { |
---|
767 | SC_Utils_Ex::sfDispException('商品規格指定なし'); |
---|
768 | } |
---|
769 | |
---|
770 | // 選択済みの商品であれば数量を1増やす |
---|
771 | $exists = false; |
---|
772 | $arrExistsProductClassIds = $objFormParam->getValue('product_class_id'); |
---|
773 | foreach (array_keys($arrExistsProductClassIds) as $key) { |
---|
774 | $exists_product_class_id = $arrExistsProductClassIds[$key]; |
---|
775 | if ($exists_product_class_id == $product_class_id) { |
---|
776 | $exists = true; |
---|
777 | $exists_no = $key; |
---|
778 | $arrExistsQuantity = $objFormParam->getValue('quantity'); |
---|
779 | $arrExistsQuantity[$key]++; |
---|
780 | $objFormParam->setValue('quantity', $arrExistsQuantity); |
---|
781 | } |
---|
782 | } |
---|
783 | |
---|
784 | // 新しく商品を追加した場合はフォームに登録 |
---|
785 | // 商品を変更した場合は、該当行を変更 |
---|
786 | if (!$exists) { |
---|
787 | $objProduct = new SC_Product_Ex(); |
---|
788 | $arrProduct = $objProduct->getDetailAndProductsClass($product_class_id); |
---|
789 | |
---|
790 | // 一致する商品規格がない場合、例外エラーを発生 |
---|
791 | if (empty($arrProduct)) { |
---|
792 | SC_Utils_Ex::sfDispException('商品規格一致なし'); |
---|
793 | } |
---|
794 | |
---|
795 | $arrProduct['quantity'] = 1; |
---|
796 | $arrProduct['price'] = $arrProduct['price02']; |
---|
797 | $arrProduct['product_name'] = $arrProduct['name']; |
---|
798 | |
---|
799 | $arrUpdateKeys = array('product_id', 'product_class_id', |
---|
800 | 'product_type_id', 'point_rate', |
---|
801 | 'product_code', 'product_name', |
---|
802 | 'classcategory_name1', 'classcategory_name2', |
---|
803 | 'quantity', 'price'); |
---|
804 | foreach ($arrUpdateKeys as $key) { |
---|
805 | $arrValues = $objFormParam->getValue($key); |
---|
806 | if (isset($changed_no)) { |
---|
807 | $arrValues[$changed_no] = $arrProduct[$key]; |
---|
808 | } else { |
---|
809 | $added_no = 0; |
---|
810 | if (is_array($arrExistsProductClassIds)) { |
---|
811 | $added_no = count($arrExistsProductClassIds); |
---|
812 | } |
---|
813 | $arrValues[$added_no] = $arrProduct[$key]; |
---|
814 | } |
---|
815 | $objFormParam->setValue($key, $arrValues); |
---|
816 | } |
---|
817 | } elseif (isset($changed_no) && $exists_no != $changed_no) { |
---|
818 | // 変更したが、選択済みの商品だった場合は、変更対象行を削除。 |
---|
819 | $this->doDeleteProduct($changed_no, $objFormParam); |
---|
820 | } |
---|
821 | } |
---|
822 | |
---|
823 | /** |
---|
824 | * 受注商品を削除する. |
---|
825 | * |
---|
826 | * @param integer $delete_no 削除する受注商品の項番 |
---|
827 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
828 | * @return void |
---|
829 | */ |
---|
830 | function doDeleteProduct($delete_no, &$objFormParam) { |
---|
831 | $arrDeleteKeys = array('product_id', 'product_class_id', |
---|
832 | 'product_type_id', 'point_rate', |
---|
833 | 'product_code', 'product_name', |
---|
834 | 'classcategory_name1', 'classcategory_name2', |
---|
835 | 'quantity', 'price'); |
---|
836 | foreach ($arrDeleteKeys as $key) { |
---|
837 | $arrNewValues = array(); |
---|
838 | $arrValues = $objFormParam->getValue($key); |
---|
839 | foreach ($arrValues as $index => $val) { |
---|
840 | if ($index != $delete_no) { |
---|
841 | $arrNewValues[] = $val; |
---|
842 | } |
---|
843 | } |
---|
844 | $objFormParam->setValue($key, $arrNewValues); |
---|
845 | } |
---|
846 | } |
---|
847 | |
---|
848 | /** |
---|
849 | * お届け先を追加する. |
---|
850 | * |
---|
851 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
852 | * @return void |
---|
853 | */ |
---|
854 | function addShipping(&$objFormParam) { |
---|
855 | $objFormParam->setValue('shipping_quantity', |
---|
856 | $objFormParam->getValue('shipping_quantity') + 1); |
---|
857 | $arrShippingIds = $objFormParam->getValue('shipping_id'); |
---|
858 | $arrShippingIds[] = max($arrShippingIds) + 1; |
---|
859 | $objFormParam->setValue('shipping_id', $arrShippingIds); |
---|
860 | } |
---|
861 | |
---|
862 | /** |
---|
863 | * 会員情報をフォームに設定する. |
---|
864 | * |
---|
865 | * @param integer $customer_id 会員ID |
---|
866 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
867 | * @return void |
---|
868 | */ |
---|
869 | function setCustomerTo($customer_id, &$objFormParam) { |
---|
870 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
871 | foreach ($arrCustomer as $key => $val) { |
---|
872 | $objFormParam->setValue('order_' . $key, $val); |
---|
873 | } |
---|
874 | $objFormParam->setValue('customer_id', $customer_id); |
---|
875 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
876 | } |
---|
877 | |
---|
878 | /** |
---|
879 | * アンカーキーを取得する. |
---|
880 | * |
---|
881 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
882 | * @return アンカーキーの文字列 |
---|
883 | */ |
---|
884 | function getAnchorKey(&$objFormParam) { |
---|
885 | $ancor_key = $objFormParam->getValue('anchor_key'); |
---|
886 | if (!SC_Utils_Ex::isBlank($ancor_key)) { |
---|
887 | return "location.hash='#" . htmlentities(urlencode($ancor_key), ENT_QUOTES) . "'"; |
---|
888 | } |
---|
889 | return ''; |
---|
890 | } |
---|
891 | } |
---|
892 | ?> |
---|