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

Revision 20670, 10.2 KB checked in by nanasess, 13 years ago (diff)

#914 (複数のお届け先選択>選択したお届け先に送る>お支払方法選択画面で戻るボタンでお届け先指定画面に戻る)

  • フォームを多次元配列に修正
  • 何回も戻るとカートの商品数が増加していたのを修正
  • 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_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->lfInitParam($objFormParam);
77
78        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
79
80        switch ($this->getMode()) {
81            case 'confirm':
82                $objFormParam->setParam($_POST);
83                $this->arrErr = $this->lfCheckError($objFormParam);
84                if (SC_Utils_Ex::isBlank($this->arrErr)) {
85                    // フォームの情報を一時保存しておく
86                    $_SESSION['multiple_temp'] = $objFormParam->getHashArray();
87                    $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
88                                                 $objCustomer, $objPurchase,
89                                                 $objCartSess);
90                    $objSiteSess->setRegistFlag();
91                    SC_Response_Ex::sendRedirect("payment.php");
92                    exit;
93                }
94                break;
95
96        default:
97            $this->setParamToSplitItems($objFormParam, $objCartSess);
98        }
99
100        // 前のページから戻ってきた場合
101        if ($_GET['from'] == 'multiple') {
102            $objFormParam->setParam($_SESSION['multiple_temp']);
103        }
104
105        $this->arrForm = $objFormParam->getFormParamList();
106    }
107
108    /**
109     * デストラクタ.
110     *
111     * @return void
112     */
113    function destroy() {
114        parent::destroy();
115    }
116
117    /**
118     * フォームを初期化する.
119     *
120     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
121     * @return void
122     */
123    function lfInitParam(&$objFormParam) {
124        $objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
125        $objFormParam->addParam("商品名", "name");
126        $objFormParam->addParam("規格1", "class_name1");
127        $objFormParam->addParam("規格2", "class_name2");
128        $objFormParam->addParam("規格分類1", "classcategory_name1");
129        $objFormParam->addParam("規格分類2", "classcategory_name2");
130        $objFormParam->addParam("メイン画像", "main_image");
131        $objFormParam->addParam("メイン一覧画像", "main_list_image");
132        $objFormParam->addParam("販売価格", "price02");
133        $objFormParam->addParam("数量", 'quantity', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
134        $objFormParam->addParam("配送先住所", 'shipping', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
135        $objFormParam->addParam("カート番号", "cart_no", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
136        $objFormParam->addParam("行数", "line_of_num", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
137    }
138
139    /**
140     * カートの商品を数量ごとに分割し, フォームに設定する.
141     *
142     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
143     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
144     * @return void
145     */
146    function setParamToSplitItems(&$objFormParam, &$objCartSess) {
147        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
148        $arrItems = array();
149        $index = 0;
150        foreach (array_keys($cartLists) as $key) {
151            $arrProductsClass = $cartLists[$key]['productsClass'];
152            $quantity = (int) $cartLists[$key]['quantity'];
153            for ($i = 0; $i < $quantity; $i++) {
154                foreach ($arrProductsClass as $key => $val) {
155                    $arrItems[$key][$index] = $val;
156                }
157                $arrItems['quantity'][$index] = 1;
158                $index++;
159            }
160        }
161        $objFormParam->setParam($arrItems);
162        $objFormParam->setValue('line_of_num', $index);
163    }
164
165    /**
166     * 配送住所のプルダウン用連想配列を取得する.
167     *
168     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
169     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
170     *
171     * @param SC_Customer $objCustomer SC_Customer インスタンス
172     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
173     * @param integer $uniqid 受注一時テーブルのユニークID
174     * @return array 配送住所のプルダウン用連想配列
175     */
176    function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
177        $masterData = new SC_DB_MasterData();
178        $arrPref = $masterData->getMasterData('mtb_pref');
179
180        // 会員ログイン時
181        if ($objCustomer->isLoginSuccess(true)) {
182            $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
183            $arrResults = array();
184            foreach ($arrAddrs as $val) {
185                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
186                $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
187                    . " " . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
188            }
189        }
190        // 非会員
191        else {
192            $arrShippings = $objPurchase->getShippingTemp();
193            foreach ($arrShippings as $shipping_id => $val) {
194                $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
195                    . " " . $arrPref[$val['shipping_pref']]
196                    . $val['shipping_addr01'] . $val['shipping_addr02'];
197            }
198        }
199        return $arrResults;
200    }
201
202    /**
203     * 入力チェックを行う.
204     *
205     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
206     * @return array エラー情報の配列
207     */
208    function lfCheckError(&$objFormParam) {
209        $objFormParam->convParam();
210        return $objFormParam->checkError();
211    }
212
213    /**
214     * 複数配送情報を一時保存する.
215     *
216     * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
217     *
218     * @param integer $uniqid 一時受注テーブルのユニークID
219     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
220     * @param SC_Customer $objCustomer SC_Customer インスタンス
221     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
222     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
223     * @return void
224     */
225    function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer,
226                                   &$objPurchase, &$objCartSess) {
227        $objQuery =& SC_Query_Ex::getSingletonInstance();
228
229        $arrParams = $objFormParam->getHashArray();
230        $total = $arrParams['line_of_num'];
231
232        for ($index = 0; $index < $total; $index++) {
233            $other_deliv_id = $arrParams['shipping'][$index];
234
235            if ($objCustomer->isLoginSuccess(true)) {
236                if ($other_deliv_id != 0) {
237                    $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
238                                                    "other_deliv_id = ?",
239                                                    array($other_deliv_id));
240                    foreach ($otherDeliv[0] as $key => $val) {
241                        $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
242                    }
243                } else {
244                    $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
245                                                   'shipping');
246                }
247            }
248            $arrItemTemp[$other_deliv_id][$arrParams['product_class_id'][$index]] += $arrParams['quantity'][$index];
249        }
250
251        foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
252            foreach ($arrProductClassIds as $product_class_id => $quantity) {
253                $objPurchase->setShipmentItemTemp($other_deliv_id,
254                                                  $product_class_id,
255                                                  $quantity);
256            }
257        }
258
259        foreach ($arrValues as $shipping_id => $val) {
260            $objPurchase->saveShippingTemp($val, $shipping_id);
261        }
262
263        $objPurchase->shippingItemTempToCart($objCartSess);
264        // $arrValues[0] には, 購入者の情報が格納されている
265        $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
266    }
267}
268?>
Note: See TracBrowser for help on using the repository browser.