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

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