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 |
---|
25 | require_once(CLASS_REALDIR . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * お届け先の複数指定 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class 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[$other_deliv_id]['shipping_' . $key] = $val; |
---|
116 | } |
---|
117 | } else { |
---|
118 | $objPurchase->copyFromCustomer($sqlval[0], $objCustomer, |
---|
119 | "shipping"); |
---|
120 | } |
---|
121 | } |
---|
122 | $sqlval[$other_deliv_id]['deliv_id'] = $objPurchase->getDeliv($this->cartKey); |
---|
123 | $objPurchase->setShipmentItemTemp($other_deliv_id, $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->shippingItemTempToCart($objCartSess); |
---|
132 | $objPurchase->saveOrderTemp($uniqid, $sqlval[0], $objCustomer); |
---|
133 | $objSiteSess->setRegistFlag(); |
---|
134 | SC_Response_Ex::sendRedirect("payment.php"); |
---|
135 | exit; |
---|
136 | } |
---|
137 | break; |
---|
138 | |
---|
139 | default: |
---|
140 | } |
---|
141 | |
---|
142 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
143 | $this->transactionid = SC_Helper_Session_Ex::getToken(); |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * デストラクタ. |
---|
148 | * |
---|
149 | * @return void |
---|
150 | */ |
---|
151 | function destroy() { |
---|
152 | parent::destroy(); |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * フォームを初期化する. |
---|
157 | */ |
---|
158 | function lfInitParam($items) { |
---|
159 | for ($i = 0; $i < count($items); $i++) { |
---|
160 | $this->objFormParam->addParam("商品規格ID", "product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
161 | $this->objFormParam->addParam("数量", "quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
162 | $this->objFormParam->addParam("配送先住所", "shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
163 | $this->objFormParam->addParam("カート番号", "cart_no" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | /** |
---|
169 | * カートの商品を数量ごとに分割する |
---|
170 | */ |
---|
171 | function splitItems(&$objCartSess) { |
---|
172 | $cartLists =& $objCartSess->getCartList($objCartSess->getKey()); |
---|
173 | foreach (array_keys($cartLists) as $key) { |
---|
174 | for ($i = 0; $i < $cartLists[$key]['quantity']; $i++) { |
---|
175 | $items[] =& $cartLists[$key]['productsClass']; |
---|
176 | } |
---|
177 | } |
---|
178 | return $items; |
---|
179 | } |
---|
180 | |
---|
181 | /** |
---|
182 | * 配送住所のプルダウン用連想配列を取得する. |
---|
183 | * |
---|
184 | * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する. |
---|
185 | * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する. |
---|
186 | */ |
---|
187 | function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) { |
---|
188 | if ($objCustomer->isLoginSuccess()) { |
---|
189 | $addrs = $objCustomer->getCustomerAddress($_SESSION['customer']['customer_id']); |
---|
190 | $results = array(); |
---|
191 | foreach ($addrs as $key => $val) { |
---|
192 | $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id']; |
---|
193 | $results[$other_deliv_id] = $val['name01'] . $val['name02'] |
---|
194 | . " " . $this->arrPref[$val['pref']] . $val['addr01'] . $val['addr02']; |
---|
195 | } |
---|
196 | } else { |
---|
197 | $shipping = $objPurchase->getShippingTemp(); |
---|
198 | foreach ($shipping as $shipping_id => $val) { |
---|
199 | $results[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02'] |
---|
200 | . " " . $this->arrPref[$val['shipping_pref']] |
---|
201 | . $val['shipping_addr01'] . $val['shipping_addr02']; |
---|
202 | } |
---|
203 | } |
---|
204 | return $results; |
---|
205 | } |
---|
206 | |
---|
207 | function lfCheckError(&$objFormParam) { |
---|
208 | $objFormParam->convParam(); |
---|
209 | return $objFormParam->checkError(); |
---|
210 | } |
---|
211 | } |
---|
212 | ?> |
---|