| 1 | <?php |
|---|
| 2 | /* ¥«¡¼¥È¥»¥Ã¥·¥ç¥ó´ÉÍý¥¯¥é¥¹ */ |
|---|
| 3 | class SC_CartSession { |
|---|
| 4 | var $key; |
|---|
| 5 | var $key_tmp; // ¥æ¥Ë¡¼¥¯ID¤ò»ØÄꤹ¤ë¡£ |
|---|
| 6 | |
|---|
| 7 | /* ¥³¥ó¥¹¥È¥é¥¯¥¿ */ |
|---|
| 8 | function SC_CartSession($key = 'cart') { |
|---|
| 9 | sfDomainSessionStart(); |
|---|
| 10 | $this->key = $key; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | // ¾¦ÉÊ¹ØÆþ½èÍýÃæ¤Î¥í¥Ã¥¯ |
|---|
| 14 | function saveCurrentCart($key_tmp) { |
|---|
| 15 | $this->key_tmp = "savecart_" . $key_tmp; |
|---|
| 16 | // ¤¹¤Ç¤Ë¾ðÊ󤬤ʤ±¤ì¤Ð¸½¾õ¤Î¥«¡¼¥È¾ðÊó¤òµÏ¿¤·¤Æ¤ª¤¯ |
|---|
| 17 | if(count($_SESSION[$this->key_tmp]) == 0) { |
|---|
| 18 | $_SESSION[$this->key_tmp] = $_SESSION[$this->key]; |
|---|
| 19 | } |
|---|
| 20 | // 1À¤Âå¸Å¤¤¥³¥Ô¡¼¾ðÊó¤Ï¡¢ºï½ü¤·¤Æ¤ª¤¯ |
|---|
| 21 | foreach($_SESSION as $key => $val) { |
|---|
| 22 | if($key != $this->key_tmp && ereg("^savecart_", $key)) { |
|---|
| 23 | unset($_SESSION[$key]); |
|---|
| 24 | } |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | // ¾¦ÉÊ¹ØÆþÃæ¤ÎÊѹ¹¤¬¤¢¤Ã¤¿¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£ |
|---|
| 29 | function getCancelPurchase() { |
|---|
| 30 | $ret = $_SESSION[$this->key]['cancel_purchase']; |
|---|
| 31 | $_SESSION[$this->key]['cancel_purchase'] = false; |
|---|
| 32 | return $ret; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | // ¹ØÆþ½èÍýÃæ¤Ë¾¦ÉʤËÊѹ¹¤¬¤Ê¤«¤Ã¤¿¤«¤òȽÄê |
|---|
| 36 | function checkChangeCart() { |
|---|
| 37 | $change = false; |
|---|
| 38 | $max = $this->getMax(); |
|---|
| 39 | for($i = 0; $i <= $max; $i++) { |
|---|
| 40 | if ($_SESSION[$this->key][$i]['quantity'] != $_SESSION[$this->key_tmp][$i]['quantity']) { |
|---|
| 41 | $change = true; |
|---|
| 42 | break; |
|---|
| 43 | } |
|---|
| 44 | if ($_SESSION[$this->key][$i]['id'] != $_SESSION[$this->key_tmp][$i]['id']) { |
|---|
| 45 | $change = true; |
|---|
| 46 | break; |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | if ($change) { |
|---|
| 50 | // °ì»þ¥«¡¼¥È¤Î¥¯¥ê¥¢ |
|---|
| 51 | unset($_SESSION[$this->key_tmp]); |
|---|
| 52 | $_SESSION[$this->key]['cancel_purchase'] = true; |
|---|
| 53 | } else { |
|---|
| 54 | $_SESSION[$this->key]['cancel_purchase'] = false; |
|---|
| 55 | } |
|---|
| 56 | return $_SESSION[$this->key]['cancel_purchase']; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | // ¼¡¤Ë³ä¤êÅö¤Æ¤ë¥«¡¼¥È¤ÎID¤ò¼èÆÀ¤¹¤ë |
|---|
| 60 | function getNextCartID() { |
|---|
| 61 | $max = count($_SESSION[$this->key]); |
|---|
| 62 | for($i = 0; $i < $max; $i++) { |
|---|
| 63 | $arrRet[] = $_SESSION[$this->key][$i]['cart_no']; |
|---|
| 64 | } |
|---|
| 65 | return (max($arrRet) + 1); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | // ¾¦Éʤ´¤È¤Î¹ç·×²Á³Ê |
|---|
| 69 | function getProductTotal($arrInfo, $id) { |
|---|
| 70 | $max = $this->getMax(); |
|---|
| 71 | for($i = 0; $i <= $max; $i++) { |
|---|
| 72 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 73 | // Àǹþ¤ß¹ç·× |
|---|
| 74 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 75 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 76 | $pre_tax = sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 77 | $total = $pre_tax * $quantity; |
|---|
| 78 | return $total; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | return 0; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | // ÃͤΥ»¥Ã¥È |
|---|
| 85 | function setProductValue($id, $key, $val) { |
|---|
| 86 | $max = $this->getMax(); |
|---|
| 87 | for($i = 0; $i <= $max; $i++) { |
|---|
| 88 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 89 | $_SESSION[$this->key][$i][$key] = $val; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | // ¥«¡¼¥ÈÆâ¾¦ÉʤκÇÂçÍ×ÁÇÈÖ¹æ¤ò¼èÆÀ¤¹¤ë¡£ |
|---|
| 95 | function getMax() { |
|---|
| 96 | $cnt = 0; |
|---|
| 97 | $pos = 0; |
|---|
| 98 | $max = 0; |
|---|
| 99 | if (count($_SESSION[$this->key]) > 0){ |
|---|
| 100 | foreach($_SESSION[$this->key] as $key => $val) { |
|---|
| 101 | if (is_numeric($key)) { |
|---|
| 102 | if($max < $key) { |
|---|
| 103 | $max = $key; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | return ($max); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | // ¥«¡¼¥ÈÆâ¾¦ÉÊ¿ô¤Î¹ç·× |
|---|
| 112 | function getTotalQuantity() { |
|---|
| 113 | $total = 0; |
|---|
| 114 | $max = $this->getMax(); |
|---|
| 115 | for($i = 0; $i <= $max; $i++) { |
|---|
| 116 | $total+= $_SESSION[$this->key][$i]['quantity']; |
|---|
| 117 | } |
|---|
| 118 | return $total; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | // Á´¾¦Éʤιç·×²Á³Ê |
|---|
| 123 | function getAllProductsTotal($arrInfo) { |
|---|
| 124 | // Àǹþ¤ß¹ç·× |
|---|
| 125 | $total = 0; |
|---|
| 126 | $max = $this->getMax(); |
|---|
| 127 | for($i = 0; $i <= $max; $i++) { |
|---|
| 128 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 129 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 130 | $pre_tax = sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 131 | $total+= ($pre_tax * $quantity); |
|---|
| 132 | } |
|---|
| 133 | return $total; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | // Á´¾¦Éʤιç·×ÀǶâ |
|---|
| 137 | function getAllProductsTax($arrInfo) { |
|---|
| 138 | // Àǹç·× |
|---|
| 139 | $total = 0; |
|---|
| 140 | $max = $this->getMax(); |
|---|
| 141 | for($i = 0; $i <= $max; $i++) { |
|---|
| 142 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 143 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 144 | $tax = sfTax($price, $arrInfo['tax'], $arrInfo['tax_rule']); |
|---|
| 145 | $total+= ($tax * $quantity); |
|---|
| 146 | } |
|---|
| 147 | return $total; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // Á´¾¦Éʤιç·×¥Ý¥¤¥ó¥È |
|---|
| 151 | function getAllProductsPoint() { |
|---|
| 152 | // ¥Ý¥¤¥ó¥È¹ç·× |
|---|
| 153 | $total = 0; |
|---|
| 154 | $max = $this->getMax(); |
|---|
| 155 | for($i = 0; $i <= $max; $i++) { |
|---|
| 156 | $price = $_SESSION[$this->key][$i]['price']; |
|---|
| 157 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 158 | $point_rate = $_SESSION[$this->key][$i]['point_rate']; |
|---|
| 159 | $id = $_SESSION[$this->key][$i]['id'][0]; |
|---|
| 160 | $point = sfPrePoint($price, $point_rate, POINT_RULE, $id); |
|---|
| 161 | $total+= ($point * $quantity); |
|---|
| 162 | } |
|---|
| 163 | return $total; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // ¥«¡¼¥È¤Ø¤Î¾¦ÉÊÄɲà |
|---|
| 167 | function addProduct($id, $quantity) { |
|---|
| 168 | $find = false; |
|---|
| 169 | $max = $this->getMax(); |
|---|
| 170 | for($i = 0; $i <= $max; $i++) { |
|---|
| 171 | |
|---|
| 172 | if($_SESSION[$this->key][$i]['id'] == $id) { |
|---|
| 173 | $val = $_SESSION[$this->key][$i]['quantity'] + $quantity; |
|---|
| 174 | if(strlen($val) <= INT_LEN) { |
|---|
| 175 | $_SESSION[$this->key][$i]['quantity']+= $quantity; |
|---|
| 176 | } |
|---|
| 177 | $find = true; |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | if(!$find) { |
|---|
| 181 | $_SESSION[$this->key][$max+1]['id'] = $id; |
|---|
| 182 | $_SESSION[$this->key][$max+1]['quantity'] = $quantity; |
|---|
| 183 | $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID(); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | // ¥¡¼¤¬°ìÃפ·¤¿¾¦Éʤκï½ü |
|---|
| 188 | function delProductKey($keyname, $val) { |
|---|
| 189 | $max = count($_SESSION[$this->key]); |
|---|
| 190 | for($i = 0; $i < $max; $i++) { |
|---|
| 191 | if($_SESSION[$this->key][$i][$keyname] == $val) { |
|---|
| 192 | unset($_SESSION[$this->key][$i]); |
|---|
| 193 | } |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | function setValue($key, $val) { |
|---|
| 198 | $_SESSION[$this->key][$key] = $val; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | function getValue($key) { |
|---|
| 202 | return $_SESSION[$this->key][$key]; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | function getCartList() { |
|---|
| 206 | $max = $this->getMax(); |
|---|
| 207 | for($i = 0; $i <= $max; $i++) { |
|---|
| 208 | if($_SESSION[$this->key][$i]['cart_no'] != "") { |
|---|
| 209 | $arrRet[] = $_SESSION[$this->key][$i]; |
|---|
| 210 | } |
|---|
| 211 | } |
|---|
| 212 | return $arrRet; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | // ¥«¡¼¥ÈÆâ¤Ë¤¢¤ë¾¦ÉʣɣĤòÁ´¤Æ¼èÆÀ¤¹¤ë |
|---|
| 216 | function getAllProductID() { |
|---|
| 217 | $max = $this->getMax(); |
|---|
| 218 | for($i = 0; $i <= $max; $i++) { |
|---|
| 219 | if($_SESSION[$this->key][$i]['cart_no'] != "") { |
|---|
| 220 | $arrRet[] = $_SESSION[$this->key][$i]['id'][0]; |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | return $arrRet; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | function delAllProducts() { |
|---|
| 227 | $max = $this->getMax(); |
|---|
| 228 | for($i = 0; $i <= $max; $i++) { |
|---|
| 229 | unset($_SESSION[$this->key][$i]); |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | // ¾¦Éʤκï½ü |
|---|
| 234 | function delProduct($cart_no) { |
|---|
| 235 | $max = $this->getMax(); |
|---|
| 236 | for($i = 0; $i <= $max; $i++) { |
|---|
| 237 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 238 | unset($_SESSION[$this->key][$i]); |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | // ¸Ä¿ô¤ÎÁý²Ã |
|---|
| 244 | function upQuantity($cart_no) { |
|---|
| 245 | $max = $this->getMax(); |
|---|
| 246 | for($i = 0; $i <= $max; $i++) { |
|---|
| 247 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 248 | if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) { |
|---|
| 249 | $_SESSION[$this->key][$i]['quantity']++; |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | // ¸Ä¿ô¤Î¸º¾¯ |
|---|
| 256 | function downQuantity($cart_no) { |
|---|
| 257 | $max = $this->getMax(); |
|---|
| 258 | for($i = 0; $i <= $max; $i++) { |
|---|
| 259 | if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) { |
|---|
| 260 | if($_SESSION[$this->key][$i]['quantity'] > 1) { |
|---|
| 261 | $_SESSION[$this->key][$i]['quantity']--; |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | // Á´¾¦Éʤιç·×Á÷ÎÁ |
|---|
| 268 | function getAllProductsDelivFee() { |
|---|
| 269 | // ¥Ý¥¤¥ó¥È¹ç·× |
|---|
| 270 | $total = 0; |
|---|
| 271 | $max = $this->getMax(); |
|---|
| 272 | for($i = 0; $i <= $max; $i++) { |
|---|
| 273 | $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee']; |
|---|
| 274 | $quantity = $_SESSION[$this->key][$i]['quantity']; |
|---|
| 275 | $total+= ($deliv_fee * $quantity); |
|---|
| 276 | } |
|---|
| 277 | return $total; |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | } |
|---|
| 281 | ?> |
|---|