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

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