- Timestamp:
- 2007/07/20 15:58:59 (17 years ago)
- Location:
- branches/feature-module-update
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update
-
Property
svn:ignore
set to
.cache
.settings
.projectOptions
-
Property
svn:ignore
set to
-
branches/feature-module-update/data/class/SC_CartSession.php
r14732 r15078 6 6 */ 7 7 8 /* ¥«¡¼¥È¥»¥Ã¥·¥ç¥ó´ÉÍý¥¯¥é¥¹*/8 /* カートセッション管理クラス */ 9 9 class SC_CartSession { 10 11 var $key_tmp; // ¥æ¥Ë¡¼¥¯ID¤ò»ØÄꤹ¤ë¡£ 12 13 /* ¥³¥ó¥¹¥È¥é¥¯¥¿*/14 15 16 17 18 19 20 21 // ¾¦ÉʹØÆþ½èÍýÃæ¤Î¥í¥Ã¥¯ 22 23 24 // ¤¹¤Ç¤Ë¾ðÊ󤬤ʤ±¤ì¤Ð¸½¾õ¤Î¥«¡¼¥È¾ðÊó¤òµÏ¿¤·¤Æ¤ª¤¯ 25 26 27 28 // 1À¤Âå¸Å¤¤¥³¥Ô¡¼¾ðÊó¤Ï¡¢ºï½ü¤·¤Æ¤ª¤¯ 29 30 31 32 33 34 35 36 // ¾¦ÉʹØÆþÃæ¤ÎÊѹ¹¤¬¤¢¤Ã¤¿¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£ 37 38 39 40 41 42 43 // ¹ØÆþ½èÍýÃæ¤Ë¾¦ÉʤËÊѹ¹¤¬¤Ê¤«¤Ã¤¿¤«¤òȽÄê 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 // °ì»þ¥«¡¼¥È¤Î¥¯¥ê¥¢ 59 60 61 62 63 64 65 66 67 // ¼¡¤Ë³ä¤êÅö¤Æ¤ë¥«¡¼¥È¤ÎID¤ò¼èÆÀ¤¹¤ë 68 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 69 foreach($_SESSION[$this->key] as $key => $val){ 70 70 $arrRet[] = $_SESSION[$this->key][$key]['cart_no']; 71 71 } 72 return (max($arrRet) + 1); 73 74 75 // ¾¦Éʤ´¤È¤Î¹ç·×²Á³Ê 76 77 78 79 80 // Àǹþ¤ß¹ç·× 81 82 83 84 85 86 87 88 89 90 91 // ÃͤΥ»¥Ã¥È 92 93 94 95 96 97 98 99 100 101 // ¥«¡¼¥ÈÆ⾦ÉʤκÇÂçÍ×ÁÇÈÖ¹æ¤ò¼èÆÀ¤¹¤ë¡£ 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 // ¥«¡¼¥ÈÆ⾦ÉÊ¿ô¤Î¹ç·× 119 120 121 122 123 124 125 126 127 128 129 // Á´¾¦Éʤιç·×²Á³Ê 130 131 // Àǹþ¤ß¹ç·× 132 133 134 135 136 137 $pre_tax =sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']);138 139 140 141 142 143 // Á´¾¦Éʤιç·×ÀǶâ 144 145 // Àǹç·× 146 147 148 149 150 151 152 153 154 155 156 157 // Á´¾¦Éʤιç·×¥Ý¥¤¥ó¥È 158 159 // ¥Ý¥¤¥ó¥È¹ç·× 160 161 162 163 164 165 166 167 168 169 170 171 172 173 // ¥«¡¼¥È¤Ø¤Î¾¦ÉÊÄɲà 174 175 176 177 178 179 180 181 182 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($_SESSION[$this->key][$i]['id'] == $id) { 80 // 税込み合計 81 $price = $_SESSION[$this->key][$i]['price']; 82 $quantity = $_SESSION[$this->key][$i]['quantity']; 83 $pre_tax = sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); 84 $total = $pre_tax * $quantity; 85 return $total; 86 } 87 } 88 return 0; 89 } 90 91 // 値のセット 92 function setProductValue($id, $key, $val) { 93 $max = $this->getMax(); 94 for($i = 0; $i <= $max; $i++) { 95 if($_SESSION[$this->key][$i]['id'] == $id) { 96 $_SESSION[$this->key][$i][$key] = $val; 97 } 98 } 99 } 100 101 // カート内商品の最大要素番号を取得する。 102 function getMax() { 103 $cnt = 0; 104 $pos = 0; 105 $max = 0; 106 if (count($_SESSION[$this->key]) > 0){ 107 foreach($_SESSION[$this->key] as $key => $val) { 108 if (is_numeric($key)) { 109 if($max < $key) { 110 $max = $key; 111 } 112 } 113 } 114 } 115 return ($max); 116 } 117 118 // カート内商品数の合計 119 function getTotalQuantity() { 120 $total = 0; 121 $max = $this->getMax(); 122 for($i = 0; $i <= $max; $i++) { 123 $total+= $_SESSION[$this->key][$i]['quantity']; 124 } 125 return $total; 126 } 127 128 129 // 全商品の合計価格 130 function getAllProductsTotal($arrInfo) { 131 // 税込み合計 132 $total = 0; 133 $max = $this->getMax(); 134 for($i = 0; $i <= $max; $i++) { 135 $price = $_SESSION[$this->key][$i]['price']; 136 $quantity = $_SESSION[$this->key][$i]['quantity']; 137 $pre_tax = SC_Utils::sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); 138 $total+= ($pre_tax * $quantity); 139 } 140 return $total; 141 } 142 143 // 全商品の合計税金 144 function getAllProductsTax($arrInfo) { 145 // 税合計 146 $total = 0; 147 $max = $this->getMax(); 148 for($i = 0; $i <= $max; $i++) { 149 $price = $_SESSION[$this->key][$i]['price']; 150 $quantity = $_SESSION[$this->key][$i]['quantity']; 151 $tax = sfTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); 152 $total+= ($tax * $quantity); 153 } 154 return $total; 155 } 156 157 // 全商品の合計ポイント 158 function getAllProductsPoint() { 159 // ポイント合計 160 $total = 0; 161 $max = $this->getMax(); 162 for($i = 0; $i <= $max; $i++) { 163 $price = $_SESSION[$this->key][$i]['price']; 164 $quantity = $_SESSION[$this->key][$i]['quantity']; 165 $point_rate = $_SESSION[$this->key][$i]['point_rate']; 166 $id = $_SESSION[$this->key][$i]['id'][0]; 167 $point = sfPrePoint($price, $point_rate, POINT_RULE, $id); 168 $total+= ($point * $quantity); 169 } 170 return $total; 171 } 172 173 // カートへの商品追加 174 function addProduct($id, $quantity, $campaign_id = "") { 175 $find = false; 176 $max = $this->getMax(); 177 for($i = 0; $i <= $max; $i++) { 178 179 if($_SESSION[$this->key][$i]['id'] == $id) { 180 $val = $_SESSION[$this->key][$i]['quantity'] + $quantity; 181 if(strlen($val) <= INT_LEN) { 182 $_SESSION[$this->key][$i]['quantity']+= $quantity; 183 183 if(!empty($campaign_id)){ 184 184 $_SESSION[$this->key][$i]['campaign_id'] = $campaign_id; 185 185 $_SESSION[$this->key][$i]['is_campaign'] = true; 186 186 } 187 188 189 190 191 192 193 194 187 } 188 $find = true; 189 } 190 } 191 if(!$find) { 192 $_SESSION[$this->key][$max+1]['id'] = $id; 193 $_SESSION[$this->key][$max+1]['quantity'] = $quantity; 194 $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID(); 195 195 if(!empty($campaign_id)){ 196 196 $_SESSION[$this->key][$max+1]['campaign_id'] = $campaign_id; 197 197 $_SESSION[$this->key][$max+1]['is_campaign'] = true; 198 198 } 199 200 201 202 // Á°ÊǤÎURL¤òµÏ¿¤·¤Æ¤ª¤¯ 203 204 // Á°ÊǤȤ·¤ÆµÏ¿¤·¤Ê¤¤¥Ú¡¼¥¸¤ò»ØÄꤹ¤ë¡£ 205 206 207 208 209 210 // ¥Ú¡¼¥¸¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¡£ 211 212 213 214 215 216 217 // ½ü³°¥Ú¡¼¥¸¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢Á°ÊǤȤ·¤ÆµÏ¿¤¹¤ë¡£ 218 if(!$exclude) { 219 220 221 222 223 // Á°ÊǤÎURL¤ò¼èÆÀ¤¹¤ë 224 225 226 227 228 // ¥¡¼¤¬°ìÃפ·¤¿¾¦Éʤκï½ü 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 // ¥«¡¼¥ÈÆâ¤Ë¤¢¤ë¾¦ÉʣɣĤòÁ´¤Æ¼èÆÀ¤¹¤ë 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 // ¾¦Éʤκï½ü 275 276 277 278 279 280 281 282 283 284 // ¸Ä¿ô¤ÎÁý²Ã 285 286 287 288 289 290 291 292 293 294 295 296 // ¸Ä¿ô¤Î¸º¾¯ 297 298 299 300 301 302 303 304 305 306 307 308 // Á´¾¦Éʤιç·×Á÷ÎÁ 309 310 // ¥Ý¥¤¥ó¥È¹ç·× 311 312 313 314 315 316 317 318 319 320 321 // ¥«¡¼¥È¤ÎÃæ¤ÎÇä¤êÀÚ¤ì¥Á¥§¥Ã¥¯ 322 323 324 325 // Çä¤êÀڤ쾦Éʤò¥«¡¼¥È¤«¤éºï½ü¤¹¤ë 326 327 328 329 330 331 199 } 200 } 201 202 // 前頁のURLを記録しておく 203 function setPrevURL($url) { 204 // 前頁として記録しないページを指定する。 205 $arrExclude = array( 206 "detail_image.php", 207 "/shopping/" 208 ); 209 $exclude = false; 210 // ページチェックを行う。 211 foreach($arrExclude as $val) { 212 if(ereg($val, $url)) { 213 $exclude = true; 214 break; 215 } 216 } 217 // 除外ページでない場合は、前頁として記録する。 218 if(!$exclude) { 219 $_SESSION[$this->key]['prev_url'] = $url; 220 } 221 } 222 223 // 前頁のURLを取得する 224 function getPrevURL() { 225 return $_SESSION[$this->key]['prev_url']; 226 } 227 228 // キーが一致した商品の削除 229 function delProductKey($keyname, $val) { 230 $max = count($_SESSION[$this->key]); 231 for($i = 0; $i < $max; $i++) { 232 if($_SESSION[$this->key][$i][$keyname] == $val) { 233 unset($_SESSION[$this->key][$i]); 234 } 235 } 236 } 237 238 function setValue($key, $val) { 239 $_SESSION[$this->key][$key] = $val; 240 } 241 242 function getValue($key) { 243 return $_SESSION[$this->key][$key]; 244 } 245 246 function getCartList() { 247 $max = $this->getMax(); 248 for($i = 0; $i <= $max; $i++) { 249 if($_SESSION[$this->key][$i]['cart_no'] != "") { 250 $arrRet[] = $_SESSION[$this->key][$i]; 251 } 252 } 253 return $arrRet; 254 } 255 256 // カート内にある商品IDを全て取得する 257 function getAllProductID() { 258 $max = $this->getMax(); 259 for($i = 0; $i <= $max; $i++) { 260 if($_SESSION[$this->key][$i]['cart_no'] != "") { 261 $arrRet[] = $_SESSION[$this->key][$i]['id'][0]; 262 } 263 } 264 return $arrRet; 265 } 266 267 function delAllProducts() { 268 $max = $this->getMax(); 269 for($i = 0; $i <= $max; $i++) { 270 unset($_SESSION[$this->key][$i]); 271 } 272 } 273 274 // 商品の削除 275 function delProduct($cart_no) { 276 $max = $this->getMax(); 277 for($i = 0; $i <= $max; $i++) { 278 if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { 279 unset($_SESSION[$this->key][$i]); 280 } 281 } 282 } 283 284 // 個数の増加 285 function upQuantity($cart_no) { 286 $max = $this->getMax(); 287 for($i = 0; $i <= $max; $i++) { 288 if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { 289 if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) { 290 $_SESSION[$this->key][$i]['quantity']++; 291 } 292 } 293 } 294 } 295 296 // 個数の減少 297 function downQuantity($cart_no) { 298 $max = $this->getMax(); 299 for($i = 0; $i <= $max; $i++) { 300 if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { 301 if($_SESSION[$this->key][$i]['quantity'] > 1) { 302 $_SESSION[$this->key][$i]['quantity']--; 303 } 304 } 305 } 306 } 307 308 // 全商品の合計送料 309 function getAllProductsDelivFee() { 310 // ポイント合計 311 $total = 0; 312 $max = $this->getMax(); 313 for($i = 0; $i <= $max; $i++) { 314 $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee']; 315 $quantity = $_SESSION[$this->key][$i]['quantity']; 316 $total+= ($deliv_fee * $quantity); 317 } 318 return $total; 319 } 320 321 // カートの中の売り切れチェック 322 function chkSoldOut($arrCartList, $is_mobile = false){ 323 foreach($arrCartList as $key => $val){ 324 if($val['quantity'] == 0){ 325 // 売り切れ商品をカートから削除する 326 $this->delProduct($val['cart_no']); 327 sfDispSiteError(SOLD_OUT, "", true, "", $is_mobile); 328 } 329 } 330 } 331 332 332 /** 333 * ¥«¡¼¥È¤ÎÃæ¤Î¥¥ã¥ó¥Ú¡¼¥ó¾¦ÉʤΥÁ¥§¥Ã¥¯334 * @param integer $campaign_id ¥¥ã¥ó¥Ú¡¼¥óID335 * @return boolean True: ¥¥ã¥ó¥Ú¡¼¥ó¾¦ÉÊͤê False:¥¥ã¥ó¥Ú¡¼¥ó¾¦ÉÊ̵¤·333 * カートの中のキャンペーン商品のチェック 334 * @param integer $campaign_id キャンペーンID 335 * @return boolean True:キャンペーン商品有り False:キャンペーン商品無し 336 336 */ 337 338 339 340 341 342 343 344 345 337 function chkCampaign($campaign_id){ 338 $max = $this->getMax(); 339 for($i = 0; $i <= $max; $i++) { 340 if($_SESSION[$this->key][$i]['is_campaign'] and $_SESSION[$this->key][$i]['campaign_id'] == $campaign_id) return true; 341 } 342 343 return false; 344 } 345 346 346 } 347 347 ?>
Note: See TracChangeset
for help on using the changeset viewer.