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

Revision 21190, 12.6 KB checked in by shutta, 13 years ago (diff)

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