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