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

Revision 20116, 9.0 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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-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        $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();
67        $objCartSess = new SC_CartSession();
68        $objPurchase = new SC_Helper_Purchase_Ex();
69        $objCustomer = new SC_Customer();
70        $objFormParam = new SC_FormParam();
71
72        $this->tpl_uniqid = $objSiteSess->getUniqId();
73
74        $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase,
75                                            $this->tpl_uniqid);
76        $this->items = $this->splitItems($objCartSess);
77
78        $this->lfInitParam($this->items, $objFormParam);
79        $objFormParam->setParam($_POST);
80        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
81
82        if ($_SERVER["REQUEST_METHOD"] == "POST") {
83            if (!SC_Helper_Session_Ex::isValidToken()) {
84                SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
85                exit;
86            }
87        }
88
89        switch ($this->getMode()) {
90            case 'confirm':
91                $this->arrErr = $this->lfCheckError($objFormParam);
92                if (SC_Utils_Ex::isBlank($this->arrErr)) {
93                    $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
94                                                 $objCustomer, $objPurchase,
95                                                 $objCartSess);
96                    $objSiteSess->setRegistFlag();
97                    SC_Response_Ex::sendRedirect("payment.php");
98                    exit;
99                }
100                break;
101
102        default:
103        }
104
105        $this->arrForm = $objFormParam->getFormParamList();
106        $this->transactionid = SC_Helper_Session_Ex::getToken();
107    }
108
109    /**
110     * デストラクタ.
111     *
112     * @return void
113     */
114    function destroy() {
115        parent::destroy();
116    }
117
118    /**
119     * フォームを初期化する.
120     *
121     * @param array $arrItems 数量ごとに分割した, カートの商品情報の配列
122     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
123     * @return void
124     */
125    function lfInitParam($arrItems, $objFormParam) {
126        for ($i = 0; $i < count($arrItems); $i++) {
127            $objFormParam->addParam("商品規格ID", "product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
128            $objFormParam->addParam("数量", "quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
129            $objFormParam->addParam("配送先住所", "shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
130            $objFormParam->addParam("カート番号", "cart_no" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
131        }
132    }
133
134    /**
135     * カートの商品を数量ごとに分割する
136     *
137     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
138     * @return array 数量ごとに分割した, カートの商品情報の配列
139     */
140    function splitItems(&$objCartSess) {
141        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
142        foreach (array_keys($cartLists) as $key) {
143            for ($i = 0; $i < $cartLists[$key]['quantity']; $i++) {
144                $items[] =& $cartLists[$key]['productsClass'];
145            }
146        }
147        return $items;
148    }
149
150    /**
151     * 配送住所のプルダウン用連想配列を取得する.
152     *
153     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
154     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
155     *
156     * @param SC_Customer $objCustomer SC_Customer インスタンス
157     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
158     * @param integer $uniqid 受注一時テーブルのユニークID
159     * @return array 配送住所のプルダウン用連想配列
160     */
161    function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
162        $masterData = new SC_DB_MasterData();
163        $arrPref = $masterData->getMasterData('mtb_pref');
164
165        // 会員ログイン時
166        if ($objCustomer->isLoginSuccess(true)) {
167            $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
168            $arrResults = array();
169            foreach ($arrAddrs as $val) {
170                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
171                $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
172                    . " " . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
173            }
174        }
175        // 非会員
176        else {
177            $arrShippings = $objPurchase->getShippingTemp();
178            foreach ($arrShippings as $shipping_id => $val) {
179                $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
180                    . " " . $arrPref[$val['shipping_pref']]
181                    . $val['shipping_addr01'] . $val['shipping_addr02'];
182            }
183        }
184        return $arrResults;
185    }
186
187    /**
188     * 入力チェックを行う.
189     *
190     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
191     * @return array エラー情報の配列
192     */
193    function lfCheckError(&$objFormParam) {
194        $objFormParam->convParam();
195        return $objFormParam->checkError();
196    }
197
198    /**
199     * 複数配送情報を一時保存する.
200     *
201     * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
202     *
203     * @param integer $uniqid 一時受注テーブルのユニークID
204     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
205     * @param SC_Customer $objCustomer SC_Customer インスタンス
206     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
207     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
208     * @return void
209     */
210    function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer,
211                                   &$objPurchase, &$objCartSess) {
212        $objQuery =& SC_Query::getSingletonInstance();
213
214        $arrParams = $objFormParam->getHashArray();
215        $i = 0;
216        while ($arrParams['cart_no' . $i] != null) {
217            $other_deliv_id = $arrParams['shipping' . $i];
218
219            if ($objCustomer->isLoginSuccess(true)) {
220                if ($other_deliv_id != 0) {
221                    $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
222                                                    "other_deliv_id = ?",
223                                                    array($other_deliv_id));
224                    foreach ($otherDeliv[0] as $key => $val) {
225                        $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
226                    }
227                } else {
228                    $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
229                                                   "shipping");
230                }
231            }
232
233            $objPurchase->setShipmentItemTemp($other_deliv_id,
234                                              $arrParams['product_class_id' . $i],
235                                              $arrParams['quantity' . $i]);
236            $i++;
237        }
238
239        foreach ($arrValues as $shipping_id => $val) {
240            $objPurchase->saveShippingTemp($val, $shipping_id);
241        }
242
243        $objPurchase->shippingItemTempToCart($objCartSess);
244        // $arrValues[0] には, 購入者の情報が格納されている
245        $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
246    }
247}
248?>
Note: See TracBrowser for help on using the repository browser.