source: branches/version-2_13-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php @ 23647

Revision 23647, 62.8 KB checked in by Seasoft, 9 years ago (diff)

#2635 (無駄な処理を改善する for 2.13.4)

  • date() 第2引数は省略可
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/order/LC_Page_Admin_Order_Ex.php';
25
26/**
27 * 受注修正 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Order_Edit extends LC_Page_Admin_Order_Ex
34{
35    public $arrShippingKeys = array(
36        'shipping_id',
37        'shipping_name01',
38        'shipping_name02',
39        'shipping_kana01',
40        'shipping_kana02',
41        'shipping_company_name',
42        'shipping_tel01',
43        'shipping_tel02',
44        'shipping_tel03',
45        'shipping_fax01',
46        'shipping_fax02',
47        'shipping_fax03',
48        'shipping_pref',
49        'shipping_country_id',
50        'shipping_zipcode',
51        'shipping_zip01',
52        'shipping_zip02',
53        'shipping_addr01',
54        'shipping_addr02',
55        'shipping_date_year',
56        'shipping_date_month',
57        'shipping_date_day',
58        'time_id',
59    );
60
61    public $arrShipmentItemKeys = array(
62        'shipment_product_class_id',
63        'shipment_product_code',
64        'shipment_product_name',
65        'shipment_classcategory_name1',
66        'shipment_classcategory_name2',
67        'shipment_price',
68        'shipment_quantity',
69    );
70
71    public $arrProductKeys = array(
72        'product_id',
73        'product_class_id',
74        'product_type_id',
75        'point_rate',
76        'product_code',
77        'product_name',
78        'classcategory_name1',
79        'classcategory_name2',
80        'quantity',
81        'price',
82        'tax_rate',
83        'tax_rule'
84    );
85
86    /**
87     * Page を初期化する.
88     *
89     * @return void
90     */
91    public function init()
92    {
93        parent::init();
94        $this->tpl_mainpage = 'order/edit.tpl';
95        $this->tpl_mainno = 'order';
96        $this->tpl_maintitle = '受注管理';
97        $this->tpl_subtitle = '受注登録';
98
99        $masterData = new SC_DB_MasterData_Ex();
100        $this->arrPref = $masterData->getMasterData('mtb_pref');
101        $this->arrCountry = $masterData->getMasterData('mtb_country');
102        $this->arrORDERSTATUS = $masterData->getMasterData('mtb_order_status');
103        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
104        $this->arrSex = $masterData->getMasterData('mtb_sex');
105        $this->arrJob = $masterData->getMasterData('mtb_job');
106
107        $objShippingDate = new SC_Date_Ex(RELEASE_YEAR);
108        $this->arrYearShippingDate = $objShippingDate->getYear('', date('Y'), '');
109        $this->arrMonthShippingDate = $objShippingDate->getMonth(true);
110        $this->arrDayShippingDate = $objShippingDate->getDay(true);
111
112        $objBirthDate = new SC_Date_Ex(BIRTH_YEAR, date('Y'));
113        $this->arrBirthYear = $objBirthDate->getYear('', START_BIRTH_YEAR, '');
114        $this->arrBirthMonth = $objBirthDate->getMonth(true);
115        $this->arrBirthDay = $objBirthDate->getDay(true);
116
117        // 支払い方法の取得
118        $this->arrPayment = SC_Helper_Payment_Ex::getIDValueList();
119
120        // 配送業者の取得
121        $this->arrDeliv = SC_Helper_Delivery_Ex::getIDValueList();
122
123        $this->httpCacheControl('nocache');
124    }
125
126    /**
127     * Page のプロセス.
128     *
129     * @return void
130     */
131    public function process()
132    {
133        $this->action();
134        $this->sendResponse();
135    }
136
137    /**
138     * Page のアクション.
139     *
140     * @return void
141     */
142    public function action()
143    {
144        $objPurchase = new SC_Helper_Purchase_Ex();
145        $objFormParam = new SC_FormParam_Ex();
146
147        // パラメーター情報の初期化
148        $this->lfInitParam($objFormParam);
149        $objFormParam->setParam($_REQUEST);
150        $objFormParam->convParam();
151        $order_id = $objFormParam->getValue('order_id');
152        $arrValuesBefore = array();
153
154        // DBから受注情報を読み込む
155        if (!SC_Utils_Ex::isBlank($order_id)) {
156            $this->setOrderToFormParam($objFormParam, $order_id);
157            $this->tpl_subno = 'index';
158            $arrValuesBefore['deliv_id'] = $objFormParam->getValue('deliv_id');
159            $arrValuesBefore['payment_id'] = $objFormParam->getValue('payment_id');
160            $arrValuesBefore['payment_method'] = $objFormParam->getValue('payment_method');
161        } else {
162            $this->tpl_subno = 'add';
163            $this->tpl_mode = 'add';
164            $arrValuesBefore['deliv_id'] = NULL;
165            $arrValuesBefore['payment_id'] = NULL;
166            $arrValuesBefore['payment_method'] = NULL;
167            // お届け先情報を空情報で表示
168            $arrShippingIds[] = null;
169            $objFormParam->setValue('shipping_id', $arrShippingIds);
170
171            // 新規受注登録で入力エラーがあった場合の画面表示用に、会員の現在ポイントを取得
172            if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) {
173                $customer_id = $objFormParam->getValue('customer_id');
174                $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id);
175                $objFormParam->setValue('customer_point', $arrCustomer['point']);
176
177                // 新規受注登録で、ポイント利用できるように現在ポイントを設定
178                $objFormParam->setValue('point', $arrCustomer['point']);
179            }
180        }
181
182        $this->arrSearchHidden = $objFormParam->getSearchArray();
183
184        switch ($this->getMode()) {
185            case 'pre_edit':
186            case 'order_id':
187                break;
188
189            case 'edit':
190                $objFormParam->setParam($_POST);
191                $objFormParam->convParam();
192                //複数配送時に各商品の総量を設定
193                $this->setProductsQuantity($objFormParam);
194                $this->arrErr = $this->lfCheckError($objFormParam);
195                if (SC_Utils_Ex::isBlank($this->arrErr)) {
196                    $message = '受注を編集しました。';
197                    $order_id = $this->doRegister($order_id, $objPurchase, $objFormParam, $message, $arrValuesBefore);
198                    if ($order_id >= 0) {
199                        $this->setOrderToFormParam($objFormParam, $order_id);
200                    }
201                    $this->tpl_onload = "window.alert('" . $message . "');";
202                }
203                break;
204
205            case 'add':
206                if ($_SERVER['REQUEST_METHOD'] == 'POST') {
207                    $objFormParam->setParam($_POST);
208                    $objFormParam->convParam();
209                    //複数配送時に各商品の総量を設定
210                    $this->setProductsQuantity($objFormParam);
211                    $this->arrErr = $this->lfCheckError($objFormParam);
212                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
213                        $message = '受注を登録しました。';
214                        $order_id = $this->doRegister(null, $objPurchase, $objFormParam, $message, $arrValuesBefore);
215                        if ($order_id >= 0) {
216                            $this->tpl_mode = 'edit';
217                            $objFormParam->setValue('order_id', $order_id);
218                            $this->setOrderToFormParam($objFormParam, $order_id);
219                        }
220                        $this->tpl_onload = "window.alert('" . $message . "');";
221                    }
222                }
223
224                break;
225
226            // 再計算
227            case 'recalculate':
228            //支払い方法の選択
229            case 'payment':
230            // 配送業者の選択
231            case 'deliv':
232                $objFormParam->setParam($_POST);
233                $objFormParam->convParam();
234                //複数配送時に各商品の総量を設定
235                $this->setProductsQuantity($objFormParam);
236                $this->arrErr = $this->lfCheckError($objFormParam);
237                break;
238
239            // 商品削除
240            case 'delete_product':
241                $objFormParam->setParam($_POST);
242                $objFormParam->convParam();
243                $delete_no = $objFormParam->getValue('delete_no');
244                $this->doDeleteProduct($delete_no, $objFormParam);
245                //複数配送時に各商品の総量を設定
246                $this->setProductsQuantity($objFormParam);
247                $this->arrErr = $this->lfCheckError($objFormParam);
248                break;
249
250            // 商品追加ポップアップより商品選択
251            case 'select_product_detail':
252                $objFormParam->setParam($_POST);
253                $objFormParam->convParam();
254                $this->doRegisterProduct($objFormParam);
255                //複数配送時に各商品の総量を設定
256                $this->setProductsQuantity($objFormParam);
257                $this->arrErr = $this->lfCheckError($objFormParam);
258                break;
259
260            // 会員検索ポップアップより会員指定
261            case 'search_customer':
262                $objFormParam->setParam($_POST);
263                $objFormParam->convParam();
264                $this->setProductsQuantity($objFormParam);
265                $this->setCustomerTo($objFormParam->getValue('edit_customer_id'),
266                                     $objFormParam);
267                $customer_birth = $objFormParam->getValue('order_birth');
268                // 加算ポイントの計算
269                if (USE_POINT === true && $this->tpl_mode == 'add') {
270                    $birth_point = 0;
271                    if ($customer_birth) {
272                        $arrRet = preg_split('|[- :/]|', $customer_birth);
273                        $birth_date = intval($arrRet[1]);
274                        $now_date   = intval(date('m'));
275                        // 誕生日月であった場合
276                        if ($birth_date == $now_date) {
277                            $birth_point = BIRTH_MONTH_POINT;
278                        }
279                    }
280                    $objFormParam->setValue("birth_point", $birth_point);
281                }
282                $this->arrErr = $this->lfCheckError($objFormParam);
283                break;
284
285                // 複数配送設定表示
286            case 'multiple':
287                $objFormParam->setParam($_POST);
288                $objFormParam->convParam();
289                $this->setProductsQuantity($objFormParam);
290                $this->arrErr = $this->lfCheckError($objFormParam);
291                break;
292
293                // 複数配送設定を反映
294            case 'multiple_set_to':
295                $this->lfInitMultipleParam($objFormParam);
296                $objFormParam->setParam($_POST);
297                $objFormParam->convParam();
298                $this->setProductsQuantity($objFormParam);
299                $this->setMultipleItemTo($objFormParam);
300                break;
301
302                // お届け先の追加
303            case 'append_shipping':
304                $objFormParam->setParam($_POST);
305                $objFormParam->convParam();
306                $this->setProductsQuantity($objFormParam);
307                $this->addShipping($objFormParam);
308                break;
309
310            default:
311                break;
312        }
313
314        $this->arrForm        = $objFormParam->getFormParamList();
315        $this->arrAllShipping = $objFormParam->getSwapArray(array_merge($this->arrShippingKeys, $this->arrShipmentItemKeys));
316        $this->tpl_shipping_quantity = count($this->arrAllShipping);
317        $this->top_shipping_id      = array_shift((array_keys($this->arrAllShipping)));
318        $this->arrDelivTime   = SC_Helper_Delivery_Ex::getDelivTime($objFormParam->getValue('deliv_id'));
319        $this->tpl_onload .= $this->getAnchorKey($objFormParam);
320        if ($arrValuesBefore['deliv_id']) {
321            // 受注当時の配送業者名はdtb_orderにないので、
322            // 削除済みの配送業者も含めて情報を取得。
323            $objDelivery = new SC_Helper_Delivery_Ex();
324            $arrDelivery = $objDelivery->get($arrValuesBefore['deliv_id'], true);
325            $this->arrDeliv[$arrValuesBefore['deliv_id']] = $arrDelivery['name'];
326        }
327        if ($arrValuesBefore['payment_id'])
328            $this->arrPayment[$arrValuesBefore['payment_id']] = $arrValuesBefore['payment_method'];
329    }
330
331    /**
332     * パラメーター情報の初期化を行う.
333     *
334     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
335     * @return void
336     */
337    public function lfInitParam(&$objFormParam)
338    {
339        // 検索条件のパラメーターを初期化
340        parent::lfInitParam($objFormParam);
341
342        // お客様情報
343        $objFormParam->addParam('注文者 お名前(姓)', 'order_name01', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
344        $objFormParam->addParam('注文者 お名前(名)', 'order_name02', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
345        $objFormParam->addParam('注文者 お名前(フリガナ・姓)', 'order_kana01', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
346        $objFormParam->addParam('注文者 お名前(フリガナ・名)', 'order_kana02', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
347        $objFormParam->addParam('注文者 会社名', 'order_company_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
348        $objFormParam->addParam('メールアドレス', 'order_email', null, 'KVCa', array('NO_SPTAB', 'EMAIL_CHECK', 'EMAIL_CHAR_CHECK'));
349        $objFormParam->addParam('国', 'order_country_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
350        $objFormParam->addParam('ZIPCODE', 'order_zipcode', STEXT_LEN, 'n', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
351        $objFormParam->addParam('郵便番号1', 'order_zip01', ZIP01_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK'));
352        $objFormParam->addParam('郵便番号2', 'order_zip02', ZIP02_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK'));
353        $objFormParam->addParam('都道府県', 'order_pref', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
354        $objFormParam->addParam('住所1', 'order_addr01', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
355        $objFormParam->addParam('住所2', 'order_addr02', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
356        $objFormParam->addParam('電話番号1', 'order_tel01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
357        $objFormParam->addParam('電話番号2', 'order_tel02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
358        $objFormParam->addParam('電話番号3', 'order_tel03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
359        $objFormParam->addParam('FAX番号1', 'order_fax01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
360        $objFormParam->addParam('FAX番号2', 'order_fax02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
361        $objFormParam->addParam('FAX番号3', 'order_fax03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
362        $objFormParam->addParam('性別', 'order_sex', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
363        $objFormParam->addParam('職業', 'order_job', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
364        $objFormParam->addParam('生年月日(年)', 'order_birth_year', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
365        $objFormParam->addParam('生年月日(月)', 'order_birth_month', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
366        $objFormParam->addParam('生年月日(日)', 'order_birth_day', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
367        $objFormParam->addParam('生年月日', 'order_birth', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
368
369        // 受注商品情報
370        $objFormParam->addParam('値引き', 'discount', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
371        $objFormParam->addParam('送料', 'deliv_fee', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
372        $objFormParam->addParam('手数料', 'charge', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
373
374        // ポイント機能ON時のみ
375        if (USE_POINT !== false) {
376            $objFormParam->addParam('利用ポイント', 'use_point', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
377        }
378
379        $objFormParam->addParam('配送業者', 'deliv_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
380        $objFormParam->addParam('お支払い方法', 'payment_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
381        $objFormParam->addParam('対応状況', 'status', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
382        $objFormParam->addParam('お支払方法名称', 'payment_method');
383
384        // 受注詳細情報
385        $objFormParam->addParam('商品種別ID', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
386        $objFormParam->addParam('単価', 'price', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
387        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
388        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
389        $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
390        $objFormParam->addParam('ポイント付与率', 'point_rate');
391        $objFormParam->addParam('商品コード', 'product_code');
392        $objFormParam->addParam('商品名', 'product_name');
393        $objFormParam->addParam('規格名1', 'classcategory_name1');
394        $objFormParam->addParam('規格名2', 'classcategory_name2');
395        $objFormParam->addParam('税率', 'tax_rate', INT_LEN, 'n', array('NUM_CHECK'));
396        $objFormParam->addParam('課税規則', 'tax_rule', INT_LEN, 'n', array('NUM_CHECK'));
397        $objFormParam->addParam('メモ', 'note', MTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
398        $objFormParam->addParam('削除用項番', 'delete_no', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
399
400        // DB読込用
401        $objFormParam->addParam('小計', 'subtotal');
402        $objFormParam->addParam('合計', 'total');
403        $objFormParam->addParam('支払い合計', 'payment_total');
404        $objFormParam->addParam('加算ポイント', 'add_point');
405        $objFormParam->addParam('お誕生日ポイント', 'birth_point', null, 'n', array(), 0);
406        $objFormParam->addParam('消費税合計', 'tax');
407        $objFormParam->addParam('最終保持ポイント', 'total_point');
408        $objFormParam->addParam('会員ID', 'customer_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
409        $objFormParam->addParam('会員ID', 'edit_customer_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
410        $objFormParam->addParam('現在のポイント', 'customer_point');
411        $objFormParam->addParam('受注前ポイント', 'point');
412        $objFormParam->addParam('注文番号', 'order_id');
413        $objFormParam->addParam('受注日', 'create_date');
414        $objFormParam->addParam('発送日', 'commit_date');
415        $objFormParam->addParam('備考', 'message');
416        $objFormParam->addParam('入金日', 'payment_date');
417        $objFormParam->addParam('端末種別', 'device_type_id');
418        $objFormParam->addParam('税率', 'order_tax_rate');
419        $objFormParam->addParam('課税規則', 'order_tax_rule');
420
421        // 複数情報
422        $objFormParam->addParam('配送ID', 'shipping_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), 0);
423        $objFormParam->addParam('お名前(姓)', 'shipping_name01', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
424        $objFormParam->addParam('お名前(名)', 'shipping_name02', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
425        $objFormParam->addParam('お名前(フリガナ・姓)', 'shipping_kana01', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
426        $objFormParam->addParam('お名前(フリガナ・名)', 'shipping_kana02', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'NO_SPTAB'));
427        $objFormParam->addParam('会社名', 'shipping_company_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
428        $objFormParam->addParam('国', 'shipping_country_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
429        $objFormParam->addParam('ZIPCODE', 'shipping_zipcode', STEXT_LEN, 'n', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
430        $objFormParam->addParam('郵便番号1', 'shipping_zip01', ZIP01_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK'));
431        $objFormParam->addParam('郵便番号2', 'shipping_zip02', ZIP02_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK'));
432        $objFormParam->addParam('都道府県', 'shipping_pref', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
433        $objFormParam->addParam('住所1', 'shipping_addr01', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
434        $objFormParam->addParam('住所2', 'shipping_addr02', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
435        $objFormParam->addParam('電話番号1', 'shipping_tel01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
436        $objFormParam->addParam('電話番号2', 'shipping_tel02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
437        $objFormParam->addParam('電話番号3', 'shipping_tel03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
438        $objFormParam->addParam('FAX番号1', 'shipping_fax01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
439        $objFormParam->addParam('FAX番号2', 'shipping_fax02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
440        $objFormParam->addParam('FAX番号3', 'shipping_fax03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
441        $objFormParam->addParam('お届け時間ID', 'time_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
442        $objFormParam->addParam('お届け日(年)', 'shipping_date_year', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
443        $objFormParam->addParam('お届け日(月)', 'shipping_date_month', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
444        $objFormParam->addParam('お届け日(日)', 'shipping_date_day', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
445        $objFormParam->addParam('お届け日', 'shipping_date', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
446
447        $objFormParam->addParam('商品規格ID', 'shipment_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
448        $objFormParam->addParam('商品コード', 'shipment_product_code');
449        $objFormParam->addParam('商品名', 'shipment_product_name');
450        $objFormParam->addParam('規格名1', 'shipment_classcategory_name1');
451        $objFormParam->addParam('規格名2', 'shipment_classcategory_name2');
452        $objFormParam->addParam('単価', 'shipment_price', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
453        $objFormParam->addParam('数量', 'shipment_quantity', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0');
454
455        $objFormParam->addParam('商品項番', 'no', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
456        $objFormParam->addParam('追加商品規格ID', 'add_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
457        $objFormParam->addParam('修正商品規格ID', 'edit_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
458        $objFormParam->addParam('対象届け先ID', 'select_shipping_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
459        $objFormParam->addParam('アンカーキー', 'anchor_key', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
460    }
461
462    /**
463     * 複数配送用フォームの初期化を行う.
464     *
465     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
466     * @return void
467     */
468    public function lfInitMultipleParam(&$objFormParam)
469    {
470        $objFormParam->addParam('商品規格ID', 'multiple_product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
471        $objFormParam->addParam('商品コード', 'multiple_product_code', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
472        $objFormParam->addParam('商品名', 'multiple_product_name', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
473        $objFormParam->addParam('規格1', 'multiple_classcategory_name1', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
474        $objFormParam->addParam('規格2', 'multiple_classcategory_name2', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
475        $objFormParam->addParam('単価', 'multiple_price', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
476        $objFormParam->addParam('数量', 'multiple_quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
477        $objFormParam->addParam('お届け先', 'multiple_shipping_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
478    }
479
480    /**
481     * 複数配送入力フォームで入力された値を SC_FormParam へ設定する.
482     *
483     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
484     * @return void
485     */
486    public function setMultipleItemTo(&$objFormParam)
487    {
488        $arrMultipleKey = array('multiple_shipping_id',
489                'multiple_product_class_id',
490                'multiple_product_name',
491                'multiple_product_code',
492                'multiple_classcategory_name1',
493                'multiple_classcategory_name2',
494                'multiple_price',
495                'multiple_quantity');
496        $arrMultipleParams = $objFormParam->getSwapArray($arrMultipleKey);
497
498        /*
499         * 複数配送フォームの入力値を shipping_id ごとにマージ
500         *
501         * $arrShipmentItem[お届け先ID][商品規格ID]['shipment_(key)'] = 値
502         */
503        $arrShipmentItem = array();
504        foreach ($arrMultipleParams as $arrMultiple) {
505            $shipping_id = $arrMultiple['multiple_shipping_id'];
506            $product_class_id = $arrMultiple['multiple_product_class_id'];
507            foreach ($arrMultiple as $key => $val) {
508                if ($key == 'multiple_quantity') {
509                    $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] += $val;
510                } else {
511                    $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] = $val;
512                }
513            }
514        }
515
516        /*
517         * フォームのお届け先ごとの配列を生成
518         *
519         * $arrShipmentForm['(key)'][$shipping_id][$item_index] = 値
520         * $arrProductQuantity[$shipping_id] = お届け先ごとの配送商品数量
521         */
522        $arrShipmentForm = array();
523        $arrShippingIds = $objFormParam->getValue('shipping_id');
524        foreach ($arrShippingIds as $shipping_id) {
525            $item_index = 0;
526            foreach ($arrShipmentItem[$shipping_id] as $product_class_id => $shipment_item) {
527                foreach ($shipment_item as $key => $val) {
528                    $arrShipmentForm[$key][$shipping_id][$item_index] = $val;
529                }
530                // 受注商品の数量を設定
531                $arrQuantity[$product_class_id] += $shipment_item['shipment_quantity'];
532                $item_index++;
533            }
534            // お届け先ごとの配送商品数量を設定
535        }
536
537        $objFormParam->setParam($arrShipmentForm);
538
539        // 受注商品の数量を変更
540        $arrDest = array();
541        foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) {
542            $arrDest['quantity'][$n] = 0;
543        }
544        foreach ($arrQuantity as $product_class_id => $quantity) {
545            foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) {
546                if ($product_class_id == $order_product_class_id) {
547                    $arrDest['quantity'][$n] = $quantity;
548                }
549            }
550        }
551        $objFormParam->setParam($arrDest);
552    }
553
554    /**
555     * 受注データを取得して, SC_FormParam へ設定する.
556     *
557     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
558     * @param  integer      $order_id     取得元の受注ID
559     * @return void
560     */
561    public function setOrderToFormParam(&$objFormParam, $order_id)
562    {
563        $objPurchase = new SC_Helper_Purchase_Ex();
564
565        // 受注詳細を設定
566        $arrOrderDetail = $objPurchase->getOrderDetail($order_id, false);
567        $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrOrderDetail));
568
569        $arrShippingsTmp = $objPurchase->getShippings($order_id);
570        $arrShippings = array();
571
572        if ($arrShippingsTmp) {
573            foreach ($arrShippingsTmp as $row) {
574                // お届け日の処理
575                if (!SC_Utils_Ex::isBlank($row['shipping_date'])) {
576                    $ts = strtotime($row['shipping_date']);
577                    $row['shipping_date_year'] = date('Y', $ts);
578                    $row['shipping_date_month'] = date('n', $ts);
579                    $row['shipping_date_day'] = date('j', $ts);
580                }
581                $arrShippings[$row['shipping_id']] = $row;
582            }
583        } else {
584            // ダウンロード商品の場合はお届け先情報がないので受注詳細から必要なデータを挿入する
585            foreach ($this->arrShippingKeys as $keys) {
586                $arrShippings[0][$keys] = '';
587            }
588            foreach ($arrOrderDetail as $key => $value) {
589                $arrShippings[0]['shipment_item'][$key]['shipping_id'] = $key;
590                $arrShippings[0]['shipment_item'][$key]['product_class_id'] = $value['product_class_id'];
591                $arrShippings[0]['shipment_item'][$key]['quantity'] = $value['quantity'];
592            }
593        }
594        $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrShippings));
595
596        /*
597         * 配送商品を設定
598         *
599         * $arrShipmentItem['shipment_(key)'][$shipping_id][$item_index] = 値
600         * $arrProductQuantity[$shipping_id] = お届け先ごとの配送商品数量
601         */
602        $arrShipmentItem = array();
603        foreach ($arrShippings as $shipping_id => $arrShipping) {
604            foreach ($arrShipping['shipment_item'] as $item_index => $arrItem) {
605                foreach ($arrItem as $item_key => $item_val) {
606                    $arrShipmentItem['shipment_' . $item_key][$shipping_id][$item_index] = $item_val;
607                }
608            }
609        }
610        $objFormParam->setParam($arrShipmentItem);
611
612        /*
613         * 受注情報を設定
614         * $arrOrderDetail と項目が重複しており, $arrOrderDetail は連想配列の値
615         * が渡ってくるため, $arrOrder で上書きする.
616         */
617        $arrOrder = $objPurchase->getOrder($order_id);
618
619        // 生年月日の処理
620        if (!SC_Utils_Ex::isBlank($arrOrder['order_birth'])) {
621            $order_birth = substr($arrOrder['order_birth'], 0, 10);
622            $arrOrderBirth = explode("-", $order_birth);
623
624            $arrOrder['order_birth_year'] = intval($arrOrderBirth[0]);
625            $arrOrder['order_birth_month'] = intval($arrOrderBirth[1]);
626            $arrOrder['order_birth_day'] = intval($arrOrderBirth[2]);
627        }
628
629        $objFormParam->setParam($arrOrder);
630
631        // ポイントを設定
632        if (USE_POINT !== false) {
633            list($db_point, $rollback_point) = SC_Helper_DB_Ex::sfGetRollbackPoint(
634                $order_id, $arrOrder['use_point'],
635                $arrOrder['add_point'], $arrOrder['status']
636            );
637            $objFormParam->setValue('total_point', $db_point);
638            $objFormParam->setValue('point', $rollback_point);
639        } else {
640            $objFormParam->setValue('total_point', 0);
641            $objFormParam->setValue('point', 0);
642        }
643
644        if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) {
645            $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($objFormParam->getValue('customer_id'));
646            $objFormParam->setValue('customer_point', $arrCustomer['point']);
647        }
648    }
649
650    /**
651     * 入力内容のチェックを行う.
652     *
653     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
654     * @return array        エラーメッセージの配列
655     */
656    public function lfCheckError(&$objFormParam)
657    {
658        $objProduct = new SC_Product_Ex();
659        $arrValues = $objFormParam->getHashArray();
660        $arrErr = array();
661        $arrErrTemp = $objFormParam->checkError();
662        $arrErrDate = array();
663        foreach ($arrValues['shipping_date_year'] as $key_index => $year) {
664            $month = $arrValues['shipping_date_month'][$key_index];
665            $day = $arrValues['shipping_date_day'][$key_index];
666            $objError = new SC_CheckError_Ex(array('shipping_date_year' => $year,
667                'shipping_date_month' => $month,
668                'shipping_date_day' => $day));
669            $objError->doFunc(array('お届け日', 'shipping_date_year', 'shipping_date_month', 'shipping_date_day'), array('CHECK_DATE'));
670            $arrErrDate['shipping_date_year'][$key_index] = $objError->arrErr['shipping_date_year'];
671        }
672        $arrErrTemp = array_merge($arrErrTemp, $arrErrDate);
673
674        // 複数項目チェック
675        $year = $arrValues['order_birth_year'];
676        $month = $arrValues['order_birth_month'];
677        $day = $arrValues['order_birth_day'];
678        $objError = new SC_CheckError_Ex(array('order_birth_year' => $year,
679                                               'order_birth_month' => $month,
680                                               'order_birth_day' => $day));
681        $objError->doFunc(array('生年月日', 'order_birth_year', 'order_birth_month', 'order_birth_day'),
682                          array('CHECK_BIRTHDAY'));
683        $arrErrTemp['order_birth_year'] = $objError->arrErr['order_birth_year'];
684
685        // 商品の種類数
686        $max = count($arrValues['quantity']);
687        $subtotal = 0;
688        $totalpoint = 0;
689        $totaltax = 0;
690        for ($i = 0; $i < $max; $i++) {
691            // 小計の計算
692            $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i];
693            // 小計の計算
694            $totaltax += SC_Utils_Ex::sfTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i];
695            // 加算ポイントの計算
696            $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i];
697
698            // 在庫数のチェック
699            $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]);
700
701            // 編集前の値と比較するため受注詳細を取得
702            $objPurchase = new SC_Helper_Purchase_Ex();
703            $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false));
704
705            if ($arrProduct['stock_unlimited'] != '1'
706                    && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) {
707                $class_name1 = $arrValues['classcategory_name1'][$i];
708                $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? 'なし' : $class_name1;
709                $class_name2 = $arrValues['classcategory_name2'][$i];
710                $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? 'なし' : $class_name2;
711                $arrErr['quantity'][$i] .= $arrValues['product_name'][$i]
712                    . '/(' . $class_name1 . ')/(' . $class_name2 . ') の在庫が不足しています。 設定できる数量は「'
713                    . ($arrOrderDetail['quantity'][$i] + $arrProduct['stock']) . '」までです。<br />';
714            }
715        }
716
717        // 消費税
718        $arrValues['tax'] = $totaltax;
719        // 小計
720        $arrValues['subtotal'] = $subtotal;
721        // 合計
722        $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge'];
723        // お支払い合計
724        $arrValues['payment_total'] = $arrValues['total'] - ($arrValues['use_point'] * POINT_VALUE);
725
726        // 加算ポイント
727        $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']) + $arrValues['birth_point'];
728
729        // 最終保持ポイント
730        $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point'];
731
732        if ($arrValues['total'] < 0) {
733            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
734        }
735
736        if ($arrValues['payment_total'] < 0) {
737            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
738        }
739
740        if ($arrValues['total_point'] < 0) {
741            $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
742        }
743
744        $objFormParam->setParam($arrValues);
745        $arrErr = array_merge($arrErr, $arrErrTemp);
746
747        return $arrErr;
748    }
749
750    /**
751     * DB更新処理
752     *
753     * @param  integer            $order_id        受注ID
754     * @param  SC_Helper_Purchase $objPurchase     SC_Helper_Purchase インスタンス
755     * @param  SC_FormParam       $objFormParam    SC_FormParam インスタンス
756     * @param  string             $message         通知メッセージ
757     * @param  array              $arrValuesBefore 更新前の受注情報
758     * @return integer            $order_id 受注ID
759     *
760     * エラー発生時は負数を返す。
761     */
762    public function doRegister($order_id, &$objPurchase, &$objFormParam, &$message, &$arrValuesBefore)
763    {
764        $objQuery =& SC_Query_Ex::getSingletonInstance();
765        $arrValues = $objFormParam->getDbArray();
766
767        $where = 'order_id = ?';
768
769        $objQuery->begin();
770
771        // 支払い方法が変更されたら、支払い方法名称も更新
772        if ($arrValues['payment_id'] != $arrValuesBefore['payment_id']) {
773            $arrValues['payment_method'] = $this->arrPayment[$arrValues['payment_id']];
774            $arrValuesBefore['payment_id'] = NULL;
775        }
776
777        // 生年月日の調整
778        $arrValues['order_birth'] = SC_Utils_Ex::sfGetTimestamp($arrValues['order_birth_year'], $arrValues['order_birth_month'], $arrValues['order_birth_day']);
779
780        // 受注テーブルの更新
781        $order_id = $objPurchase->registerOrder($order_id, $arrValues);
782
783        $arrDetail = $objFormParam->getSwapArray(array(
784                'product_id',
785                'product_class_id',
786                'product_code',
787                'product_name',
788                'price', 'quantity',
789                'point_rate',
790                'classcategory_name1',
791                'classcategory_name2',
792                'tax_rate',
793                'tax_rule'
794        ));
795
796        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算
797        $max = count($arrDetail);
798        $k = 0;
799        $arrStockData = array();
800        for ($i = 0; $i < $max; $i++) {
801            if (!empty($arrDetail[$i]['product_id'])) {
802                $arrPreDetail = $objQuery->select('*', 'dtb_order_detail', 'order_id = ? AND product_class_id = ?', array($order_id, $arrDetail[$i]['product_class_id']));
803                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) {
804                    // 数量が変更された商品
805                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
806                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity'];
807                    ++$k;
808                } elseif (empty($arrPreDetail)) {
809                    // 新しく追加された商品 もしくは 違う商品に変更された商品
810                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
811                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity'];
812                    ++$k;
813                }
814                $objQuery->delete('dtb_order_detail', 'order_id = ? AND product_class_id = ?', array($order_id, $arrDetail[$i]['product_class_id']));
815            }
816        }
817
818        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品
819        $arrPreDetail = $objQuery->select('*', 'dtb_order_detail', 'order_id = ?', array($order_id));
820        foreach ($arrPreDetail AS $key=>$val) {
821            $arrStockData[$k]['product_class_id'] = $val['product_class_id'];
822            $arrStockData[$k]['quantity'] = $val['quantity'];
823            ++$k;
824        }
825
826        // 受注詳細データの更新
827        $objPurchase->registerOrderDetail($order_id, $arrDetail);
828
829        // 在庫数調整
830        if (ORDER_DELIV != $arrValues['status']
831            && ORDER_CANCEL != $arrValues['status']) {
832            foreach ($arrStockData AS $stock) {
833                $objQuery->update('dtb_products_class', array(),
834                                  'product_class_id = ?',
835                                  array($stock['product_class_id']),
836                                  array('stock' => 'stock + ?'),
837                                  array($stock['quantity']));
838            }
839        }
840
841        $arrAllShipping = $objFormParam->getSwapArray($this->arrShippingKeys);
842        $arrAllShipmentItem = $objFormParam->getSwapArray($this->arrShipmentItemKeys);
843
844        $arrDelivTime = SC_Helper_Delivery_Ex::getDelivTime($objFormParam->getValue('deliv_id'));
845        //商品単価を複数配送にも適応
846        $arrShippingValues = array();
847        $arrIsNotQuantityUp = array();
848        foreach ($arrAllShipping as $shipping_index => $arrShipping) {
849            $shipping_id = $arrShipping['shipping_id'];
850            $arrShippingValues[$shipping_index] = $arrShipping;
851
852            $arrShippingValues[$shipping_index]['shipping_date']
853                = SC_Utils_Ex::sfGetTimestamp($arrShipping['shipping_date_year'],
854                                              $arrShipping['shipping_date_month'],
855                                              $arrShipping['shipping_date_day']);
856
857            //商品単価を複数配送にも反映する
858            foreach ($arrDetail as $product_detail) {
859                foreach ($arrAllShipmentItem[$shipping_index]['shipment_product_class_id'] as $relation_index => $shipment_product_class_id) {
860                    if ($product_detail['product_class_id'] == $shipment_product_class_id) {
861                        $arrAllShipmentItem[$shipping_index]['shipment_price'][$relation_index] = $product_detail['price'];
862                    }
863                }
864            }
865            // 配送業者IDを取得
866            $arrShippingValues[$shipping_index]['deliv_id'] = $objFormParam->getValue('deliv_id');
867
868            // お届け時間名称を取得
869            $arrShippingValues[$shipping_index]['shipping_time'] = $arrDelivTime[$arrShipping['time_id']];
870
871            // 複数配送の場合は配送商品を登録
872            if (!SC_Utils_Ex::isBlank($arrAllShipmentItem)) {
873                $arrShipmentValues = array();
874
875                foreach ($arrAllShipmentItem[$shipping_index] as $key => $arrItem) {
876                    // TODO $arrItemが配列でない場合があるのを見直した方が良いかもしれない
877                    if (is_array($arrItem)) {
878                        $i = 0;
879                        foreach ($arrItem as $item) {
880                            $arrShipmentValues[$shipping_index][$i][str_replace('shipment_', '', $key)] = $item;
881                            $i++;
882                        }
883                    }
884                }
885                $objPurchase->registerShipmentItem($order_id, $shipping_id,
886                                                   $arrShipmentValues[$shipping_index]);
887            }
888        }
889
890        $objPurchase->registerShipping($order_id, $arrShippingValues, false);
891        $objQuery->commit();
892
893        return $order_id;
894    }
895
896    /**
897     * 受注商品の追加/更新を行う.
898     *
899     * 小画面で選択した受注商品をフォームに反映させる.
900     *
901     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
902     * @return void
903     */
904    public function doRegisterProduct(&$objFormParam)
905    {
906        $product_class_id = $objFormParam->getValue('add_product_class_id');
907        if (SC_Utils_Ex::isBlank($product_class_id)) {
908            $product_class_id = $objFormParam->getValue('edit_product_class_id');
909            $changed_no = $objFormParam->getValue('no');
910            $this->shipmentEditProduct($objFormParam, $product_class_id, $changed_no);
911        } else {
912            $this->shipmentAddProduct($objFormParam, $product_class_id);
913        }
914    }
915
916    /**
917     * 受注商品を削除する.
918     *
919     * @param  integer      $delete_no    削除する受注商品の項番
920     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
921     * @return void
922     */
923    public function doDeleteProduct($delete_no, &$objFormParam)
924    {
925        $select_shipping_id    = $objFormParam->getValue('select_shipping_id');
926
927        //変更前のproduct_class_idが他の届け先にも存在するか
928        $arrPreShipmentProductClassIds = $objFormParam->getValue('shipment_product_class_id');
929        $arrPreProductClassIds         = $objFormParam->getValue('product_class_id');
930        $delete_product_class_id       = $arrPreShipmentProductClassIds[$select_shipping_id][$delete_no];
931
932        //配送先データ削除
933        $arrNewShipments = $this->deleteShipment($objFormParam, $this->arrShipmentItemKeys, $select_shipping_id, $delete_no);
934        $objFormParam->setParam($arrNewShipments);
935
936        $is_product_delete = true;
937        foreach ($arrNewShipments['shipment_product_class_id'] as $shipping_id => $arrShipmentProductClassIds) {
938            foreach ($arrShipmentProductClassIds as $relation_index => $shipment_product_class_id) {
939                if (in_array($delete_product_class_id, $arrShipmentProductClassIds)) {
940                    $is_product_delete = false;
941                    break;
942                }
943            }
944        }
945
946        //商品情報から削除
947        if ($is_product_delete) {
948            $this->checkDeleteProducts($objFormParam, $arrPreProductClassIds, $delete_product_class_id, $this->arrProductKeys);
949        }
950    }
951
952    /**
953     * お届け先を追加する.
954     *
955     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
956     * @return void
957     */
958    public function addShipping(&$objFormParam)
959    {
960        $arrShippingIds = $objFormParam->getValue('shipping_id');
961        $arrShippingIds[] = max($arrShippingIds) + 1;
962        $objFormParam->setValue('shipping_id', $arrShippingIds);
963    }
964
965    /**
966     * 会員情報をフォームに設定する.
967     *
968     * @param  integer      $customer_id  会員ID
969     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
970     * @return void
971     */
972    public function setCustomerTo($customer_id, &$objFormParam)
973    {
974        $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id);
975        foreach ($arrCustomer as $key => $val) {
976            $objFormParam->setValue('order_' . $key, $val);
977        }
978
979        // 誕生日の処理
980        if (!SC_Utils_Ex::isBlank($objFormParam->getValue('order_birth'))) {
981            $order_birth = substr($objFormParam->getValue('order_birth'), 0, 10);
982            $arrOrderBirth = explode("-", $order_birth);
983
984            $objFormParam->setValue('order_birth_year', intval($arrOrderBirth[0]));
985            $objFormParam->setValue('order_birth_month', intval($arrOrderBirth[1]));
986            $objFormParam->setValue('order_birth_day', intval($arrOrderBirth[2]));
987        }
988
989        $objFormParam->setValue('customer_id', $customer_id);
990        $objFormParam->setValue('customer_point', $arrCustomer['point']);
991    }
992
993    /**
994     * アンカーキーを取得する.
995     *
996     * @param  SC_FormParam                   $objFormParam SC_FormParam インスタンス
997     * @return string アンカーキーの文字列
998     */
999    public function getAnchorKey(&$objFormParam)
1000    {
1001        $ancor_key = $objFormParam->getValue('anchor_key');
1002        if (!SC_Utils_Ex::isBlank($ancor_key)) {
1003            return "location.hash='#" . htmlentities(urlencode($ancor_key), ENT_QUOTES) . "'";
1004        }
1005
1006        return '';
1007    }
1008
1009    /**
1010     * 商品を追加
1011     *
1012     * @param  SC_FormParam $objFormParam         SC_FormParam インスタンス
1013     * @param  integer      $add_product_class_id 追加商品規格ID
1014     * @return void
1015     */
1016    public function shipmentAddProduct(&$objFormParam, $add_product_class_id)
1017    {
1018        //複数配送に商品情報追加
1019        $select_shipping_id = $objFormParam->getValue('select_shipping_id');
1020
1021        //届け先に選択済みの商品がある場合
1022        $arrShipmentProducts = $this->getShipmentProducts($objFormParam);
1023
1024        if ($arrShipmentProducts['shipment_product_class_id'] && in_array($add_product_class_id, $arrShipmentProducts['shipment_product_class_id'][$select_shipping_id])) {
1025            foreach ($arrShipmentProducts['shipment_product_class_id'][$select_shipping_id] as $relation_index => $shipment_product_class_id) {
1026                if ($shipment_product_class_id == $add_product_class_id) {
1027                    $arrShipmentProducts['shipment_quantity'][$select_shipping_id][$relation_index]++;
1028                    break;
1029                }
1030            }
1031        } else {
1032            //届け先に選択商品がない場合
1033            $objProduct = new SC_Product_Ex();
1034            $arrAddProductInfo = $objProduct->getDetailAndProductsClass($add_product_class_id);
1035
1036            $arrShipmentProducts['shipment_product_class_id'][$select_shipping_id][] = $add_product_class_id;
1037            $arrShipmentProducts['shipment_product_code'][$select_shipping_id][]     = $arrAddProductInfo['product_code'];
1038            $arrShipmentProducts['shipment_product_name'][$select_shipping_id][]     = $arrAddProductInfo['name'];
1039            $arrShipmentProducts['shipment_price'][$select_shipping_id][]            = $arrAddProductInfo['price02'];
1040            $arrShipmentProducts['shipment_quantity'][$select_shipping_id][]         = 1;
1041
1042            //受注商品情報に追加
1043            $arrPreProductClassIds = $objFormParam->getValue('product_class_id');
1044            $arrProducts = $this->checkInsertOrderProducts($objFormParam, $arrPreProductClassIds, $add_product_class_id, $arrAddProductInfo);
1045            $objFormParam->setParam($arrProducts);
1046        }
1047        $objFormParam->setParam($arrShipmentProducts);
1048    }
1049
1050    /**
1051     * 商品を変更
1052     *
1053     * @param  SC_FormParam $objFormParam         SC_FormParam インスタンス
1054     * @param  integer      $edit_product_class_id 変更商品規格ID
1055     * @param  integer      $change_no            変更対象
1056     * @return void
1057     */
1058    public function shipmentEditProduct(&$objFormParam, $edit_product_class_id, $change_no)
1059    {
1060        $arrPreProductClassIds = $objFormParam->getValue('product_class_id');
1061        $select_shipping_id    = $objFormParam->getValue('select_shipping_id');
1062
1063        $arrShipmentProducts = $this->getShipmentProducts($objFormParam);
1064
1065        $pre_shipment_product_class_id = $arrShipmentProducts['shipment_product_class_id'][$select_shipping_id][$change_no];
1066        if ($pre_shipment_product_class_id == $edit_product_class_id) {
1067            // 商品規格に変更がない場合は何もしない
1068        } elseif (in_array($edit_product_class_id, $arrShipmentProducts['shipment_product_class_id'][$select_shipping_id])) {
1069            // 商品規格の変更によって商品の重複が発生する場合は一つにまとめる
1070            $arrShipmentProducts = $this->deleteShipment($objFormParam, $this->arrShipmentItemKeys, $select_shipping_id, $change_no);
1071            foreach ($arrShipmentProducts['shipment_product_class_id'][$select_shipping_id] as $relation_index => $shipment_product_class_id) {
1072                if ($shipment_product_class_id == $edit_product_class_id) {
1073                    $arrShipmentProducts['shipment_quantity'][$select_shipping_id][$relation_index] ++;
1074                    break;
1075                }
1076            }
1077        } else {
1078            $objProduct = new SC_Product_Ex();
1079            $arrAddProductInfo = $objProduct->getDetailAndProductsClass($edit_product_class_id);
1080
1081            //上書き
1082            $this->changeShipmentProducts($arrShipmentProducts, $arrAddProductInfo, $select_shipping_id, $change_no);
1083            //受注商品情報に追加
1084            $arrProducts = $this->checkInsertOrderProducts($objFormParam, $arrPreProductClassIds, $edit_product_class_id, $arrAddProductInfo);
1085            $objFormParam->setParam($arrProducts);
1086        }
1087        $objFormParam->setParam($arrShipmentProducts);
1088
1089        //更新のみの場合、全配列を持っていないので、新しい配列を取得
1090        $arrNewShipmentProducts = $this->getShipmentProducts($objFormParam);
1091        $is_product_delete = true;
1092        //変更前のproduct_class_idが他の届け先にも存在するか
1093        foreach ($arrNewShipmentProducts['shipment_product_class_id'] as $shipping_id => $arrShipmentProductClassIds) {
1094            if (in_array($pre_shipment_product_class_id, $arrShipmentProductClassIds)) {
1095                $is_product_delete = false;
1096                break;
1097            }
1098        }
1099
1100        //商品情報から削除
1101        if ($is_product_delete) {
1102            $this->checkDeleteProducts($objFormParam, $arrPreProductClassIds, $pre_shipment_product_class_id, $this->arrProductKeys);
1103        }
1104    }
1105
1106    /**
1107     * 複数配送のパラメータを取り出す
1108     *
1109     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
1110     * @return array        配送データ
1111     */
1112    public function getShipmentProducts(&$objFormParam)
1113    {
1114        $arrShipmentProducts['shipment_product_class_id']    = $objFormParam->getValue('shipment_product_class_id');
1115        $arrShipmentProducts['shipment_product_code']        = $objFormParam->getValue('shipment_product_code');
1116        $arrShipmentProducts['shipment_product_name']        = $objFormParam->getValue('shipment_product_name');
1117        $arrShipmentProducts['shipment_classcategory_name1'] = $objFormParam->getValue('shipment_classcategory_name1');
1118        $arrShipmentProducts['shipment_classcategory_name2'] = $objFormParam->getValue('shipment_classcategory_name2');
1119        $arrShipmentProducts['shipment_price']               = $objFormParam->getValue('shipment_price');
1120        $arrShipmentProducts['shipment_quantity']            = $objFormParam->getValue('shipment_quantity');
1121
1122        foreach ($arrShipmentProducts as $key => $value) {
1123            if (!is_array($value)) {
1124                $arrShipmentProducts[$key] = array();
1125            }
1126        }
1127
1128        return $arrShipmentProducts;
1129    }
1130
1131    /**
1132     * 変更対象のデータを上書きする
1133     *
1134     * @param  array    $arrShipmentProducts 変更対象配列
1135     * @param  array    $arrProductInfo      上書きデータ
1136     * @param  int      $shipping_id         配送先ID
1137     * @param  int      $no                  変更対象
1138     * @return void
1139     */
1140    public function changeShipmentProducts(&$arrShipmentProducts, $arrProductInfo, $shipping_id, $no)
1141    {
1142        $arrShipmentProducts['shipment_product_class_id'][$shipping_id][$no]    = $arrProductInfo['product_class_id'];
1143        $arrShipmentProducts['shipment_product_code'][$shipping_id][$no]        = $arrProductInfo['product_code'];
1144        $arrShipmentProducts['shipment_product_name'][$shipping_id][$no]        = $arrProductInfo['name'];
1145        $arrShipmentProducts['shipment_classcategory_name1'][$shipping_id][$no] = $arrProductInfo['classcategory_name1'];
1146        $arrShipmentProducts['shipment_classcategory_name2'][$shipping_id][$no] = $arrProductInfo['classcategory_name2'];
1147        $arrShipmentProducts['shipment_price'][$shipping_id][$no]               = $arrProductInfo['price02'];
1148        $arrShipmentProducts['shipment_quantity'][$shipping_id][$no]            = 1;
1149    }
1150
1151    /**
1152     * 商品側の総量計算&セット
1153     *
1154     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
1155     * @return void
1156     */
1157    public function setProductsQuantity(&$objFormParam)
1158    {
1159        $arrShipmentsItems = $objFormParam->getSwapArray(array('shipment_product_class_id', 'shipment_quantity'));
1160
1161        // 配送先が存在する時のみ、商品個数の再設定を行います
1162        if (!SC_Utils_Ex::isBlank($arrShipmentsItems)) {
1163            $arrUpdateQuantity = array();
1164            foreach ($arrShipmentsItems as $arritems) {
1165                foreach ($arritems['shipment_product_class_id'] as $relation_index => $shipment_product_class_id) {
1166                    $arrUpdateQuantity[$shipment_product_class_id] += $arritems['shipment_quantity'][$relation_index];
1167                }
1168            }
1169
1170            $arrProductsClass = $objFormParam->getValue('product_class_id');
1171            $arrQuantity = array();
1172            foreach ($arrProductsClass as $relation_key => $product_class_id) {
1173                $arrQuantity[$relation_key] = isset($arrUpdateQuantity[$product_class_id]) ? $arrUpdateQuantity[$product_class_id] : 0;
1174            }
1175            $objFormParam->setParam(array('quantity' => $arrQuantity));
1176        }
1177    }
1178
1179    /**
1180     * 削除対象の確認、削除をする
1181     *
1182     * @param  SC_FormParam $objFormParam                               SC_FormParam インスタンス
1183     * @param  array        $arrProductClassIds                       削除対象配列の商品規格ID
1184     * @param  integer      $delete_product_class_id 削除商品規? ?ID
1185     * @param  array        $arrDeleteKeys                              削除項目
1186     * @return void
1187     */
1188    public function checkDeleteProducts(&$objFormParam, $arrProductClassIds, $delete_product_class_id, $arrDeleteKeys)
1189    {
1190        foreach ($arrProductClassIds as $relation_index => $product_class_id) {
1191            //product_class_idの重複はないので、1つ削除したら完了
1192            if ($product_class_id == $delete_product_class_id) {
1193                foreach ($arrDeleteKeys as $delete_key) {
1194                    $arrProducts = $objFormParam->getValue($delete_key);
1195                    $arrUpdateParams = array();
1196                    foreach ($arrProducts as $index => $product_info) {
1197                        if ($index != $relation_index) {
1198                            $arrUpdateParams[$delete_key][] = $product_info;
1199                        }
1200                    }
1201                    $objFormParam->setParam($arrUpdateParams);
1202                }
1203                break;
1204            }
1205        }
1206    }
1207
1208    /**
1209     * 配送先商品の削除の削除
1210     *
1211     * @param  SC_FormParam $objFormParam          SC_FormParam インスタンス
1212     * @param  array        $arrShipmentDeleteKeys 削除項目
1213     * @param  int          $delete_shipping_id   削除配送ID
1214     * @param  int          $delete_no             削除対象
1215     * @return array
1216     */
1217    public function deleteShipment(&$objFormParam, $arrShipmentDeleteKeys, $delete_shipping_id, $delete_no)
1218    {
1219        $arrUpdateParams = array();
1220        foreach ($arrShipmentDeleteKeys as $delete_key) {
1221            $arrShipments = $objFormParam->getValue($delete_key);
1222            foreach ($arrShipments as $shipp_id => $arrKeyData) {
1223                if (empty($arrKeyData)) continue;
1224                foreach ($arrKeyData as $relation_index => $shipment_info) {
1225                    if ($relation_index != $delete_no || $shipp_id != $delete_shipping_id) {
1226                        $arrUpdateParams[$delete_key][$shipp_id][] = $shipment_info;
1227                    }
1228                }
1229            }
1230        }
1231        //$objFormParam->setParam($arrUpdateParams);
1232        return $arrUpdateParams;
1233    }
1234
1235    /**
1236     * 受注商品一覧側に商品を追加
1237     *
1238     * @param SC_FormParam  $objFormParam               SC_FormParam インスタンス
1239     * @param array         $arrProductClassIds        対象配列の商品規格ID
1240     * @param int           $insert_product_class_id    追加商品規格ID
1241     * @param array         $arrAddProductInfo          追加データ
1242     * @return array|null   $arrAddProducts             更新データ
1243     */
1244    public function checkInsertOrderProducts(&$objFormParam, $arrProductClassIds, $insert_product_class_id, $arrAddProductInfo)
1245    {
1246        if (!$arrProductClassIds || !in_array($insert_product_class_id, $arrProductClassIds)) {
1247            $arrAddProducts = array();
1248            $arrTax = SC_Helper_TaxRule_Ex::getTaxRule(0, $insert_product_class_id);
1249
1250            $arrAddProductInfo['product_name'] = ($arrAddProductInfo['product_name'])
1251                ? $arrAddProductInfo['product_name']
1252                : $arrAddProductInfo['name'];
1253
1254            $arrAddProductInfo['price'] = ($arrAddProductInfo['price'])
1255                ? $arrAddProductInfo['price']
1256                : $arrAddProductInfo['price02'];
1257
1258            $arrAddProductInfo['quantity'] = 1;
1259            $arrAddProductInfo['tax_rate'] = ($objFormParam->getValue('order_tax_rate') == '')
1260                ? $arrTax['tax_rate']
1261                : $objFormParam->getValue('order_tax_rate');
1262
1263            $arrAddProductInfo['tax_rule'] = ($objFormParam->getValue('order_tax_rule') == '')
1264                ? $arrTax['tax_rule']
1265                : $objFormParam->getValue('order_tax_rule');
1266
1267            foreach ($this->arrProductKeys as $insert_key) {
1268                $value = $objFormParam->getValue($insert_key);
1269                $arrAddProducts[$insert_key]   = (is_array($value))? $value: array();
1270                $arrAddProducts[$insert_key][] = $arrAddProductInfo[$insert_key];
1271            }
1272
1273            return $arrAddProducts;
1274        } else {
1275            //受注商品の数量は、複数配送側の集計で出しているので、重複しても数量を増やさない。
1276            return null;
1277        }
1278    }
1279}
Note: See TracBrowser for help on using the repository browser.