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

Revision 6685, 7.1 KB checked in by kakinaka, 20 years ago (diff)

* empty log message *

  • 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    // ¥­¡¼¤¬°ìÃפ·¤¿¾¦Éʤκï½ü
194    function delProductKey($keyname, $val) {
195        $max = count($_SESSION[$this->key]);
196        for($i = 0; $i < $max; $i++) {
197            if($_SESSION[$this->key][$i][$keyname] == $val) {
198                unset($_SESSION[$this->key][$i]);
199            }
200        }
201    }
202   
203    function setValue($key, $val) {
204        $_SESSION[$this->key][$key] = $val;
205    }
206   
207    function getValue($key) {
208        return $_SESSION[$this->key][$key];
209    }
210   
211    function getCartList() {
212        $max = $this->getMax();
213        for($i = 0; $i <= $max; $i++) {
214            if($_SESSION[$this->key][$i]['cart_no'] != "") {
215                $arrRet[] = $_SESSION[$this->key][$i];
216            }
217        }
218        return $arrRet;
219    }
220   
221    // ¥«¡¼¥ÈÆâ¤Ë¤¢¤ë¾¦ÉʣɣĤòÁ´¤Æ¼èÆÀ¤¹¤ë
222    function getAllProductID() {
223        $max = $this->getMax();
224        for($i = 0; $i <= $max; $i++) {
225            if($_SESSION[$this->key][$i]['cart_no'] != "") {
226                $arrRet[] = $_SESSION[$this->key][$i]['id'][0];
227            }
228        }
229        return $arrRet;
230    }
231   
232    function delAllProducts() {
233        $max = $this->getMax();
234        for($i = 0; $i <= $max; $i++) {
235            unset($_SESSION[$this->key][$i]);
236        }
237    }
238   
239    // ¾¦Éʤκï½ü
240    function delProduct($cart_no) {
241        $max = $this->getMax();
242        for($i = 0; $i <= $max; $i++) {
243            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
244                unset($_SESSION[$this->key][$i]);
245            }
246        }
247    }
248   
249    // ¸Ä¿ô¤ÎÁý²Ã
250    function upQuantity($cart_no) {
251        $max = $this->getMax();
252        for($i = 0; $i <= $max; $i++) {
253            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
254                if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) {
255                    $_SESSION[$this->key][$i]['quantity']++;
256                }
257            }
258        }
259    }
260   
261    // ¸Ä¿ô¤Î¸º¾¯
262    function downQuantity($cart_no) {
263        $max = $this->getMax();
264        for($i = 0; $i <= $max; $i++) {
265            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
266                if($_SESSION[$this->key][$i]['quantity'] > 1) {
267                    $_SESSION[$this->key][$i]['quantity']--;
268                }
269            }
270        }
271    }
272   
273    // Á´¾¦Éʤιç·×Á÷ÎÁ
274    function getAllProductsDelivFee() {
275        // ¥Ý¥¤¥ó¥È¹ç·×
276        $total = 0;
277        $max = $this->getMax();
278        for($i = 0; $i <= $max; $i++) {
279            $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee'];
280            $quantity = $_SESSION[$this->key][$i]['quantity'];
281            $total+= ($deliv_fee * $quantity);
282        }
283        return $total;
284    }
285   
286    // ¥«¡¼¥È¤ÎÃæ¤ÎÇä¤êÀÚ¤ì¥Á¥§¥Ã¥¯
287    function chkSoldOut($arrCartList){
288        foreach($arrCartList as $key => $val){
289            if($val['quantity'] == 0){
290                // Çä¤êÀڤ쾦Éʤò¥«¡¼¥È¤«¤éºï½ü¤¹¤ë
291                $this->delProduct($val['cart_no']);
292                sfDispSiteError(SOLD_OUT, "", true);
293            }
294        }
295    }
296   
297}
298?>
Note: See TracBrowser for help on using the repository browser.