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
RevLine 
[19860]1<?php
2/*
3 * This file is part of EC-CUBE
4 *
[21864]5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
[19860]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
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
[19860]26
27/**
28 * お届け先の複数指定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
[20116]32 * @version $Id$
[19860]33 */
[20344]34class LC_Page_Shopping_Multiple extends LC_Page_Ex {
[19860]35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
[21514]46        $this->tpl_title = 'お届け先の複数指定';
[19860]47        $this->httpCacheControl('nocache');
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process() {
[21314]56        parent::process();
[19860]57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のプロセス.
63     *
64     * @return void
65     */
66    function action() {
[21596]67
[20448]68        $objSiteSess = new SC_SiteSession_Ex();
[20444]69        $objCartSess = new SC_CartSession_Ex();
[19862]70        $objPurchase = new SC_Helper_Purchase_Ex();
[20490]71        $objCustomer = new SC_Customer_Ex();
[20501]72        $objFormParam = new SC_FormParam_Ex();
[19860]73
[21437]74        // 複数配送先指定が無効な場合はエラー
75        if (USE_MULTIPLE_SHIPPING === false) {
76            SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
[21743]77            SC_Response_Ex::actionExit();
[21437]78        }
79
[20072]80        $this->tpl_uniqid = $objSiteSess->getUniqId();
[19872]81
[20072]82        $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase,
83                                            $this->tpl_uniqid);
[20706]84        $this->tpl_addrmax = count($this->addrs);
[20670]85        $this->lfInitParam($objFormParam);
[19862]86
[20072]87        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
[19862]88
[20041]89        switch ($this->getMode()) {
[19862]90            case 'confirm':
[20670]91                $objFormParam->setParam($_POST);
[20072]92                $this->arrErr = $this->lfCheckError($objFormParam);
[19862]93                if (SC_Utils_Ex::isBlank($this->arrErr)) {
[20670]94                    // フォームの情報を一時保存しておく
95                    $_SESSION['multiple_temp'] = $objFormParam->getHashArray();
[20072]96                    $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
97                                                 $objCustomer, $objPurchase,
98                                                 $objCartSess);
[19862]99                    $objSiteSess->setRegistFlag();
[21596]100
101
[21514]102                    SC_Response_Ex::sendRedirect('payment.php');
[21743]103                    SC_Response_Ex::actionExit();
[19862]104                }
105                break;
106
[21100]107            default:
108                $this->setParamToSplitItems($objFormParam, $objCartSess);
[19862]109        }
110
[20670]111        // 前のページから戻ってきた場合
112        if ($_GET['from'] == 'multiple') {
113            $objFormParam->setParam($_SESSION['multiple_temp']);
114        }
[20072]115        $this->arrForm = $objFormParam->getFormParamList();
[21596]116
[21743]117
[19860]118    }
119
120    /**
121     * デストラクタ.
122     *
123     * @return void
124     */
125    function destroy() {
126        parent::destroy();
127    }
128
129    /**
[19862]130     * フォームを初期化する.
[20072]131     *
132     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
133     * @return void
[19862]134     */
[20670]135    function lfInitParam(&$objFormParam) {
[21514]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);
[21549]146        $objFormParam->addParam('お届け先', 'shipping', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
[21514]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'));
[19862]149    }
150
151    /**
[20670]152     * カートの商品を数量ごとに分割し, フォームに設定する.
[20072]153     *
[20670]154     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
[20072]155     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
[20670]156     * @return void
[19862]157     */
[20670]158    function setParamToSplitItems(&$objFormParam, &$objCartSess) {
[19862]159        $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
[20670]160        $arrItems = array();
161        $index = 0;
[19862]162        foreach (array_keys($cartLists) as $key) {
[20670]163            $arrProductsClass = $cartLists[$key]['productsClass'];
164            $quantity = (int) $cartLists[$key]['quantity'];
165            for ($i = 0; $i < $quantity; $i++) {
[20975]166                foreach ($arrProductsClass as $key2 => $val) {
167                    $arrItems[$key2][$index] = $val;
[20670]168                }
169                $arrItems['quantity'][$index] = 1;
[20975]170                $arrItems['price'][$index] = $cartLists[$key]['price'];
[20670]171                $index++;
[19862]172            }
173        }
[20670]174        $objFormParam->setParam($arrItems);
175        $objFormParam->setValue('line_of_num', $index);
[19862]176    }
177
178    /**
[19860]179     * 配送住所のプルダウン用連想配列を取得する.
180     *
181     * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
182     * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
[20072]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 配送住所のプルダウン用連想配列
[19860]188     */
[19872]189    function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
[20072]190        $masterData = new SC_DB_MasterData();
191        $arrPref = $masterData->getMasterData('mtb_pref');
192
[21109]193        $arrResults = array('' => '選択してください');
[20072]194        // 会員ログイン時
[19991]195        if ($objCustomer->isLoginSuccess(true)) {
[20072]196            $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
197            foreach ($arrAddrs as $val) {
[19872]198                $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
[20072]199                $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
[21514]200                    . ' ' . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
[19872]201            }
[20072]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']
[21514]208                    . ' ' . $arrPref[$val['shipping_pref']]
[19872]209                    . $val['shipping_addr01'] . $val['shipping_addr02'];
210            }
[19860]211        }
[20072]212        return $arrResults;
[19860]213    }
[19862]214
[20072]215    /**
216     * 入力チェックを行う.
217     *
218     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
219     * @return array エラー情報の配列
220     */
[19862]221    function lfCheckError(&$objFormParam) {
[20984]222        $objCartSess = new SC_CartSession_Ex();
223
[19862]224        $objFormParam->convParam();
[21100]225        // 数量未入力は0に置換
226        $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0));
227
[20984]228        $arrErr = $objFormParam->checkError();
[21008]229
230        $arrParams = $objFormParam->getSwapArray();
231
[21100]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                }
[21008]242            }
243        }
244
[20984]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]) {
[21008]259                    foreach ($arrParams as $index => $arrParam) {
[20984]260                        if ($arrParam['product_class_id'] == $product_class_id) {
[21140]261                            $arrErr['quantity'][$index] = '※ 数量合計を「' . $arrCartRow['quantity'] .'」にしてください。<br />';
[20984]262                        }
263                    }
264                }
265            }
266        }
267        return $arrErr;
[19862]268    }
[20072]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     */
[21527]282    function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer, &$objPurchase, &$objCartSess) {
[20507]283        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20072]284
[21008]285        $arrParams = $objFormParam->getSwapArray();
[20072]286
[21008]287        foreach ($arrParams as $arrParam) {
288            $other_deliv_id = $arrParam['shipping'];
[20670]289
[20072]290            if ($objCustomer->isLoginSuccess(true)) {
291                if ($other_deliv_id != 0) {
[21514]292                    $otherDeliv = $objQuery->select('*', 'dtb_other_deliv',
293                                                    'other_deliv_id = ?',
[20072]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,
[20538]300                                                   'shipping');
[20072]301                }
[20765]302            } else {
303                $arrValues = $objPurchase->getShippingTemp();
[20072]304            }
[21008]305            $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
[20670]306        }
[20072]307
[20963]308        $objPurchase->clearShipmentItemTemp();
309
[21006]310        foreach ($arrValues as $shipping_id => $arrVal) {
311            $objPurchase->saveShippingTemp($arrVal, $shipping_id);
312        }
313
[20670]314        foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
315            foreach ($arrProductClassIds as $product_class_id => $quantity) {
[21008]316                if ($quantity == 0) continue;
[20670]317                $objPurchase->setShipmentItemTemp($other_deliv_id,
318                                                  $product_class_id,
319                                                  $quantity);
320            }
[20072]321        }
322
323        // $arrValues[0] には, 購入者の情報が格納されている
324        $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
325    }
[19860]326}
Note: See TracBrowser for help on using the repository browser.