| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2010 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_PATH . "pages/LC_Page.php"); |
|---|
| 26 | if (file_exists(MODULE_PATH . "mdl_gmopg/inc/function.php")) { |
|---|
| 27 | require_once(MODULE_PATH . "mdl_gmopg/inc/function.php"); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * カート のページクラス. |
|---|
| 32 | * |
|---|
| 33 | * @package Page |
|---|
| 34 | * @author LOCKON CO.,LTD. |
|---|
| 35 | * @version $Id:LC_Page_Cart.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 36 | */ |
|---|
| 37 | class LC_Page_Cart extends LC_Page { |
|---|
| 38 | |
|---|
| 39 | // {{{ properties |
|---|
| 40 | |
|---|
| 41 | /** セッションの配列 */ |
|---|
| 42 | var $arrSession; |
|---|
| 43 | |
|---|
| 44 | /** カテゴリの配列 */ |
|---|
| 45 | var $arrProductsClass; |
|---|
| 46 | |
|---|
| 47 | /** 商品規格情報の配列 */ |
|---|
| 48 | var $arrData; |
|---|
| 49 | |
|---|
| 50 | // }}} |
|---|
| 51 | // {{{ functions |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Page を初期化する. |
|---|
| 55 | * |
|---|
| 56 | * @return void |
|---|
| 57 | */ |
|---|
| 58 | function init() { |
|---|
| 59 | parent::init(); |
|---|
| 60 | $this->tpl_mainpage = 'cart/index.tpl'; |
|---|
| 61 | $this->tpl_column_num = 1; |
|---|
| 62 | $this->tpl_title = "カゴの中を見る"; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /** |
|---|
| 66 | * Page のプロセス. |
|---|
| 67 | * |
|---|
| 68 | * @return void |
|---|
| 69 | */ |
|---|
| 70 | function process() { |
|---|
| 71 | global $objCampaignSess; |
|---|
| 72 | |
|---|
| 73 | $objView = new SC_SiteView(false); |
|---|
| 74 | $objCartSess = new SC_CartSession(); |
|---|
| 75 | $objSiteSess = new SC_SiteSession(); |
|---|
| 76 | $objCampaignSess = new SC_CampaignSession(); |
|---|
| 77 | $objSiteInfo = $objView->objSiteInfo; |
|---|
| 78 | $objCustomer = new SC_Customer(); |
|---|
| 79 | $db = new SC_Helper_DB_Ex(); |
|---|
| 80 | // 基本情報の取得 |
|---|
| 81 | $arrInfo = $objSiteInfo->data; |
|---|
| 82 | |
|---|
| 83 | // 商品購入中にカート内容が変更された。 |
|---|
| 84 | if($objCartSess->getCancelPurchase()) { |
|---|
| 85 | $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。"; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
|---|
| 89 | |
|---|
| 90 | /* |
|---|
| 91 | * FIXME reload() を使った方が良いが無限ループしてしまう... |
|---|
| 92 | */ |
|---|
| 93 | switch($_POST['mode']) { |
|---|
| 94 | case 'up': |
|---|
| 95 | $objCartSess->upQuantity($_POST['cart_no']); |
|---|
| 96 | SC_Utils_Ex::sfReload(); |
|---|
| 97 | break; |
|---|
| 98 | case 'down': |
|---|
| 99 | $objCartSess->downQuantity($_POST['cart_no']); |
|---|
| 100 | SC_Utils_Ex::sfReload(); |
|---|
| 101 | break; |
|---|
| 102 | case 'delete': |
|---|
| 103 | $objCartSess->delProduct($_POST['cart_no']); |
|---|
| 104 | SC_Utils_Ex::sfReload(); |
|---|
| 105 | break; |
|---|
| 106 | case 'confirm': |
|---|
| 107 | // カート内情報の取得 |
|---|
| 108 | $arrRet = $objCartSess->getCartList(); |
|---|
| 109 | $max = count($arrRet); |
|---|
| 110 | $cnt = 0; |
|---|
| 111 | for ($i = 0; $i < $max; $i++) { |
|---|
| 112 | // 商品規格情報の取得 |
|---|
| 113 | $this->arrData = $db->sfGetProductsClass($arrRet[$i]['id']); |
|---|
| 114 | // DBに存在する商品 |
|---|
| 115 | if($this->arrData != "") { |
|---|
| 116 | $cnt++; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | // カート商品が1件以上存在する場合 |
|---|
| 120 | if($cnt > 0) { |
|---|
| 121 | // 正常に登録されたことを記録しておく |
|---|
| 122 | $objSiteSess->setRegistFlag(); |
|---|
| 123 | $pre_uniqid = $objSiteSess->getUniqId(); |
|---|
| 124 | // 注文一時IDの発行 |
|---|
| 125 | $objSiteSess->setUniqId(); |
|---|
| 126 | $uniqid = $objSiteSess->getUniqId(); |
|---|
| 127 | // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ |
|---|
| 128 | if($pre_uniqid != "") { |
|---|
| 129 | $sqlval['order_temp_id'] = $uniqid; |
|---|
| 130 | $where = "order_temp_id = ?"; |
|---|
| 131 | $objQuery = new SC_Query(); |
|---|
| 132 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid)); |
|---|
| 133 | } |
|---|
| 134 | // カートを購入モードに設定 |
|---|
| 135 | $objCartSess->saveCurrentCart($uniqid); |
|---|
| 136 | // 購入ページへ |
|---|
| 137 | $this->sendRedirect(URL_SHOP_TOP); |
|---|
| 138 | exit; |
|---|
| 139 | } |
|---|
| 140 | break; |
|---|
| 141 | default: |
|---|
| 142 | break; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | // カート集計処理 |
|---|
| 146 | $db->sfTotalCart($this, $objCartSess, $arrInfo); |
|---|
| 147 | $this->arrData = $db->sfTotalConfirm($this->arrData, $this, $objCartSess, $arrInfo, $objCustomer); |
|---|
| 148 | |
|---|
| 149 | $this->arrInfo = $arrInfo; |
|---|
| 150 | |
|---|
| 151 | // ログイン判定 |
|---|
| 152 | if($objCustomer->isLoginSuccess()) { |
|---|
| 153 | $this->tpl_login = true; |
|---|
| 154 | $this->tpl_user_point = $objCustomer->getValue('point'); |
|---|
| 155 | $this->tpl_name = $objCustomer->getValue('name01'); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | // 送料無料までの金額を計算 |
|---|
| 159 | $this->tpl_deliv_free = $this->arrInfo['free_rule'] - $this->tpl_total_pretax; |
|---|
| 160 | |
|---|
| 161 | // 前頁のURLを取得 |
|---|
| 162 | $this->tpl_prev_url = $objCartSess->getPrevURL(); |
|---|
| 163 | |
|---|
| 164 | $objView->assignobj($this); |
|---|
| 165 | // フレームを選択(キャンペーンページから遷移なら変更) |
|---|
| 166 | $objCampaignSess->pageView($objView); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /** |
|---|
| 170 | * モバイルページを初期化する. |
|---|
| 171 | * |
|---|
| 172 | * @return void |
|---|
| 173 | */ |
|---|
| 174 | function mobileInit() { |
|---|
| 175 | $this->init(); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | * Page のプロセス(モバイル). |
|---|
| 180 | * |
|---|
| 181 | * @return void |
|---|
| 182 | */ |
|---|
| 183 | function mobileProcess() { |
|---|
| 184 | |
|---|
| 185 | // 買い物を続ける場合 |
|---|
| 186 | if (!isset($_REQUEST['continue'])) $_REQUEST['continue'] = ""; |
|---|
| 187 | if($_REQUEST['continue']) { |
|---|
| 188 | $this->sendRedirect($this->getLocation(MOBILE_URL_SITE_TOP), true); |
|---|
| 189 | exit; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | $objView = new SC_MobileView(false); |
|---|
| 193 | $objCartSess = new SC_CartSession(); |
|---|
| 194 | $objSiteSess = new SC_SiteSession(); |
|---|
| 195 | $objSiteInfo = $objView->objSiteInfo; |
|---|
| 196 | $objCustomer = new SC_Customer(); |
|---|
| 197 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 198 | |
|---|
| 199 | // 基本情報の取得 |
|---|
| 200 | $arrInfo = $objSiteInfo->data; |
|---|
| 201 | |
|---|
| 202 | // 商品購入中にカート内容が変更された。 |
|---|
| 203 | if($objCartSess->getCancelPurchase()) { |
|---|
| 204 | $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。"; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
|---|
| 208 | |
|---|
| 209 | switch($_POST['mode']) { |
|---|
| 210 | case 'confirm': |
|---|
| 211 | // カート内情報の取得 |
|---|
| 212 | $arrRet = $objCartSess->getCartList(); |
|---|
| 213 | $max = count($arrRet); |
|---|
| 214 | $cnt = 0; |
|---|
| 215 | for ($i = 0; $i < $max; $i++) { |
|---|
| 216 | // 商品規格情報の取得 |
|---|
| 217 | $arrData = $objDb->sfGetProductsClass($arrRet[$i]['id']); |
|---|
| 218 | // DBに存在する商品 |
|---|
| 219 | if($arrData != "") { |
|---|
| 220 | $cnt++; |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | // カート商品が1件以上存在する場合 |
|---|
| 224 | if($cnt > 0) { |
|---|
| 225 | // 正常に登録されたことを記録しておく |
|---|
| 226 | $objSiteSess->setRegistFlag(); |
|---|
| 227 | $pre_uniqid = $objSiteSess->getUniqId(); |
|---|
| 228 | // 注文一時IDの発行 |
|---|
| 229 | $objSiteSess->setUniqId(); |
|---|
| 230 | $uniqid = $objSiteSess->getUniqId(); |
|---|
| 231 | // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ |
|---|
| 232 | if($pre_uniqid != "") { |
|---|
| 233 | $sqlval['order_temp_id'] = $uniqid; |
|---|
| 234 | $where = "order_temp_id = ?"; |
|---|
| 235 | $objQuery = new SC_Query(); |
|---|
| 236 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid)); |
|---|
| 237 | } |
|---|
| 238 | // カートを購入モードに設定 |
|---|
| 239 | $objCartSess->saveCurrentCart($uniqid); |
|---|
| 240 | // 購入ページへ |
|---|
| 241 | $this->sendRedirect(MOBILE_URL_SHOP_TOP, true); |
|---|
| 242 | exit; |
|---|
| 243 | } |
|---|
| 244 | break; |
|---|
| 245 | default: |
|---|
| 246 | break; |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
|---|
| 250 | |
|---|
| 251 | /* |
|---|
| 252 | * FIXME sendRedirect() を使った方が良いが無限ループしてしまう... |
|---|
| 253 | */ |
|---|
| 254 | switch($_GET['mode']) { |
|---|
| 255 | case 'up': |
|---|
| 256 | $objCartSess->upQuantity($_GET['cart_no']); |
|---|
| 257 | SC_Utils_Ex::sfReload(session_name() . "=" . session_id()); |
|---|
| 258 | break; |
|---|
| 259 | case 'down': |
|---|
| 260 | $objCartSess->downQuantity($_GET['cart_no']); |
|---|
| 261 | SC_Utils_Ex::sfReload(session_name() . "=" . session_id()); |
|---|
| 262 | break; |
|---|
| 263 | case 'delete': |
|---|
| 264 | $objCartSess->delProduct($_GET['cart_no']); |
|---|
| 265 | SC_Utils_Ex::sfReload(session_name() . "=" . session_id()); |
|---|
| 266 | break; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | // カート集計処理 |
|---|
| 270 | if (empty($arrData)) { |
|---|
| 271 | $arrData = array(); |
|---|
| 272 | } |
|---|
| 273 | $objDb->sfTotalCart($this, $objCartSess, $arrInfo); |
|---|
| 274 | $this->arrData = $objDb->sfTotalConfirm($arrData, $this, $objCartSess, $arrInfo, $objCustomer); |
|---|
| 275 | |
|---|
| 276 | $this->arrInfo = $arrInfo; |
|---|
| 277 | |
|---|
| 278 | // ログイン判定 |
|---|
| 279 | if($objCustomer->isLoginSuccess(true)) { |
|---|
| 280 | $this->tpl_login = true; |
|---|
| 281 | $this->tpl_user_point = $objCustomer->getValue('point'); |
|---|
| 282 | $this->tpl_name = $objCustomer->getValue('name01'); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | // 送料無料までの金額を計算 |
|---|
| 286 | $tpl_deliv_free = $this->arrInfo['free_rule'] - $this->tpl_total_pretax; |
|---|
| 287 | $this->tpl_deliv_free = $tpl_deliv_free; |
|---|
| 288 | |
|---|
| 289 | // 前頁のURLを取得 |
|---|
| 290 | $this->tpl_prev_url = $objCartSess->getPrevURL(); |
|---|
| 291 | |
|---|
| 292 | $objView->assignobj($this); |
|---|
| 293 | $objView->display(SITE_FRAME); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | /** |
|---|
| 297 | * デストラクタ. |
|---|
| 298 | * |
|---|
| 299 | * @return void |
|---|
| 300 | */ |
|---|
| 301 | function destroy() { |
|---|
| 302 | parent::destroy(); |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| 305 | ?> |
|---|