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

Revision 22857, 14.1 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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