source: branches/version-2_12-dev/data/class/pages/shopping/LC_Page_Shopping_Multiple.php @ 22546

Revision 22546, 14.0 KB checked in by h_yoshimoto, 11 years ago (diff)

#1958 r22497 の内容をマージ

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