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