| 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 | 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 | $max = count($_SESSION[$this->key]); |
|---|
| 70 | for($i = 0; $i < $max; $i++) { |
|---|
| 71 | $arrRet[] = $_SESSION[$this->key][$i]['cart_no']; |
|---|
| 72 | } |
|---|
| 73 | return (max($arrRet) + 1); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | // ¾¦Éʤ´¤È¤Î¹ç·×²Á³Ê |
|---|
| 77 | function getProductTotal($arrInfo, $id) { |
|---|
| 78 | $max = $this->getMax(); |
|---|
| 79 | for($i = 0; $i <= $max; $i++) { |
|---|
| 80 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 81 | // Àǹþ¤ß¹ç·× |
|---|
| 82 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 83 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 84 | $pre_tax = sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 85 | $total = $pre_tax * $quantity; |
|---|
| 86 | return $total; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | return 0; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // ÃͤΥ»¥Ã¥È |
|---|
| 93 | function setProductValue($id, $key, $val) { |
|---|
| 94 | $max = $this->getMax(); |
|---|
| 95 | for($i = 0; $i <= $max; $i++) { |
|---|
| 96 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 97 | $_SESSION[$this->key][$i][$key] = $val; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | // ¥«¡¼¥ÈÆâ¾¦ÉʤκÇÂçÍ×ÁÇÈÖ¹æ¤ò¼èÆÀ¤¹¤ë¡£ |
|---|
| 103 | function getMax() { |
|---|
| 104 | $cnt = 0; |
|---|
| 105 | $pos = 0; |
|---|
| 106 | $max = 0; |
|---|
| 107 | if (count($_SESSION[$this->key]) > 0){ |
|---|
| 108 | foreach($_SESSION[$this->key] as $key => $val) { |
|---|
| 109 | if (is_numeric($key)) { |
|---|
| 110 | if($max < $key) { |
|---|
| 111 | $max = $key; |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | return ($max); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // ¥«¡¼¥ÈÆâ¾¦ÉÊ¿ô¤Î¹ç·× |
|---|
| 120 | function getTotalQuantity() { |
|---|
| 121 | $total = 0; |
|---|
| 122 | $max = $this->getMax(); |
|---|
| 123 | for($i = 0; $i <= $max; $i++) { |
|---|
| 124 | $total+= $_SESSION[$this->key][$i]['quantity']; |
|---|
| 125 | } |
|---|
| 126 | return $total; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | // Á´¾¦Éʤιç·×²Á³Ê |
|---|
| 131 | function getAllProductsTotal($arrInfo) { |
|---|
| 132 | // Àǹþ¤ß¹ç·× |
|---|
| 133 | $total = 0; |
|---|
| 134 | $max = $this->getMax(); |
|---|
| 135 | for($i = 0; $i <= $max; $i++) { |
|---|
| 136 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 137 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 138 | $pre_tax = sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 139 | $total+= ($pre_tax * $quantity); |
|---|
| 140 | } |
|---|
| 141 | return $total; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | // Á´¾¦Éʤιç·×ÀǶâ |
|---|
| 145 | function getAllProductsTax($arrInfo) { |
|---|
| 146 | // Àǹç·× |
|---|
| 147 | $total = 0; |
|---|
| 148 | $max = $this->getMax(); |
|---|
| 149 | for($i = 0; $i <= $max; $i++) { |
|---|
| 150 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 151 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 152 | $tax = sfTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 153 | $total+= ($tax * $quantity); |
|---|
| 154 | } |
|---|
| 155 | return $total; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | // Á´¾¦Éʤιç·×¥Ý¥¤¥ó¥È |
|---|
| 159 | function getAllProductsPoint() { |
|---|
| 160 | // ¥Ý¥¤¥ó¥È¹ç·× |
|---|
| 161 | $total = 0; |
|---|
| 162 | $max = $this->getMax(); |
|---|
| 163 | for($i = 0; $i <= $max; $i++) { |
|---|
| 164 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 165 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 166 | $point_rate = $_SESSION[$this->key][$i]['point_rate']; |
|---|
| 167 | $id = $_SESSION[$this->key][$i]['id'][0]; |
|---|
| 168 | $point = sfPrePoint($price, $point_rate, POINT_RULE, $id); |
|---|
| 169 | $total+= ($point * $quantity); |
|---|
| 170 | } |
|---|
| 171 | return $total; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | // ¥«¡¼¥È¤Ø¤Î¾¦ÉÊÄɲà |
|---|
| 175 | function addProduct($id, $quantity) { |
|---|
| 176 | $find = false; |
|---|
| 177 | $max = $this->getMax(); |
|---|
| 178 | for($i = 0; $i <= $max; $i++) { |
|---|
| 179 | |
|---|
| 180 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 181 | $val = $_SESSION[$this->key][$i]['quantity'] + $quantity; |
|---|
| 182 | if(strlen($val) <= INT_LEN) { |
|---|
| 183 | $_SESSION[$this->key][$i]['quantity']+= $quantity; |
|---|
| 184 | } |
|---|
| 185 | $find = true; |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | if(!$find) { |
|---|
| 189 | $_SESSION[$this->key][$max+1]['id'] = $id; |
|---|
| 190 | $_SESSION[$this->key][$max+1]['quantity'] = $quantity; |
|---|
| 191 | $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID(); |
|---|
| 192 | } |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | // Á°ÊǤÎURL¤òµÏ¿¤·¤Æ¤ª¤¯ |
|---|
| 196 | function setPrevURL($url) { |
|---|
| 197 | // Á°ÊǤȤ·¤ÆµÏ¿¤·¤Ê¤¤¥Ú¡¼¥¸¤ò»ØÄꤹ¤ë¡£ |
|---|
| 198 | $arrExclude = array( |
|---|
| 199 | "detail_image.php", |
|---|
| 200 | "/shopping/" |
|---|
| 201 | ); |
|---|
| 202 | $exclude = false; |
|---|
| 203 | // ¥Ú¡¼¥¸¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¡£ |
|---|
| 204 | foreach($arrExclude as $val) { |
|---|
| 205 | if(ereg($val, $url)) { |
|---|
| 206 | $exclude = true; |
|---|
| 207 | break; |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | // ½ü³°¥Ú¡¼¥¸¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢Á°ÊǤȤ·¤ÆµÏ¿¤¹¤ë¡£ |
|---|
| 211 | if(!$exclude) { |
|---|
| 212 | $_SESSION[$this->key]['prev_url'] = $url; |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | // Á°ÊǤÎURL¤ò¼èÆÀ¤¹¤ë |
|---|
| 217 | function getPrevURL() { |
|---|
| 218 | return $_SESSION[$this->key]['prev_url']; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | // ¥¡¼¤¬°ìÃפ·¤¿¾¦Éʤκï½ü |
|---|
| 222 | function delProductKey($keyname, $val) { |
|---|
| 223 | $max = count($_SESSION[$this->key]); |
|---|
| 224 | for($i = 0; $i < $max; $i++) { |
|---|
| 225 | if($_SESSION[$this->key][$i][$keyname] == $val) { |
|---|
| 226 | unset($_SESSION[$this->key][$i]); |
|---|
| 227 | } |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | function setValue($key, $val) { |
|---|
| 232 | $_SESSION[$this->key][$key] = $val; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | function getValue($key) { |
|---|
| 236 | return $_SESSION[$this->key][$key]; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | function getCartList() { |
|---|
| 240 | $max = $this->getMax(); |
|---|
| 241 | for($i = 0; $i <= $max; $i++) { |
|---|
| 242 | if($_SESSION[$this->key][$i]['cart_no'] != "") { |
|---|
| 243 | $arrRet[] = $_SESSION[$this->key][$i]; |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | return $arrRet; |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | // ¥«¡¼¥ÈÆâ¤Ë¤¢¤ë¾¦ÉʣɣĤòÁ´¤Æ¼èÆÀ¤¹¤ë |
|---|
| 250 | function getAllProductID() { |
|---|
| 251 | $max = $this->getMax(); |
|---|
| 252 | for($i = 0; $i <= $max; $i++) { |
|---|
| 253 | if($_SESSION[$this->key][$i]['cart_no'] != "") { |
|---|
| 254 | $arrRet[] = $_SESSION[$this->key][$i]['id'][0]; |
|---|
| 255 | } |
|---|
| 256 | } |
|---|
| 257 | return $arrRet; |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | function delAllProducts() { |
|---|
| 261 | $max = $this->getMax(); |
|---|
| 262 | for($i = 0; $i <= $max; $i++) { |
|---|
| 263 | unset($_SESSION[$this->key][$i]); |
|---|
| 264 | } |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | // ¾¦Éʤκï½ü |
|---|
| 268 | function delProduct($cart_no) { |
|---|
| 269 | $max = $this->getMax(); |
|---|
| 270 | for($i = 0; $i <= $max; $i++) { |
|---|
| 271 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 272 | unset($_SESSION[$this->key][$i]); |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | // ¸Ä¿ô¤ÎÁý²Ã |
|---|
| 278 | function upQuantity($cart_no) { |
|---|
| 279 | $max = $this->getMax(); |
|---|
| 280 | for($i = 0; $i <= $max; $i++) { |
|---|
| 281 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 282 | if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) { |
|---|
| 283 | $_SESSION[$this->key][$i]['quantity']++; |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | // ¸Ä¿ô¤Î¸º¾¯ |
|---|
| 290 | function downQuantity($cart_no) { |
|---|
| 291 | $max = $this->getMax(); |
|---|
| 292 | for($i = 0; $i <= $max; $i++) { |
|---|
| 293 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 294 | if($_SESSION[$this->key][$i]['quantity'] > 1) { |
|---|
| 295 | $_SESSION[$this->key][$i]['quantity']--; |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | // Á´¾¦Éʤιç·×Á÷ÎÁ |
|---|
| 302 | function getAllProductsDelivFee() { |
|---|
| 303 | // ¥Ý¥¤¥ó¥È¹ç·× |
|---|
| 304 | $total = 0; |
|---|
| 305 | $max = $this->getMax(); |
|---|
| 306 | for($i = 0; $i <= $max; $i++) { |
|---|
| 307 | $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee']; |
|---|
| 308 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 309 | $total+= ($deliv_fee * $quantity); |
|---|
| 310 | } |
|---|
| 311 | return $total; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | // ¥«¡¼¥È¤ÎÃæ¤ÎÇä¤êÀÚ¤ì¥Á¥§¥Ã¥¯ |
|---|
| 315 | function chkSoldOut($arrCartList){ |
|---|
| 316 | foreach($arrCartList as $key => $val){ |
|---|
| 317 | if($val['quantity'] == 0){ |
|---|
| 318 | // Çä¤êÀڤ쾦Éʤò¥«¡¼¥È¤«¤éºï½ü¤¹¤ë |
|---|
| 319 | $this->delProduct($val['cart_no']); |
|---|
| 320 | sfDispSiteError(SOLD_OUT, "", true); |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | } |
|---|
| 326 | ?> |
|---|