source: temp/trunk/data/class/SC_CartSession.php @ 8420

Revision 8420, 7.4 KB checked in by kakinaka, 20 years ago (diff)

blank

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