source: branches/version-2_13_0/data/class/pages/shopping/LC_Page_Shopping_Multiple.php @ 23126

Revision 23126, 14.1 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

  • 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/LC_Page_Ex.php';
25
26/**
27 * お届け先の複数指定 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Shopping_Multiple extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_title = 'お届け先の複数指定';
44        $this->httpCacheControl('nocache');
45    }
46
47    /**
48     * Page のプロセス.
49     *
50     * @return void
51     */
52    public function process()
53    {
54        parent::process();
55        $this->action();
56        $this->sendResponse();
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    public function action()
65    {
66        //決済処理中ステータスのロールバック
67        $objPurchase = new SC_Helper_Purchase_Ex();
68        $objPurchase->checkSessionPendingOrder();
69        $objPurchase->checkDbMyPendignOrder();
70        $objPurchase->checkDbAllPendingOrder();
71
72        $objSiteSess = new SC_SiteSession_Ex();
73        $objCartSess = new SC_CartSession_Ex();
74        $objPurchase = new SC_Helper_Purchase_Ex();
75        $objCustomer = new SC_Customer_Ex();
76        $objFormParam = new SC_FormParam_Ex();
77        $objAddress = new SC_Helper_Address_Ex();
78
79        // 複数配送先指定が無効な場合はエラー
80        if (USE_MULTIPLE_SHIPPING === false) {
81            SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
82            SC_Response_Ex::actionExit();
83        }
84
85        $this->tpl_uniqid = $objSiteSess->getUniqId();
86
87        $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase, $objAddress);
88        $this->tpl_addrmax = count($this->addrs) - 2; // 「選択してください」と会員の住所をカウントしない
89        $this->lfInitParam($objFormParam);
90
91        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
92
93        switch ($this->getMode()) {
94            case 'confirm':
95                $objFormParam->setParam($_POST);
96                $this->arrErr = $this->lfCheckError($objFormParam);
97                if (SC_Utils_Ex::isBlank($this->arrErr)) {
98                    // フォームの情報を一時保存しておく
99                    $_SESSION['multiple_temp'] = $objFormParam->getHashArray();
100                    $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
101                                                 $objCustomer, $objPurchase,
102                                                 $objAddress);
103                    $objSiteSess->setRegistFlag();
104
105                    SC_Response_Ex::sendRedirect('payment.php');
106                    SC_Response_Ex::actionExit();
107                }
108                break;
109
110            default:
111                $this->setParamToSplitItems($objFormParam, $objCartSess);
112        }
113
114        // 前のページから戻ってきた場合
115        if ($_GET['from'] == 'multiple') {
116            $objFormParam->setParam($_SESSION['multiple_temp']);
117        }
118        $this->arrForm = $objFormParam->getFormParamList();
119    }
120
121    /**
122     * フォームを初期化する.
123     *
124     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
125     * @return void
126     */
127    public function lfInitParam(&$objFormParam)
128    {
129        $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
130        $objFormParam->addParam('商品名', 'name');
131        $objFormParam->addParam('規格1', 'class_name1');
132        $objFormParam->addParam('規格2', 'class_name2');
133        $objFormParam->addParam('規格分類1', 'classcategory_name1');
134        $objFormParam->addParam('規格分類2', 'classcategory_name2');
135        $objFormParam->addParam('メイン画像', 'main_image');
136        $objFormParam->addParam('メイン一覧画像', 'main_list_image');
137        $objFormParam->addParam(SALE_PRICE_TITLE, 'price');
138        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1);
139        $objFormParam->addParam('お届け先', 'shipping', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
140        $objFormParam->addParam('カート番号', 'cart_no', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
141        $objFormParam->addParam('行数', 'line_of_num', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
142    }
143
144    /**
145     * カートの商品を数量ごとに分割し, フォームに設定する.
146     *
147     * @param  SC_FormParam   $objFormParam SC_FormParam インスタンス
148     * @param  SC_CartSession $objCartSess  SC_CartSession インスタンス
149     * @return void
150     */
151    public function setParamToSplitItems(&$objFormParam, &$objCartSess)
152    {
153        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
154        $arrItems = array();
155        $index = 0;
156        foreach (array_keys($cartLists) as $key) {
157            $arrProductsClass = $cartLists[$key]['productsClass'];
158            $quantity = (int) $cartLists[$key]['quantity'];
159            for ($i = 0; $i < $quantity; $i++) {
160                foreach ($arrProductsClass as $key2 => $val) {
161                    $arrItems[$key2][$index] = $val;
162                }
163                $arrItems['quantity'][$index] = 1;
164                $arrItems['price'][$index] = $cartLists[$key]['price'];
165                $index++;
166            }
167        }
168        $objFormParam->setParam($arrItems);
169        $objFormParam->setValue('line_of_num', $index);
170    }
171
172    /**
173     * 配送住所のプルダウン用連想配列を取得する.
174     *
175     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
176     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
177     *
178     * @param  SC_Customer        $objCustomer SC_Customer インスタンス
179     * @param  SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
180     * @return array              配送住所のプルダウン用連想配列
181     */
182    public function getDelivAddrs(&$objCustomer, &$objPurchase, &$objAddress)
183    {
184        $masterData = new SC_DB_MasterData_Ex();
185        $arrPref = $masterData->getMasterData('mtb_pref');
186
187        $arrResults = array('' => '選択してください');
188        // 会員ログイン時
189        if ($objCustomer->isLoginSuccess(true)) {
190            $addr = array(
191                array(
192                    'other_deliv_id'    => NULL,
193                    'customer_id'       => $objCustomer->getValue('customer_id'),
194                    'name01'            => $objCustomer->getValue('name01'),
195                    'name02'            => $objCustomer->getValue('name02'),
196                    'kana01'            => $objCustomer->getValue('kana01'),
197                    'kana02'            => $objCustomer->getValue('kana02'),
198                    'zip01'             => $objCustomer->getValue('zip01'),
199                    'zip02'             => $objCustomer->getValue('zip02'),
200                    'pref'              => $objCustomer->getValue('pref'),
201                    'addr01'            => $objCustomer->getValue('addr01'),
202                    'addr02'            => $objCustomer->getValue('addr02'),
203                    'tel01'             => $objCustomer->getValue('tel01'),
204                    'tel02'             => $objCustomer->getValue('tel02'),
205                    'tel03'             => $objCustomer->getValue('tel03'),
206                )
207            );
208            $arrAddrs = array_merge($addr, $objAddress->getList($objCustomer->getValue('customer_id')));
209            foreach ($arrAddrs as $val) {
210                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
211                $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
212                    . ' ' . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
213            }
214        }
215        // 非会員
216        else {
217            $arrShippings = $objPurchase->getShippingTemp();
218            foreach ($arrShippings as $shipping_id => $val) {
219                $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
220                    . ' ' . $arrPref[$val['shipping_pref']]
221                    . $val['shipping_addr01'] . $val['shipping_addr02'];
222            }
223        }
224
225        return $arrResults;
226    }
227
228    /**
229     * 入力チェックを行う.
230     *
231     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
232     * @return array        エラー情報の配列
233     */
234    public function lfCheckError(&$objFormParam)
235    {
236        $objCartSess = new SC_CartSession_Ex();
237
238        $objFormParam->convParam();
239        // 数量未入力は0に置換
240        $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0));
241
242        $arrErr = $objFormParam->checkError();
243
244        $arrParams = $objFormParam->getSwapArray();
245
246        if (empty($arrErr)) {
247            foreach ($arrParams as $index => $arrParam) {
248                // 数量0で、お届け先を選択している場合
249                if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) {
250                    $arrErr['shipping'][$index] = '※ 数量が0の場合、お届け先を入力できません。<br />';;
251                }
252                // 数量の入力があり、お届け先を選択していない場合
253                if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) {
254                    $arrErr['shipping'][$index] = '※ お届け先が入力されていません。<br />';
255                }
256            }
257        }
258
259        // 入力エラーが無い場合、カゴの中身との数量の整合を確認
260        if (empty($arrErr)) {
261            $arrQuantity = array();
262            // 入力内容を集計
263            foreach ($arrParams as $arrParam) {
264                $product_class_id = $arrParam['product_class_id'];
265                $arrQuantity[$product_class_id] += $arrParam['quantity'];
266            }
267            // カゴの中身と突き合わせ
268            $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
269            foreach ($cartLists as $arrCartRow) {
270                $product_class_id = $arrCartRow['id'];
271                // 差異がある場合、エラーを記録
272                if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) {
273                    foreach ($arrParams as $index => $arrParam) {
274                        if ($arrParam['product_class_id'] == $product_class_id) {
275                            $arrErr['quantity'][$index] = '※ 数量合計を「' . $arrCartRow['quantity'] .'」にしてください。<br />';
276                        }
277                    }
278                }
279            }
280        }
281
282        return $arrErr;
283    }
284
285    /**
286     * 複数配送情報を一時保存する.
287     *
288     * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
289     *
290     * @param  integer            $uniqid       一時受注テーブルのユニークID
291     * @param  SC_FormParam       $objFormParam SC_FormParam インスタンス
292     * @param  SC_Customer        $objCustomer  SC_Customer インスタンス
293     * @param  SC_Helper_Purchase $objPurchase  SC_Helper_Purchase インスタンス
294     * @return void
295     */
296    public function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer, &$objPurchase, &$objAddress)
297    {
298        $arrParams = $objFormParam->getSwapArray();
299
300        foreach ($arrParams as $arrParam) {
301            $other_deliv_id = $arrParam['shipping'];
302
303            if ($objCustomer->isLoginSuccess(true)) {
304                if ($other_deliv_id != 0) {
305                    $otherDeliv = $objAddress->getAddress($other_deliv_id);
306                    foreach ($otherDeliv as $key => $val) {
307                        $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
308                    }
309                } else {
310                    $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
311                                                   'shipping');
312                }
313            } else {
314                $arrValues = $objPurchase->getShippingTemp();
315            }
316            $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
317        }
318
319        $objPurchase->clearShipmentItemTemp();
320
321        foreach ($arrValues as $shipping_id => $arrVal) {
322            $objPurchase->saveShippingTemp($arrVal, $shipping_id);
323        }
324
325        foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
326            foreach ($arrProductClassIds as $product_class_id => $quantity) {
327                if ($quantity == 0) continue;
328                $objPurchase->setShipmentItemTemp($other_deliv_id,
329                                                  $product_class_id,
330                                                  $quantity);
331            }
332        }
333
334        //不必要な配送先を削除
335        foreach ($_SESSION['shipping'] as $id=>$arrShipping) {
336            if (!isset($arrShipping['shipment_item'])) {
337                $objPurchase->unsetOneShippingTemp($id);
338            }
339        }
340
341        // $arrValues[0] には, 購入者の情報が格納されている
342        $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
343    }
344}
Note: See TracBrowser for help on using the repository browser.