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

Revision 21008, 12.5 KB checked in by Seasoft, 13 years ago (diff)

#1322 (単価の表示が永続化される変数と異なる)
#1328 (複数配送時に入力内容確認画面でお届け先別商品欄に単価が表示されない)
#1362 (お届け先の複数指定 数量0も保持される)
#1387 (お届け先の複数指定 数量空欄も許容したい)

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