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

Revision 19923, 7.5 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

  • お届け日/お届け時間が反映されるよう修正
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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_REALDIR . "pages/LC_Page.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 {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $masterData = new SC_DB_MasterData();
47        $this->arrPref = $masterData->getMasterData('mtb_pref');
48        $this->tpl_title = "お届け先の複数指定";
49        $this->httpCacheControl('nocache');
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    function process() {
58        $this->action();
59        $this->sendResponse();
60    }
61
62    /**
63     * Page のプロセス.
64     *
65     * @return void
66     */
67    function action() {
68        $objSiteSess = new SC_SiteSession();
69        $objCartSess = new SC_CartSession();
70        $objPurchase = new SC_Helper_Purchase_Ex();
71        $objCustomer = new SC_Customer();
72        $objQuery = SC_Query::getSingletonInstance();
73        $this->objFormParam = new SC_FormParam();
74
75        $uniqid = $objSiteSess->getUniqId();
76
77        $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase, $uniqid);
78        $this->items = $this->splitItems($objCartSess);
79
80        $this->lfInitParam($this->items);
81        $this->objFormParam->setParam($_POST);
82
83        $objPurchase->verifyChangeCart($uniqid, $objCartSess);
84
85        $this->tpl_uniqid = $uniqid;
86
87        $this->cartKey = $objCartSess->getKey();
88        if ($_SERVER["REQUEST_METHOD"] == "POST") {
89            if (!SC_Helper_Session_Ex::isValidToken()) {
90                SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
91            }
92        }
93
94        if (!isset($_POST['mode'])) $_POST['mode'] = "";
95
96        switch ($_POST['mode']) {
97            case 'delete':
98                // TODO
99                break;
100
101            case 'confirm':
102                $this->arrErr = $this->lfCheckError($this->objFormParam);
103                if (SC_Utils_Ex::isBlank($this->arrErr)) {
104                    // TODO リファクタリング
105                    $params = $this->objFormParam->getHashArray();
106                    $i = 0;
107                    while ($params['cart_no' . $i] != null) {
108                        $other_deliv_id = $params['shipping' . $i];
109                        if ($objCustomer->isLoginSuccess()) {
110                            if ($other_deliv_id != 0) {
111                                $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
112                                                                "other_deliv_id = ?",
113                                                                array($other_deliv_id));
114                                foreach ($otherDeliv[0] as $key => $val) {
115                                    $sqlval[$i]['shipping_' . $key] = $val;
116                                }
117                            } else {
118                                $objPurchase->copyFromCustomer($sqlval[$i], $objCustomer,
119                                                               "shipping");
120                            }
121                        }
122                        $sqlval[$i]['deliv_id'] = $objPurchase->getDeliv($this->cartKey);
123                        $objPurchase->setShipmentItemTemp($i, $params['product_class_id' . $i], $params['quantity' . $i]);
124                        $i++;
125                    }
126
127                    foreach ($sqlval as $shipping_id => $val) {
128                        $objPurchase->saveShippingTemp($val, $shipping_id);
129                    }
130
131                    $objPurchase->saveOrderTemp($uniqid, $sqlval[0], $objCustomer);
132                    $objSiteSess->setRegistFlag();
133                    SC_Response_Ex::sendRedirect("payment.php");
134                    exit;
135                }
136                break;
137
138        default:
139        }
140
141        $this->arrForm = $this->objFormParam->getFormParamList();
142        $this->transactionid = SC_Helper_Session_Ex::getToken();
143    }
144
145    /**
146     * デストラクタ.
147     *
148     * @return void
149     */
150    function destroy() {
151        parent::destroy();
152    }
153
154    /**
155     * フォームを初期化する.
156     */
157    function lfInitParam($items) {
158        for ($i = 0; $i < count($items); $i++) {
159            $this->objFormParam->addParam("商品規格ID", "product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
160            $this->objFormParam->addParam("数量", "quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
161            $this->objFormParam->addParam("配送先住所", "shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
162            $this->objFormParam->addParam("カート番号", "cart_no" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
163        }
164    }
165
166
167    /**
168     * カートの商品を数量ごとに分割する
169     */
170    function splitItems(&$objCartSess) {
171        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
172        foreach (array_keys($cartLists) as $key) {
173            for ($i = 0; $i < $cartLists[$key]['quantity']; $i++) {
174                $items[] =& $cartLists[$key]['productsClass'];
175            }
176        }
177        return $items;
178    }
179
180    /**
181     * 配送住所のプルダウン用連想配列を取得する.
182     *
183     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
184     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
185     */
186    function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
187        if ($objCustomer->isLoginSuccess()) {
188            $addrs = $objCustomer->getCustomerAddress($_SESSION['customer']['customer_id']);
189            $results = array();
190            foreach ($addrs as $key => $val) {
191                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
192                $results[$other_deliv_id] = $val['name01'] . $val['name02']
193                    . " " . $this->arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
194            }
195        } else {
196            $shipping = $objPurchase->getShippingTemp();
197            foreach ($shipping as $shipping_id => $val) {
198                $results[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
199                    . " " . $this->arrPref[$val['shipping_pref']]
200                    . $val['shipping_addr01'] . $val['shipping_addr02'];
201            }
202        }
203        return $results;
204    }
205
206    function lfCheckError(&$objFormParam) {
207        $objFormParam->convParam();
208        return $objFormParam->checkError();
209    }
210}
211?>
Note: See TracBrowser for help on using the repository browser.