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