| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 4 | * |
---|
| 5 | * http://www.lockon.co.jp/ |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* カートセッション管理クラス */ |
---|
| 9 | class SC_CartSession { |
---|
| 10 | var $key; |
---|
| 11 | var $key_tmp; // ユニークIDを指定する。 |
---|
| 12 | |
---|
| 13 | /* コンストラクタ */ |
---|
| 14 | function SC_CartSession($key = 'cart') { |
---|
| 15 | SC_Utils::sfDomainSessionStart(); |
---|
| 16 | |
---|
| 17 | if($key == "") $key = "cart"; |
---|
| 18 | $this->key = $key; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | // 商品購入処理中のロック |
---|
| 22 | function saveCurrentCart($key_tmp) { |
---|
| 23 | $this->key_tmp = "savecart_" . $key_tmp; |
---|
| 24 | // すでに情報がなければ現状のカート情報を記録しておく |
---|
| 25 | if(count($_SESSION[$this->key_tmp]) == 0) { |
---|
| 26 | $_SESSION[$this->key_tmp] = $_SESSION[$this->key]; |
---|
| 27 | } |
---|
| 28 | // 1世代古いコピー情報は、削除しておく |
---|
| 29 | foreach($_SESSION as $key => $val) { |
---|
| 30 | if($key != $this->key_tmp && ereg("^savecart_", $key)) { |
---|
| 31 | unset($_SESSION[$key]); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | // 商品購入中の変更があったかをチェックする。 |
---|
| 37 | function getCancelPurchase() { |
---|
| 38 | $ret = $_SESSION[$this->key]['cancel_purchase']; |
---|
| 39 | $_SESSION[$this->key]['cancel_purchase'] = false; |
---|
| 40 | return $ret; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | // 購入処理中に商品に変更がなかったかを判定 |
---|
| 44 | function checkChangeCart() { |
---|
| 45 | $change = false; |
---|
| 46 | $max = $this->getMax(); |
---|
| 47 | for($i = 0; $i <= $max; $i++) { |
---|
| 48 | if ($_SESSION[$this->key][$i]['quantity'] != $_SESSION[$this->key_tmp][$i]['quantity']) { |
---|
| 49 | $change = true; |
---|
| 50 | break; |
---|
| 51 | } |
---|
| 52 | if ($_SESSION[$this->key][$i]['id'] != $_SESSION[$this->key_tmp][$i]['id']) { |
---|
| 53 | $change = true; |
---|
| 54 | break; |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | if ($change) { |
---|
| 58 | // 一時カートのクリア |
---|
| 59 | unset($_SESSION[$this->key_tmp]); |
---|
| 60 | $_SESSION[$this->key]['cancel_purchase'] = true; |
---|
| 61 | } else { |
---|
| 62 | $_SESSION[$this->key]['cancel_purchase'] = false; |
---|
| 63 | } |
---|
| 64 | return $_SESSION[$this->key]['cancel_purchase']; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // 次に割り当てるカートのIDを取得する |
---|
| 68 | function getNextCartID() { |
---|
| 69 | foreach($_SESSION[$this->key] as $key => $val){ |
---|
| 70 | $arrRet[] = $_SESSION[$this->key][$key]['cart_no']; |
---|
| 71 | } |
---|
| 72 | return (max($arrRet) + 1); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // 商品ごとの合計価格 |
---|
| 76 | function getProductTotal($arrInfo, $id) { |
---|
| 77 | $max = $this->getMax(); |
---|
| 78 | for($i = 0; $i <= $max; $i++) { |
---|
| 79 | if(isset($_SESSION[$this->key][$i]['id']) |
---|
| 80 | && $_SESSION[$this->key][$i]['id'] == $id) { |
---|
| 81 | |
---|
| 82 | // 税込み合計 |
---|
| 83 | $price = $_SESSION[$this->key][$i]['price']; |
---|
| 84 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
---|
| 85 | $pre_tax = SC_Utils_Ex::sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
---|
| 86 | $total = $pre_tax * $quantity; |
---|
| 87 | return $total; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | return 0; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // 値のセット |
---|
| 94 | function setProductValue($id, $key, $val) { |
---|
| 95 | $max = $this->getMax(); |
---|
| 96 | for($i = 0; $i <= $max; $i++) { |
---|
| 97 | if(isset($_SESSION[$this->key][$i]['id']) |
---|
| 98 | && $_SESSION[$this->key][$i]['id'] == $id) { |
---|
| 99 | $_SESSION[$this->key][$i][$key] = $val; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | // カート内商品の最大要素番号を取得する。 |
---|
| 105 | function getMax() { |
---|
| 106 | $cnt = 0; |
---|
| 107 | $pos = 0; |
---|
| 108 | $max = 0; |
---|
| 109 | if (count($_SESSION[$this->key]) > 0){ |
---|
| 110 | foreach($_SESSION[$this->key] as $key => $val) { |
---|
| 111 | if (is_numeric($key)) { |
---|
| 112 | if($max < $key) { |
---|
| 113 | $max = $key; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | return ($max); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // カート内商品数の合計 |
---|
| 122 | function getTotalQuantity() { |
---|
| 123 | $total = 0; |
---|
| 124 | $max = $this->getMax(); |
---|
| 125 | for($i = 0; $i <= $max; $i++) { |
---|
| 126 | $total+= $_SESSION[$this->key][$i]['quantity']; |
---|
| 127 | } |
---|
| 128 | return $total; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | // 全商品の合計価格 |
---|
| 133 | function getAllProductsTotal($arrInfo) { |
---|
| 134 | // 税込み合計 |
---|
| 135 | $total = 0; |
---|
| 136 | $max = $this->getMax(); |
---|
| 137 | for($i = 0; $i <= $max; $i++) { |
---|
| 138 | |
---|
| 139 | if (!isset($_SESSION[$this->key][$i]['price'])) { |
---|
| 140 | $_SESSION[$this->key][$i]['price'] = ""; |
---|
| 141 | } |
---|
| 142 | $price = $_SESSION[$this->key][$i]['price']; |
---|
| 143 | |
---|
| 144 | if (!isset($_SESSION[$this->key][$i]['quantity'])) { |
---|
| 145 | $_SESSION[$this->key][$i]['quantity'] = ""; |
---|
| 146 | } |
---|
| 147 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
---|
| 148 | |
---|
| 149 | $pre_tax = SC_Utils::sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
---|
| 150 | $total+= ($pre_tax * $quantity); |
---|
| 151 | } |
---|
| 152 | return $total; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // 全商品の合計税金 |
---|
| 156 | function getAllProductsTax($arrInfo) { |
---|
| 157 | // 税合計 |
---|
| 158 | $total = 0; |
---|
| 159 | $max = $this->getMax(); |
---|
| 160 | for($i = 0; $i <= $max; $i++) { |
---|
| 161 | $price = $_SESSION[$this->key][$i]['price']; |
---|
| 162 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
---|
| 163 | $tax = SC_Utils_Ex::sfTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
---|
| 164 | $total+= ($tax * $quantity); |
---|
| 165 | } |
---|
| 166 | return $total; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | // 全商品の合計ポイント |
---|
| 170 | function getAllProductsPoint() { |
---|
| 171 | // ポイント合計 |
---|
| 172 | $total = 0; |
---|
| 173 | $max = $this->getMax(); |
---|
| 174 | for($i = 0; $i <= $max; $i++) { |
---|
| 175 | $price = $_SESSION[$this->key][$i]['price']; |
---|
| 176 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
---|
| 177 | |
---|
| 178 | if (!isset($_SESSION[$this->key][$i]['point_rate'])) { |
---|
| 179 | $_SESSION[$this->key][$i]['point_rate'] = ""; |
---|
| 180 | } |
---|
| 181 | $point_rate = $_SESSION[$this->key][$i]['point_rate']; |
---|
| 182 | |
---|
| 183 | if (!isset($_SESSION[$this->key][$i]['id'][0])) { |
---|
| 184 | $_SESSION[$this->key][$i]['id'][0] = ""; |
---|
| 185 | } |
---|
| 186 | $id = $_SESSION[$this->key][$i]['id'][0]; |
---|
| 187 | $point = SC_Utils_Ex::sfPrePoint($price, $point_rate, POINT_RULE, $id); |
---|
| 188 | $total+= ($point * $quantity); |
---|
| 189 | } |
---|
| 190 | return $total; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | // カートへの商品追加 |
---|
| 194 | function addProduct($id, $quantity, $campaign_id = "") { |
---|
| 195 | $find = false; |
---|
| 196 | $max = $this->getMax(); |
---|
| 197 | for($i = 0; $i <= $max; $i++) { |
---|
| 198 | |
---|
| 199 | if($_SESSION[$this->key][$i]['id'] == $id) { |
---|
| 200 | $val = $_SESSION[$this->key][$i]['quantity'] + $quantity; |
---|
| 201 | if(strlen($val) <= INT_LEN) { |
---|
| 202 | $_SESSION[$this->key][$i]['quantity']+= $quantity; |
---|
| 203 | if(!empty($campaign_id)){ |
---|
| 204 | $_SESSION[$this->key][$i]['campaign_id'] = $campaign_id; |
---|
| 205 | $_SESSION[$this->key][$i]['is_campaign'] = true; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | $find = true; |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | if(!$find) { |
---|
| 212 | $_SESSION[$this->key][$max+1]['id'] = $id; |
---|
| 213 | $_SESSION[$this->key][$max+1]['quantity'] = $quantity; |
---|
| 214 | $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID(); |
---|
| 215 | if(!empty($campaign_id)){ |
---|
| 216 | $_SESSION[$this->key][$max+1]['campaign_id'] = $campaign_id; |
---|
| 217 | $_SESSION[$this->key][$max+1]['is_campaign'] = true; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // 前頁のURLを記録しておく |
---|
| 223 | function setPrevURL($url) { |
---|
| 224 | // 前頁として記録しないページを指定する。 |
---|
| 225 | $arrExclude = array( |
---|
| 226 | "detail_image.php", |
---|
| 227 | "/shopping/" |
---|
| 228 | ); |
---|
| 229 | $exclude = false; |
---|
| 230 | // ページチェックを行う。 |
---|
| 231 | foreach($arrExclude as $val) { |
---|
| 232 | if(ereg($val, $url)) { |
---|
| 233 | $exclude = true; |
---|
| 234 | break; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | // 除外ページでない場合は、前頁として記録する。 |
---|
| 238 | if(!$exclude) { |
---|
| 239 | $_SESSION[$this->key]['prev_url'] = $url; |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | // 前頁のURLを取得する |
---|
| 244 | function getPrevURL() { |
---|
| 245 | return $_SESSION[$this->key]['prev_url']; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | // キーが一致した商品の削除 |
---|
| 249 | function delProductKey($keyname, $val) { |
---|
| 250 | $max = count($_SESSION[$this->key]); |
---|
| 251 | for($i = 0; $i < $max; $i++) { |
---|
| 252 | if($_SESSION[$this->key][$i][$keyname] == $val) { |
---|
| 253 | unset($_SESSION[$this->key][$i]); |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | function setValue($key, $val) { |
---|
| 259 | $_SESSION[$this->key][$key] = $val; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | function getValue($key) { |
---|
| 263 | return $_SESSION[$this->key][$key]; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | function getCartList() { |
---|
| 267 | $max = $this->getMax(); |
---|
| 268 | for($i = 0; $i <= $max; $i++) { |
---|
| 269 | if(isset($_SESSION[$this->key][$i]['cart_no']) |
---|
| 270 | && $_SESSION[$this->key][$i]['cart_no'] != "") { |
---|
| 271 | $arrRet[] = $_SESSION[$this->key][$i]; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | return $arrRet; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | // カート内にある商品IDを全て取得する |
---|
| 278 | function getAllProductID() { |
---|
| 279 | $max = $this->getMax(); |
---|
| 280 | for($i = 0; $i <= $max; $i++) { |
---|
| 281 | if($_SESSION[$this->key][$i]['cart_no'] != "") { |
---|
| 282 | $arrRet[] = $_SESSION[$this->key][$i]['id'][0]; |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | return $arrRet; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | function delAllProducts() { |
---|
| 289 | $max = $this->getMax(); |
---|
| 290 | for($i = 0; $i <= $max; $i++) { |
---|
| 291 | unset($_SESSION[$this->key][$i]); |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | // 商品の削除 |
---|
| 296 | function delProduct($cart_no) { |
---|
| 297 | $max = $this->getMax(); |
---|
| 298 | for($i = 0; $i <= $max; $i++) { |
---|
| 299 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
---|
| 300 | unset($_SESSION[$this->key][$i]); |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | // 個数の増加 |
---|
| 306 | function upQuantity($cart_no) { |
---|
| 307 | $max = $this->getMax(); |
---|
| 308 | for($i = 0; $i <= $max; $i++) { |
---|
| 309 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
---|
| 310 | if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) { |
---|
| 311 | $_SESSION[$this->key][$i]['quantity']++; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | // 個数の減少 |
---|
| 318 | function downQuantity($cart_no) { |
---|
| 319 | $max = $this->getMax(); |
---|
| 320 | for($i = 0; $i <= $max; $i++) { |
---|
| 321 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
---|
| 322 | if($_SESSION[$this->key][$i]['quantity'] > 1) { |
---|
| 323 | $_SESSION[$this->key][$i]['quantity']--; |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | // 全商品の合計送料 |
---|
| 330 | function getAllProductsDelivFee() { |
---|
| 331 | // ポイント合計 |
---|
| 332 | $total = 0; |
---|
| 333 | $max = $this->getMax(); |
---|
| 334 | for($i = 0; $i <= $max; $i++) { |
---|
| 335 | $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee']; |
---|
| 336 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
---|
| 337 | $total+= ($deliv_fee * $quantity); |
---|
| 338 | } |
---|
| 339 | return $total; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | // カートの中の売り切れチェック |
---|
| 343 | function chkSoldOut($arrCartList, $is_mobile = false){ |
---|
| 344 | foreach($arrCartList as $key => $val){ |
---|
| 345 | if($val['quantity'] == 0){ |
---|
| 346 | // 売り切れ商品をカートから削除する |
---|
| 347 | $this->delProduct($val['cart_no']); |
---|
| 348 | sfDispSiteError(SOLD_OUT, "", true, "", $is_mobile); |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | /** |
---|
| 354 | * カートの中のキャンペーン商品のチェック |
---|
| 355 | * @param integer $campaign_id キャンペーンID |
---|
| 356 | * @return boolean True:キャンペーン商品有り False:キャンペーン商品無し |
---|
| 357 | */ |
---|
| 358 | function chkCampaign($campaign_id){ |
---|
| 359 | $max = $this->getMax(); |
---|
| 360 | for($i = 0; $i <= $max; $i++) { |
---|
| 361 | if($_SESSION[$this->key][$i]['is_campaign'] and $_SESSION[$this->key][$i]['campaign_id'] == $campaign_id) return true; |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | return false; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | } |
---|
| 368 | ?> |
---|