| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 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 |
---|
| 25 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php'; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * お届け先の指定 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
| 32 | * @version $Id$ |
---|
| 33 | */ |
---|
| 34 | class LC_Page_Shopping_Deliv extends LC_Page_Ex { |
---|
| 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 47 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
| 48 | $this->tpl_title = t('LC_Page_Shopping_Deliv_001'); |
---|
| 49 | $this->httpCacheControl('nocache'); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Page のプロセス. |
---|
| 54 | * |
---|
| 55 | * @return void |
---|
| 56 | */ |
---|
| 57 | function process() { |
---|
| 58 | parent::process(); |
---|
| 59 | $this->action(); |
---|
| 60 | $this->sendResponse(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * Page のプロセス. |
---|
| 65 | * |
---|
| 66 | * @return void |
---|
| 67 | */ |
---|
| 68 | function action() { |
---|
| 69 | |
---|
| 70 | $objSiteSess = new SC_SiteSession_Ex(); |
---|
| 71 | $objCartSess = new SC_CartSession_Ex(); |
---|
| 72 | $objCustomer = new SC_Customer_Ex(); |
---|
| 73 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
| 74 | $objFormParam = new SC_FormParam_Ex(); |
---|
| 75 | $objAddress = new SC_Helper_Address_Ex(); |
---|
| 76 | |
---|
| 77 | $this->tpl_uniqid = $objSiteSess->getUniqId(); |
---|
| 78 | $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess); |
---|
| 79 | |
---|
| 80 | $this->cartKey = $objCartSess->getKey(); |
---|
| 81 | |
---|
| 82 | // ログインチェック |
---|
| 83 | if (!$objCustomer->isLoginSuccess(true)) { |
---|
| 84 | SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // ダウンロード商品の場合は、支払方法画面に転送 |
---|
| 88 | if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) { |
---|
| 89 | $objPurchase->copyFromCustomer($sqlval, $objCustomer, 'shipping'); |
---|
| 90 | $objPurchase->saveShippingTemp($sqlval); |
---|
| 91 | $objPurchase->saveOrderTemp($this->tpl_uniqid, $sqlval, $objCustomer); |
---|
| 92 | $objSiteSess->setRegistFlag(); |
---|
| 93 | |
---|
| 94 | SC_Response_Ex::sendRedirect('payment.php'); |
---|
| 95 | SC_Response_Ex::actionExit(); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | $this->lfInitParam($objFormParam); |
---|
| 99 | $objFormParam->setParam($_POST); |
---|
| 100 | $objFormParam->convParam(); |
---|
| 101 | $arrErr = $objFormParam->checkError(); |
---|
| 102 | if (!SC_Utils_Ex::isBlank($arrErr)) { |
---|
| 103 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
---|
| 104 | SC_Response_Ex::actionExit(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | $arrForm = $objFormParam->getHashArray(); |
---|
| 108 | |
---|
| 109 | switch ($this->getMode()) { |
---|
| 110 | // 削除 |
---|
| 111 | case 'delete': |
---|
| 112 | $objAddress->delete($arrForm['other_deliv_id']); |
---|
| 113 | break; |
---|
| 114 | |
---|
| 115 | // 会員登録住所に送る |
---|
| 116 | case 'customer_addr': |
---|
| 117 | $objPurchase->unsetShippingTemp(); |
---|
| 118 | |
---|
| 119 | $shipping_id = $arrForm['deliv_check'] == -1 ? 0 : $arrForm['deliv_check']; |
---|
| 120 | $success = $this->registerDeliv($shipping_id, $this->tpl_uniqid, $objPurchase, $objCustomer, $objAddress); |
---|
| 121 | if (!$success) { |
---|
| 122 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | $objPurchase->setShipmentItemTempForSole($objCartSess, $shipping_id); |
---|
| 126 | $objSiteSess->setRegistFlag(); |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URLPATH); |
---|
| 130 | SC_Response_Ex::actionExit(); |
---|
| 131 | break; |
---|
| 132 | |
---|
| 133 | // 前のページに戻る |
---|
| 134 | case 'return': |
---|
| 135 | |
---|
| 136 | // 確認ページへ移動 |
---|
| 137 | SC_Response_Ex::sendRedirect(CART_URLPATH); |
---|
| 138 | SC_Response_Ex::actionExit(); |
---|
| 139 | break; |
---|
| 140 | |
---|
| 141 | // お届け先複数指定 |
---|
| 142 | case 'multiple': |
---|
| 143 | // 複数配送先指定が無効な場合はエラー |
---|
| 144 | if (USE_MULTIPLE_SHIPPING === false) { |
---|
| 145 | SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true); |
---|
| 146 | SC_Response_Ex::actionExit(); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | SC_Response_Ex::sendRedirect('multiple.php'); |
---|
| 150 | SC_Response_Ex::actionExit(); |
---|
| 151 | break; |
---|
| 152 | |
---|
| 153 | default: |
---|
| 154 | // 配送IDの取得 |
---|
| 155 | $shippingData = $objPurchase->getShippingTemp(); |
---|
| 156 | $arrShippingId = array_keys($shippingData); |
---|
| 157 | if (isset($arrShippingId[0])) { |
---|
| 158 | $this->arrForm['deliv_check']['value'] = $arrShippingId[0] == 0 ? -1 : $arrShippingId[0]; |
---|
| 159 | } |
---|
| 160 | break; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // 登録済み住所を取得 |
---|
| 164 | $addr = array( |
---|
| 165 | array( |
---|
| 166 | 'other_deliv_id' => NULL, |
---|
| 167 | 'customer_id' => $objCustomer->getValue('customer_id'), |
---|
| 168 | 'name01' => $objCustomer->getValue('name01'), |
---|
| 169 | 'name02' => $objCustomer->getValue('name02'), |
---|
| 170 | 'kana01' => $objCustomer->getValue('kana01'), |
---|
| 171 | 'kana02' => $objCustomer->getValue('kana02'), |
---|
| 172 | // 'zip01' => $objCustomer->getValue('zip01'), |
---|
| 173 | // 'zip02' => $objCustomer->getValue('zip02'), |
---|
| 174 | 'zipcode' => $objCustomer->getValue('zipcode'), |
---|
| 175 | 'pref' => $objCustomer->getValue('pref'), |
---|
| 176 | 'addr01' => $objCustomer->getValue('addr01'), |
---|
| 177 | 'addr02' => $objCustomer->getValue('addr02'), |
---|
| 178 | 'tel01' => $objCustomer->getValue('tel01'), |
---|
| 179 | 'tel02' => $objCustomer->getValue('tel02'), |
---|
| 180 | 'tel03' => $objCustomer->getValue('tel03'), |
---|
| 181 | ) |
---|
| 182 | ); |
---|
| 183 | $this->arrAddr = array_merge($addr, $objAddress->getList($objCustomer->getValue('customer_id'))); |
---|
| 184 | $this->tpl_addrmax = count($this->arrAddr); |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | * デストラクタ. |
---|
| 191 | * |
---|
| 192 | * @return void |
---|
| 193 | */ |
---|
| 194 | function destroy() { |
---|
| 195 | parent::destroy(); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
| 199 | * パラメーター情報の初期化を行う. |
---|
| 200 | * |
---|
| 201 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 202 | * @return void |
---|
| 203 | */ |
---|
| 204 | function lfInitParam(&$objFormParam) { |
---|
| 205 | $objFormParam->addParam(t('PARAM_LABEL_OTHER_DELIV_ID'), 'other_deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 206 | $objFormParam->addParam(t('PARAM_LABEL_CUSTOMER_DELIV_CHECK'), 'deliv_check', INT_LEN, 'n', array('MAX_LENGTH_CHECK')); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | /** |
---|
| 210 | * お届け先チェックの値に応じて, お届け先情報を保存する. |
---|
| 211 | * |
---|
| 212 | * 会員住所がチェックされている場合は, 会員情報からお届け先を取得する. |
---|
| 213 | * その他のお届け先がチェックされている場合は, その他のお届け先からお届け先を取得する. |
---|
| 214 | * お届け先チェックの値が不正な場合は false を返す. |
---|
| 215 | * |
---|
| 216 | * @param integer $other_deliv_id |
---|
| 217 | * @param string $uniqid 受注一時テーブルのユニークID |
---|
| 218 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
| 219 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
| 220 | * @return boolean お届け先チェックの値が妥当な場合 true |
---|
| 221 | */ |
---|
| 222 | function registerDeliv($other_deliv_id, $uniqid, &$objPurchase, &$objCustomer, $objAddress) { |
---|
| 223 | GC_Utils_Ex::gfDebugLog('register deliv. deliv_check=' . $deliv_check); |
---|
| 224 | $arrValues = array(); |
---|
| 225 | // 会員登録住所がチェックされている場合 |
---|
| 226 | if ($other_deliv_id == 0) { |
---|
| 227 | $objPurchase->copyFromCustomer($arrValues, $objCustomer, 'shipping'); |
---|
| 228 | } |
---|
| 229 | // 別のお届け先がチェックされている場合 |
---|
| 230 | else { |
---|
| 231 | $arrOtherDeliv = $objAddress->get($other_deliv_id); |
---|
| 232 | if (!$arrOtherDeliv) { |
---|
| 233 | return false; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | $objPurchase->copyFromOrder($arrValues, $arrOtherDeliv, 'shipping', ''); |
---|
| 237 | } |
---|
| 238 | $objPurchase->saveShippingTemp($arrValues, $other_deliv_id); |
---|
| 239 | $objPurchase->saveOrderTemp($uniqid, $arrValues, $objCustomer); |
---|
| 240 | return true; |
---|
| 241 | } |
---|
| 242 | } |
---|