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

Revision 22782, 14.1 KB checked in by pineray, 11 years ago (diff)

#2218 お届け先最大登録数の比較演算子を元に戻し、スクリプト側のカウント部分を変更

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