source: temp/test-xoops.ec-cube.net/data/class/SC_CartSession.php @ 1142

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