[19860] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 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 | |
---|
[20534] | 24 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php'; |
---|
[19860] | 25 | |
---|
| 26 | /** |
---|
| 27 | * お届け先の複数指定 のページクラス. |
---|
| 28 | * |
---|
| 29 | * @package Page |
---|
| 30 | * @author LOCKON CO.,LTD. |
---|
[20116] | 31 | * @version $Id$ |
---|
[19860] | 32 | */ |
---|
[22856] | 33 | class LC_Page_Shopping_Multiple extends LC_Page_Ex |
---|
[22567] | 34 | { |
---|
[19860] | 35 | /** |
---|
| 36 | * Page を初期化する. |
---|
| 37 | * |
---|
| 38 | * @return void |
---|
| 39 | */ |
---|
[23124] | 40 | public function init() |
---|
[22567] | 41 | { |
---|
[19860] | 42 | parent::init(); |
---|
[21514] | 43 | $this->tpl_title = 'お届け先の複数指定'; |
---|
[19860] | 44 | $this->httpCacheControl('nocache'); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Page のプロセス. |
---|
| 49 | * |
---|
| 50 | * @return void |
---|
| 51 | */ |
---|
[23124] | 52 | public function process() |
---|
[22567] | 53 | { |
---|
[21314] | 54 | parent::process(); |
---|
[19860] | 55 | $this->action(); |
---|
| 56 | $this->sendResponse(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Page のプロセス. |
---|
| 61 | * |
---|
| 62 | * @return void |
---|
| 63 | */ |
---|
[23124] | 64 | public function action() |
---|
[22567] | 65 | { |
---|
[23055] | 66 | //決済処理中ステータスのロールバック |
---|
| 67 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
[23230] | 68 | $objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG); |
---|
[23124] | 69 | |
---|
[20448] | 70 | $objSiteSess = new SC_SiteSession_Ex(); |
---|
[20444] | 71 | $objCartSess = new SC_CartSession_Ex(); |
---|
[20490] | 72 | $objCustomer = new SC_Customer_Ex(); |
---|
[20501] | 73 | $objFormParam = new SC_FormParam_Ex(); |
---|
[22065] | 74 | $objAddress = new SC_Helper_Address_Ex(); |
---|
[19860] | 75 | |
---|
[21437] | 76 | // 複数配送先指定が無効な場合はエラー |
---|
| 77 | if (USE_MULTIPLE_SHIPPING === false) { |
---|
| 78 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
---|
[21743] | 79 | SC_Response_Ex::actionExit(); |
---|
[21437] | 80 | } |
---|
| 81 | |
---|
[20072] | 82 | $this->tpl_uniqid = $objSiteSess->getUniqId(); |
---|
[19872] | 83 | |
---|
[22941] | 84 | $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase, $objAddress); |
---|
[22782] | 85 | $this->tpl_addrmax = count($this->addrs) - 2; // 「選択してください」と会員の住所をカウントしない |
---|
[20670] | 86 | $this->lfInitParam($objFormParam); |
---|
[19862] | 87 | |
---|
[20072] | 88 | $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess); |
---|
[19862] | 89 | |
---|
[20041] | 90 | switch ($this->getMode()) { |
---|
[19862] | 91 | case 'confirm': |
---|
[20670] | 92 | $objFormParam->setParam($_POST); |
---|
[20072] | 93 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
[19862] | 94 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
[20670] | 95 | // フォームの情報を一時保存しておく |
---|
| 96 | $_SESSION['multiple_temp'] = $objFormParam->getHashArray(); |
---|
[20072] | 97 | $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam, |
---|
| 98 | $objCustomer, $objPurchase, |
---|
[22941] | 99 | $objAddress); |
---|
[19862] | 100 | $objSiteSess->setRegistFlag(); |
---|
[21596] | 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(); |
---|
[19860] | 116 | } |
---|
| 117 | |
---|
| 118 | /** |
---|
[19862] | 119 | * フォームを初期化する. |
---|
[20072] | 120 | * |
---|
[23124] | 121 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
[20072] | 122 | * @return void |
---|
[19862] | 123 | */ |
---|
[23124] | 124 | public function lfInitParam(&$objFormParam) |
---|
[22567] | 125 | { |
---|
[21514] | 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'); |
---|
[22494] | 134 | $objFormParam->addParam(SALE_PRICE_TITLE, 'price'); |
---|
[23230] | 135 | $objFormParam->addParam(SALE_PRICE_TITLE . '(税込)', 'price_inctax'); |
---|
[21514] | 136 | $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
[21549] | 137 | $objFormParam->addParam('お届け先', 'shipping', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[21514] | 138 | $objFormParam->addParam('カート番号', 'cart_no', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 139 | $objFormParam->addParam('行数', 'line_of_num', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[19862] | 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
[20670] | 143 | * カートの商品を数量ごとに分割し, フォームに設定する. |
---|
[20072] | 144 | * |
---|
[23124] | 145 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 146 | * @param SC_CartSession $objCartSess SC_CartSession インスタンス |
---|
[20670] | 147 | * @return void |
---|
[19862] | 148 | */ |
---|
[23124] | 149 | public function setParamToSplitItems(&$objFormParam, &$objCartSess) |
---|
[22567] | 150 | { |
---|
[19862] | 151 | $cartLists =& $objCartSess->getCartList($objCartSess->getKey()); |
---|
[20670] | 152 | $arrItems = array(); |
---|
| 153 | $index = 0; |
---|
[22941] | 154 | foreach (array_keys($cartLists) as $key) { |
---|
[20670] | 155 | $arrProductsClass = $cartLists[$key]['productsClass']; |
---|
| 156 | $quantity = (int) $cartLists[$key]['quantity']; |
---|
| 157 | for ($i = 0; $i < $quantity; $i++) { |
---|
[20975] | 158 | foreach ($arrProductsClass as $key2 => $val) { |
---|
| 159 | $arrItems[$key2][$index] = $val; |
---|
[20670] | 160 | } |
---|
| 161 | $arrItems['quantity'][$index] = 1; |
---|
[20975] | 162 | $arrItems['price'][$index] = $cartLists[$key]['price']; |
---|
[23230] | 163 | $arrItems['price_inctax'][$index] = $cartLists[$key]['price_inctax']; |
---|
[20670] | 164 | $index++; |
---|
[19862] | 165 | } |
---|
| 166 | } |
---|
[20670] | 167 | $objFormParam->setParam($arrItems); |
---|
| 168 | $objFormParam->setValue('line_of_num', $index); |
---|
[19862] | 169 | } |
---|
| 170 | |
---|
| 171 | /** |
---|
[19860] | 172 | * 配送住所のプルダウン用連想配列を取得する. |
---|
| 173 | * |
---|
| 174 | * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する. |
---|
| 175 | * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する. |
---|
[20072] | 176 | * |
---|
[23124] | 177 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
| 178 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
| 179 | * @return array 配送住所のプルダウン用連想配列 |
---|
[19860] | 180 | */ |
---|
[23124] | 181 | public function getDelivAddrs(&$objCustomer, &$objPurchase, &$objAddress) |
---|
[22567] | 182 | { |
---|
[21951] | 183 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[20072] | 184 | $arrPref = $masterData->getMasterData('mtb_pref'); |
---|
| 185 | |
---|
[21109] | 186 | $arrResults = array('' => '選択してください'); |
---|
[20072] | 187 | // 会員ログイン時 |
---|
[19991] | 188 | if ($objCustomer->isLoginSuccess(true)) { |
---|
[22065] | 189 | $addr = array( |
---|
| 190 | array( |
---|
| 191 | 'other_deliv_id' => NULL, |
---|
| 192 | 'customer_id' => $objCustomer->getValue('customer_id'), |
---|
| 193 | 'name01' => $objCustomer->getValue('name01'), |
---|
| 194 | 'name02' => $objCustomer->getValue('name02'), |
---|
| 195 | 'kana01' => $objCustomer->getValue('kana01'), |
---|
| 196 | 'kana02' => $objCustomer->getValue('kana02'), |
---|
| 197 | 'zip01' => $objCustomer->getValue('zip01'), |
---|
| 198 | 'zip02' => $objCustomer->getValue('zip02'), |
---|
| 199 | 'pref' => $objCustomer->getValue('pref'), |
---|
| 200 | 'addr01' => $objCustomer->getValue('addr01'), |
---|
| 201 | 'addr02' => $objCustomer->getValue('addr02'), |
---|
| 202 | 'tel01' => $objCustomer->getValue('tel01'), |
---|
| 203 | 'tel02' => $objCustomer->getValue('tel02'), |
---|
| 204 | 'tel03' => $objCustomer->getValue('tel03'), |
---|
| 205 | ) |
---|
| 206 | ); |
---|
| 207 | $arrAddrs = array_merge($addr, $objAddress->getList($objCustomer->getValue('customer_id'))); |
---|
[20072] | 208 | foreach ($arrAddrs as $val) { |
---|
[19872] | 209 | $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id']; |
---|
[20072] | 210 | $arrResults[$other_deliv_id] = $val['name01'] . $val['name02'] |
---|
[21514] | 211 | . ' ' . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02']; |
---|
[19872] | 212 | } |
---|
[20072] | 213 | } |
---|
| 214 | // 非会員 |
---|
| 215 | else { |
---|
| 216 | $arrShippings = $objPurchase->getShippingTemp(); |
---|
| 217 | foreach ($arrShippings as $shipping_id => $val) { |
---|
| 218 | $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02'] |
---|
[21514] | 219 | . ' ' . $arrPref[$val['shipping_pref']] |
---|
[19872] | 220 | . $val['shipping_addr01'] . $val['shipping_addr02']; |
---|
| 221 | } |
---|
[19860] | 222 | } |
---|
[22494] | 223 | |
---|
[20072] | 224 | return $arrResults; |
---|
[19860] | 225 | } |
---|
[19862] | 226 | |
---|
[20072] | 227 | /** |
---|
| 228 | * 入力チェックを行う. |
---|
| 229 | * |
---|
[23124] | 230 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 231 | * @return array エラー情報の配列 |
---|
[20072] | 232 | */ |
---|
[23124] | 233 | public function lfCheckError(&$objFormParam) |
---|
[22567] | 234 | { |
---|
[20984] | 235 | $objCartSess = new SC_CartSession_Ex(); |
---|
| 236 | |
---|
[19862] | 237 | $objFormParam->convParam(); |
---|
[21100] | 238 | // 数量未入力は0に置換 |
---|
| 239 | $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0)); |
---|
| 240 | |
---|
[20984] | 241 | $arrErr = $objFormParam->checkError(); |
---|
[21008] | 242 | |
---|
| 243 | $arrParams = $objFormParam->getSwapArray(); |
---|
| 244 | |
---|
[21100] | 245 | if (empty($arrErr)) { |
---|
| 246 | foreach ($arrParams as $index => $arrParam) { |
---|
| 247 | // 数量0で、お届け先を選択している場合 |
---|
| 248 | if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) { |
---|
| 249 | $arrErr['shipping'][$index] = '※ 数量が0の場合、お届け先を入力できません。<br />';; |
---|
| 250 | } |
---|
| 251 | // 数量の入力があり、お届け先を選択していない場合 |
---|
| 252 | if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) { |
---|
| 253 | $arrErr['shipping'][$index] = '※ お届け先が入力されていません。<br />'; |
---|
| 254 | } |
---|
[21008] | 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
[20984] | 258 | // 入力エラーが無い場合、カゴの中身との数量の整合を確認 |
---|
| 259 | if (empty($arrErr)) { |
---|
| 260 | $arrQuantity = array(); |
---|
| 261 | // 入力内容を集計 |
---|
| 262 | foreach ($arrParams as $arrParam) { |
---|
| 263 | $product_class_id = $arrParam['product_class_id']; |
---|
| 264 | $arrQuantity[$product_class_id] += $arrParam['quantity']; |
---|
| 265 | } |
---|
| 266 | // カゴの中身と突き合わせ |
---|
| 267 | $cartLists =& $objCartSess->getCartList($objCartSess->getKey()); |
---|
| 268 | foreach ($cartLists as $arrCartRow) { |
---|
| 269 | $product_class_id = $arrCartRow['id']; |
---|
| 270 | // 差異がある場合、エラーを記録 |
---|
| 271 | if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) { |
---|
[21008] | 272 | foreach ($arrParams as $index => $arrParam) { |
---|
[20984] | 273 | if ($arrParam['product_class_id'] == $product_class_id) { |
---|
[21140] | 274 | $arrErr['quantity'][$index] = '※ 数量合計を「' . $arrCartRow['quantity'] .'」にしてください。<br />'; |
---|
[20984] | 275 | } |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | } |
---|
[22494] | 280 | |
---|
[20984] | 281 | return $arrErr; |
---|
[19862] | 282 | } |
---|
[20072] | 283 | |
---|
| 284 | /** |
---|
| 285 | * 複数配送情報を一時保存する. |
---|
| 286 | * |
---|
| 287 | * 会員ログインしている場合は, その他のお届け先から住所情報を取得する. |
---|
| 288 | * |
---|
[23124] | 289 | * @param integer $uniqid 一時受注テーブルのユニークID |
---|
| 290 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 291 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
| 292 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
[20072] | 293 | * @return void |
---|
| 294 | */ |
---|
[23124] | 295 | public function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer, &$objPurchase, &$objAddress) |
---|
[22567] | 296 | { |
---|
[21008] | 297 | $arrParams = $objFormParam->getSwapArray(); |
---|
[20072] | 298 | |
---|
[21008] | 299 | foreach ($arrParams as $arrParam) { |
---|
| 300 | $other_deliv_id = $arrParam['shipping']; |
---|
[20670] | 301 | |
---|
[20072] | 302 | if ($objCustomer->isLoginSuccess(true)) { |
---|
| 303 | if ($other_deliv_id != 0) { |
---|
[22546] | 304 | $otherDeliv = $objAddress->getAddress($other_deliv_id); |
---|
[22065] | 305 | foreach ($otherDeliv as $key => $val) { |
---|
[20072] | 306 | $arrValues[$other_deliv_id]['shipping_' . $key] = $val; |
---|
| 307 | } |
---|
| 308 | } else { |
---|
| 309 | $objPurchase->copyFromCustomer($arrValues[0], $objCustomer, |
---|
[20538] | 310 | 'shipping'); |
---|
[20072] | 311 | } |
---|
[20765] | 312 | } else { |
---|
| 313 | $arrValues = $objPurchase->getShippingTemp(); |
---|
[20072] | 314 | } |
---|
[21008] | 315 | $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity']; |
---|
[20670] | 316 | } |
---|
[20072] | 317 | |
---|
[20963] | 318 | $objPurchase->clearShipmentItemTemp(); |
---|
| 319 | |
---|
[21006] | 320 | foreach ($arrValues as $shipping_id => $arrVal) { |
---|
| 321 | $objPurchase->saveShippingTemp($arrVal, $shipping_id); |
---|
| 322 | } |
---|
| 323 | |
---|
[20670] | 324 | foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) { |
---|
| 325 | foreach ($arrProductClassIds as $product_class_id => $quantity) { |
---|
[21008] | 326 | if ($quantity == 0) continue; |
---|
[20670] | 327 | $objPurchase->setShipmentItemTemp($other_deliv_id, |
---|
| 328 | $product_class_id, |
---|
| 329 | $quantity); |
---|
| 330 | } |
---|
[20072] | 331 | } |
---|
| 332 | |
---|
[22086] | 333 | //不必要な配送先を削除 |
---|
| 334 | foreach ($_SESSION['shipping'] as $id=>$arrShipping) { |
---|
[23124] | 335 | if (!isset($arrShipping['shipment_item'])) { |
---|
[22086] | 336 | $objPurchase->unsetOneShippingTemp($id); |
---|
| 337 | } |
---|
| 338 | } |
---|
| 339 | |
---|
[20072] | 340 | // $arrValues[0] には, 購入者の情報が格納されている |
---|
| 341 | $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer); |
---|
| 342 | } |
---|
[19860] | 343 | } |
---|