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

Revision 23326, 61.2 KB checked in by undertree, 10 years ago (diff)

#2411 非会員購入時に生年月日が登録されない 受注登録時の生年月日の挿入箇所修正

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