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

Revision 21437, 12.8 KB checked in by shutta, 12 years ago (diff)

#1627 (複数配送先指定機能の使用可否をパラメータ設定化)
ロジック側での不正入力チェックを実装。

  • 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-2011 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
73        // 複数配送先指定が無効な場合はエラー
74        if (USE_MULTIPLE_SHIPPING === false) {
75            SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
76            exit;
77        }
78
79        $this->tpl_uniqid = $objSiteSess->getUniqId();
80
81        $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase,
82                                            $this->tpl_uniqid);
83        $this->tpl_addrmax = count($this->addrs);
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);
98                    $objSiteSess->setRegistFlag();
99                    SC_Response_Ex::sendRedirect("payment.php");
100                    exit;
101                }
102                break;
103
104            default:
105                $this->setParamToSplitItems($objFormParam, $objCartSess);
106        }
107
108        // 前のページから戻ってきた場合
109        if ($_GET['from'] == 'multiple') {
110            $objFormParam->setParam($_SESSION['multiple_temp']);
111        }
112
113        $this->arrForm = $objFormParam->getFormParamList();
114    }
115
116    /**
117     * デストラクタ.
118     *
119     * @return void
120     */
121    function destroy() {
122        parent::destroy();
123    }
124
125    /**
126     * フォームを初期化する.
127     *
128     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
129     * @return void
130     */
131    function lfInitParam(&$objFormParam) {
132        $objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
133        $objFormParam->addParam("商品名", "name");
134        $objFormParam->addParam("規格1", "class_name1");
135        $objFormParam->addParam("規格2", "class_name2");
136        $objFormParam->addParam("規格分類1", "classcategory_name1");
137        $objFormParam->addParam("規格分類2", "classcategory_name2");
138        $objFormParam->addParam("メイン画像", "main_image");
139        $objFormParam->addParam("メイン一覧画像", "main_list_image");
140        $objFormParam->addParam("販売価格", "price");
141        $objFormParam->addParam("数量", 'quantity', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
142        $objFormParam->addParam("配送先住所", 'shipping', INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
143        $objFormParam->addParam("カート番号", "cart_no", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
144        $objFormParam->addParam("行数", "line_of_num", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
145    }
146
147    /**
148     * カートの商品を数量ごとに分割し, フォームに設定する.
149     *
150     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
151     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
152     * @return void
153     */
154    function setParamToSplitItems(&$objFormParam, &$objCartSess) {
155        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
156        $arrItems = array();
157        $index = 0;
158        foreach (array_keys($cartLists) as $key) {
159            $arrProductsClass = $cartLists[$key]['productsClass'];
160            $quantity = (int) $cartLists[$key]['quantity'];
161            for ($i = 0; $i < $quantity; $i++) {
162                foreach ($arrProductsClass as $key2 => $val) {
163                    $arrItems[$key2][$index] = $val;
164                }
165                $arrItems['quantity'][$index] = 1;
166                $arrItems['price'][$index] = $cartLists[$key]['price'];
167                $index++;
168            }
169        }
170        $objFormParam->setParam($arrItems);
171        $objFormParam->setValue('line_of_num', $index);
172    }
173
174    /**
175     * 配送住所のプルダウン用連想配列を取得する.
176     *
177     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
178     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
179     *
180     * @param SC_Customer $objCustomer SC_Customer インスタンス
181     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
182     * @param integer $uniqid 受注一時テーブルのユニークID
183     * @return array 配送住所のプルダウン用連想配列
184     */
185    function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
186        $masterData = new SC_DB_MasterData();
187        $arrPref = $masterData->getMasterData('mtb_pref');
188
189        $arrResults = array('' => '選択してください');
190        // 会員ログイン時
191        if ($objCustomer->isLoginSuccess(true)) {
192            $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
193            foreach ($arrAddrs as $val) {
194                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
195                $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
196                    . " " . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
197            }
198        }
199        // 非会員
200        else {
201            $arrShippings = $objPurchase->getShippingTemp();
202            foreach ($arrShippings as $shipping_id => $val) {
203                $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
204                    . " " . $arrPref[$val['shipping_pref']]
205                    . $val['shipping_addr01'] . $val['shipping_addr02'];
206            }
207        }
208        return $arrResults;
209    }
210
211    /**
212     * 入力チェックを行う.
213     *
214     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
215     * @return array エラー情報の配列
216     */
217    function lfCheckError(&$objFormParam) {
218        $objCartSess = new SC_CartSession_Ex();
219
220        $objFormParam->convParam();
221        // 数量未入力は0に置換
222        $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0));
223
224        $arrErr = $objFormParam->checkError();
225
226        $arrParams = $objFormParam->getSwapArray();
227
228        if (empty($arrErr)) {
229            foreach ($arrParams as $index => $arrParam) {
230                // 数量0で、お届け先を選択している場合
231                if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) {
232                    $arrErr['shipping'][$index] = '※ 数量が0の場合、お届け先を入力できません。<br />';;
233                }
234                // 数量の入力があり、お届け先を選択していない場合
235                if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) {
236                    $arrErr['shipping'][$index] = '※ お届け先が入力されていません。<br />';
237                }
238            }
239        }
240
241        // 入力エラーが無い場合、カゴの中身との数量の整合を確認
242        if (empty($arrErr)) {
243            $arrQuantity = array();
244            // 入力内容を集計
245            foreach ($arrParams as $arrParam) {
246                $product_class_id = $arrParam['product_class_id'];
247                $arrQuantity[$product_class_id] += $arrParam['quantity'];
248            }
249            // カゴの中身と突き合わせ
250            $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
251            foreach ($cartLists as $arrCartRow) {
252                $product_class_id = $arrCartRow['id'];
253                // 差異がある場合、エラーを記録
254                if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) {
255                    foreach ($arrParams as $index => $arrParam) {
256                        if ($arrParam['product_class_id'] == $product_class_id) {
257                            $arrErr['quantity'][$index] = '※ 数量合計を「' . $arrCartRow['quantity'] .'」にしてください。<br />';
258                        }
259                    }
260                }
261            }
262        }
263        return $arrErr;
264    }
265
266    /**
267     * 複数配送情報を一時保存する.
268     *
269     * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
270     *
271     * @param integer $uniqid 一時受注テーブルのユニークID
272     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
273     * @param SC_Customer $objCustomer SC_Customer インスタンス
274     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
275     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
276     * @return void
277     */
278    function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer,
279                                   &$objPurchase, &$objCartSess) {
280        $objQuery =& SC_Query_Ex::getSingletonInstance();
281
282        $arrParams = $objFormParam->getSwapArray();
283
284        foreach ($arrParams as $arrParam) {
285            $other_deliv_id = $arrParam['shipping'];
286
287            if ($objCustomer->isLoginSuccess(true)) {
288                if ($other_deliv_id != 0) {
289                    $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
290                                                    "other_deliv_id = ?",
291                                                    array($other_deliv_id));
292                    foreach ($otherDeliv[0] as $key => $val) {
293                        $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
294                    }
295                } else {
296                    $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
297                                                   'shipping');
298                }
299            } else {
300                $arrValues = $objPurchase->getShippingTemp();
301            }
302            $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
303        }
304
305        $objPurchase->clearShipmentItemTemp();
306
307        foreach ($arrValues as $shipping_id => $arrVal) {
308            $objPurchase->saveShippingTemp($arrVal, $shipping_id);
309        }
310
311        foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
312            foreach ($arrProductClassIds as $product_class_id => $quantity) {
313                if ($quantity == 0) continue;
314                $objPurchase->setShipmentItemTemp($other_deliv_id,
315                                                  $product_class_id,
316                                                  $quantity);
317            }
318        }
319
320        // $arrValues[0] には, 購入者の情報が格納されている
321        $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
322    }
323}
Note: See TracBrowser for help on using the repository browser.