[19860] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[21867] | 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] | 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(); |
---|
[22100] | 46 | $this->tpl_title = t('LC_Page_Shopping_Multiple_001'); |
---|
[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(); |
---|
[22081] | 73 | $objAddress = new SC_Helper_Address_Ex(); |
---|
[19860] | 74 | |
---|
[21437] | 75 | // 複数配送先指定が無効な場合はエラー |
---|
| 76 | if (USE_MULTIPLE_SHIPPING === false) { |
---|
| 77 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
---|
[21743] | 78 | SC_Response_Ex::actionExit(); |
---|
[21437] | 79 | } |
---|
| 80 | |
---|
[20072] | 81 | $this->tpl_uniqid = $objSiteSess->getUniqId(); |
---|
[19872] | 82 | |
---|
[20072] | 83 | $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase, |
---|
[22081] | 84 | $objAddress, $this->tpl_uniqid); |
---|
[20706] | 85 | $this->tpl_addrmax = count($this->addrs); |
---|
[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, |
---|
[22081] | 99 | $objCartSess, $objAddress); |
---|
[19862] | 100 | $objSiteSess->setRegistFlag(); |
---|
[21596] | 101 | |
---|
| 102 | |
---|
[21514] | 103 | SC_Response_Ex::sendRedirect('payment.php'); |
---|
[21743] | 104 | SC_Response_Ex::actionExit(); |
---|
[19862] | 105 | } |
---|
| 106 | break; |
---|
| 107 | |
---|
[21100] | 108 | default: |
---|
| 109 | $this->setParamToSplitItems($objFormParam, $objCartSess); |
---|
[19862] | 110 | } |
---|
| 111 | |
---|
[20670] | 112 | // 前のページから戻ってきた場合 |
---|
| 113 | if ($_GET['from'] == 'multiple') { |
---|
| 114 | $objFormParam->setParam($_SESSION['multiple_temp']); |
---|
| 115 | } |
---|
[20072] | 116 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
[21596] | 117 | |
---|
[21743] | 118 | |
---|
[19860] | 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * デストラクタ. |
---|
| 123 | * |
---|
| 124 | * @return void |
---|
| 125 | */ |
---|
| 126 | function destroy() { |
---|
| 127 | parent::destroy(); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
[19862] | 131 | * フォームを初期化する. |
---|
[20072] | 132 | * |
---|
| 133 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 134 | * @return void |
---|
[19862] | 135 | */ |
---|
[20670] | 136 | function lfInitParam(&$objFormParam) { |
---|
[22100] | 137 | $objFormParam->addParam(t('PARAM_LABEL_PRODUCT_CLASS_ID'), 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 138 | $objFormParam->addParam(t('PARAM_LABEL_PRODUCT_NAME'), 'name'); |
---|
| 139 | $objFormParam->addParam(t('PARAM_LABEL_CLASS1'), 'class_name1'); |
---|
| 140 | $objFormParam->addParam(t('PARAM_LABEL_CLASS2'), 'class_name2'); |
---|
| 141 | $objFormParam->addParam(t('PARAM_LABEL_CLASSCATEGORY1'), 'classcategory_name1'); |
---|
| 142 | $objFormParam->addParam(t('PARAM_LABEL_CLASSCATEGORY2'), 'classcategory_name2'); |
---|
| 143 | $objFormParam->addParam(t('PARAM_LABEL_MAIN_IMAGE'), 'main_image'); |
---|
| 144 | $objFormParam->addParam(t('PARAM_LABEL_MAIN_LIST_IMAGE'), 'main_list_image'); |
---|
| 145 | $objFormParam->addParam(t('PARAM_LABEL_SELLPRICE'), 'price'); |
---|
| 146 | $objFormParam->addParam(t('PARAM_LABEL_QUANTITY'), 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 147 | $objFormParam->addParam(t('PARAM_LABEL_CUSTOMER_DELIV_ADDRESSEE'), 'shipping', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 148 | $objFormParam->addParam(t('PARAM_LABEL_CART_NO'), 'cart_no', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 149 | $objFormParam->addParam(t('PARAM_LABEL_LINE_NUM'), 'line_of_num', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[19862] | 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
[20670] | 153 | * カートの商品を数量ごとに分割し, フォームに設定する. |
---|
[20072] | 154 | * |
---|
[20670] | 155 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
[20072] | 156 | * @param SC_CartSession $objCartSess SC_CartSession インスタンス |
---|
[20670] | 157 | * @return void |
---|
[19862] | 158 | */ |
---|
[20670] | 159 | function setParamToSplitItems(&$objFormParam, &$objCartSess) { |
---|
[19862] | 160 | $cartLists =& $objCartSess->getCartList($objCartSess->getKey()); |
---|
[20670] | 161 | $arrItems = array(); |
---|
| 162 | $index = 0; |
---|
[21935] | 163 | foreach ($cartLists as $key => $value) { |
---|
[20670] | 164 | $arrProductsClass = $cartLists[$key]['productsClass']; |
---|
| 165 | $quantity = (int) $cartLists[$key]['quantity']; |
---|
| 166 | for ($i = 0; $i < $quantity; $i++) { |
---|
[20975] | 167 | foreach ($arrProductsClass as $key2 => $val) { |
---|
| 168 | $arrItems[$key2][$index] = $val; |
---|
[20670] | 169 | } |
---|
| 170 | $arrItems['quantity'][$index] = 1; |
---|
[20975] | 171 | $arrItems['price'][$index] = $cartLists[$key]['price']; |
---|
[20670] | 172 | $index++; |
---|
[19862] | 173 | } |
---|
| 174 | } |
---|
[20670] | 175 | $objFormParam->setParam($arrItems); |
---|
| 176 | $objFormParam->setValue('line_of_num', $index); |
---|
[19862] | 177 | } |
---|
| 178 | |
---|
| 179 | /** |
---|
[19860] | 180 | * 配送住所のプルダウン用連想配列を取得する. |
---|
| 181 | * |
---|
| 182 | * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する. |
---|
| 183 | * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する. |
---|
[20072] | 184 | * |
---|
| 185 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
| 186 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
| 187 | * @param integer $uniqid 受注一時テーブルのユニークID |
---|
| 188 | * @return array 配送住所のプルダウン用連想配列 |
---|
[19860] | 189 | */ |
---|
[22081] | 190 | function getDelivAddrs(&$objCustomer, &$objPurchase, &$objAddress, $uniqid) { |
---|
[21951] | 191 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[20072] | 192 | $arrPref = $masterData->getMasterData('mtb_pref'); |
---|
| 193 | |
---|
[22100] | 194 | $arrResults = array('' => t('LC_Page_Shopping_Multiple_002')); |
---|
[20072] | 195 | // 会員ログイン時 |
---|
[19991] | 196 | if ($objCustomer->isLoginSuccess(true)) { |
---|
[22081] | 197 | $addr = array( |
---|
| 198 | array( |
---|
| 199 | 'other_deliv_id' => NULL, |
---|
| 200 | 'customer_id' => $objCustomer->getValue('customer_id'), |
---|
| 201 | 'name01' => $objCustomer->getValue('name01'), |
---|
| 202 | 'name02' => $objCustomer->getValue('name02'), |
---|
| 203 | 'kana01' => $objCustomer->getValue('kana01'), |
---|
| 204 | 'kana02' => $objCustomer->getValue('kana02'), |
---|
[22205] | 205 | // 'zip01' => $objCustomer->getValue('zip01'), |
---|
| 206 | // 'zip02' => $objCustomer->getValue('zip02'), |
---|
| 207 | 'zipcode' => $objCustomer->getValue('zipcode'), |
---|
[22081] | 208 | 'pref' => $objCustomer->getValue('pref'), |
---|
| 209 | 'addr01' => $objCustomer->getValue('addr01'), |
---|
| 210 | 'addr02' => $objCustomer->getValue('addr02'), |
---|
| 211 | 'tel01' => $objCustomer->getValue('tel01'), |
---|
| 212 | 'tel02' => $objCustomer->getValue('tel02'), |
---|
| 213 | 'tel03' => $objCustomer->getValue('tel03'), |
---|
| 214 | ) |
---|
| 215 | ); |
---|
| 216 | $arrAddrs = array_merge($addr, $objAddress->getList($objCustomer->getValue('customer_id'))); |
---|
[20072] | 217 | foreach ($arrAddrs as $val) { |
---|
[19872] | 218 | $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id']; |
---|
[20072] | 219 | $arrResults[$other_deliv_id] = $val['name01'] . $val['name02'] |
---|
[21514] | 220 | . ' ' . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02']; |
---|
[19872] | 221 | } |
---|
[20072] | 222 | } |
---|
| 223 | // 非会員 |
---|
| 224 | else { |
---|
| 225 | $arrShippings = $objPurchase->getShippingTemp(); |
---|
| 226 | foreach ($arrShippings as $shipping_id => $val) { |
---|
| 227 | $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02'] |
---|
[21514] | 228 | . ' ' . $arrPref[$val['shipping_pref']] |
---|
[19872] | 229 | . $val['shipping_addr01'] . $val['shipping_addr02']; |
---|
| 230 | } |
---|
[19860] | 231 | } |
---|
[20072] | 232 | return $arrResults; |
---|
[19860] | 233 | } |
---|
[19862] | 234 | |
---|
[20072] | 235 | /** |
---|
| 236 | * 入力チェックを行う. |
---|
| 237 | * |
---|
| 238 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 239 | * @return array エラー情報の配列 |
---|
| 240 | */ |
---|
[19862] | 241 | function lfCheckError(&$objFormParam) { |
---|
[20984] | 242 | $objCartSess = new SC_CartSession_Ex(); |
---|
| 243 | |
---|
[19862] | 244 | $objFormParam->convParam(); |
---|
[21100] | 245 | // 数量未入力は0に置換 |
---|
| 246 | $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0)); |
---|
| 247 | |
---|
[20984] | 248 | $arrErr = $objFormParam->checkError(); |
---|
[21008] | 249 | |
---|
| 250 | $arrParams = $objFormParam->getSwapArray(); |
---|
| 251 | |
---|
[21100] | 252 | if (empty($arrErr)) { |
---|
| 253 | foreach ($arrParams as $index => $arrParam) { |
---|
| 254 | // 数量0で、お届け先を選択している場合 |
---|
| 255 | if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) { |
---|
[22100] | 256 | $arrErr['shipping'][$index] = t('LC_Page_Shopping_Multiple_003'); |
---|
[21100] | 257 | } |
---|
| 258 | // 数量の入力があり、お届け先を選択していない場合 |
---|
| 259 | if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) { |
---|
[22100] | 260 | $arrErr['shipping'][$index] = t('LC_Page_Shopping_Multiple_004'); |
---|
[21100] | 261 | } |
---|
[21008] | 262 | } |
---|
| 263 | } |
---|
| 264 | |
---|
[20984] | 265 | // 入力エラーが無い場合、カゴの中身との数量の整合を確認 |
---|
| 266 | if (empty($arrErr)) { |
---|
| 267 | $arrQuantity = array(); |
---|
| 268 | // 入力内容を集計 |
---|
| 269 | foreach ($arrParams as $arrParam) { |
---|
| 270 | $product_class_id = $arrParam['product_class_id']; |
---|
| 271 | $arrQuantity[$product_class_id] += $arrParam['quantity']; |
---|
| 272 | } |
---|
| 273 | // カゴの中身と突き合わせ |
---|
| 274 | $cartLists =& $objCartSess->getCartList($objCartSess->getKey()); |
---|
| 275 | foreach ($cartLists as $arrCartRow) { |
---|
| 276 | $product_class_id = $arrCartRow['id']; |
---|
| 277 | // 差異がある場合、エラーを記録 |
---|
| 278 | if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) { |
---|
[21008] | 279 | foreach ($arrParams as $index => $arrParam) { |
---|
[20984] | 280 | if ($arrParam['product_class_id'] == $product_class_id) { |
---|
[22100] | 281 | $arrErr['quantity'][$index] = t('LC_Page_Shopping_Multiple_005', array('T_FIELD' => $arrCartRow['quantity'])); |
---|
[22066] | 282 | |
---|
[20984] | 283 | } |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | return $arrErr; |
---|
[19862] | 289 | } |
---|
[20072] | 290 | |
---|
| 291 | /** |
---|
| 292 | * 複数配送情報を一時保存する. |
---|
| 293 | * |
---|
| 294 | * 会員ログインしている場合は, その他のお届け先から住所情報を取得する. |
---|
| 295 | * |
---|
| 296 | * @param integer $uniqid 一時受注テーブルのユニークID |
---|
| 297 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 298 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
| 299 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
| 300 | * @param SC_CartSession $objCartSess SC_CartSession インスタンス |
---|
| 301 | * @return void |
---|
| 302 | */ |
---|
[22081] | 303 | function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer, &$objPurchase, &$objCartSess, &$objAddress) { |
---|
[21008] | 304 | $arrParams = $objFormParam->getSwapArray(); |
---|
[20072] | 305 | |
---|
[21008] | 306 | foreach ($arrParams as $arrParam) { |
---|
| 307 | $other_deliv_id = $arrParam['shipping']; |
---|
[20670] | 308 | |
---|
[20072] | 309 | if ($objCustomer->isLoginSuccess(true)) { |
---|
| 310 | if ($other_deliv_id != 0) { |
---|
[22081] | 311 | $otherDeliv = $objAddress->get($other_deliv_id); |
---|
| 312 | foreach ($otherDeliv as $key => $val) { |
---|
[20072] | 313 | $arrValues[$other_deliv_id]['shipping_' . $key] = $val; |
---|
| 314 | } |
---|
| 315 | } else { |
---|
| 316 | $objPurchase->copyFromCustomer($arrValues[0], $objCustomer, |
---|
[20538] | 317 | 'shipping'); |
---|
[20072] | 318 | } |
---|
[20765] | 319 | } else { |
---|
| 320 | $arrValues = $objPurchase->getShippingTemp(); |
---|
[20072] | 321 | } |
---|
[21008] | 322 | $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity']; |
---|
[20670] | 323 | } |
---|
[20072] | 324 | |
---|
[20963] | 325 | $objPurchase->clearShipmentItemTemp(); |
---|
| 326 | |
---|
[21006] | 327 | foreach ($arrValues as $shipping_id => $arrVal) { |
---|
| 328 | $objPurchase->saveShippingTemp($arrVal, $shipping_id); |
---|
| 329 | } |
---|
| 330 | |
---|
[20670] | 331 | foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) { |
---|
| 332 | foreach ($arrProductClassIds as $product_class_id => $quantity) { |
---|
[21008] | 333 | if ($quantity == 0) continue; |
---|
[20670] | 334 | $objPurchase->setShipmentItemTemp($other_deliv_id, |
---|
| 335 | $product_class_id, |
---|
| 336 | $quantity); |
---|
| 337 | } |
---|
[20072] | 338 | } |
---|
| 339 | |
---|
[22087] | 340 | //不必要な配送先を削除 |
---|
| 341 | foreach ($_SESSION['shipping'] as $id=>$arrShipping) { |
---|
[22096] | 342 | if (!isset($arrShipping['shipment_item'])){ |
---|
[22087] | 343 | $objPurchase->unsetOneShippingTemp($id); |
---|
| 344 | } |
---|
| 345 | } |
---|
| 346 | |
---|
[20072] | 347 | // $arrValues[0] には, 購入者の情報が格納されている |
---|
| 348 | $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer); |
---|
| 349 | } |
---|
[19860] | 350 | } |
---|