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

Revision 21864, 12.8 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

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