source: branches/beta/data/class/SC_CartSession.php @ 15056

Revision 15056, 8.6 KB checked in by adati, 17 years ago (diff)

relブランチのマージ(r12156-r15055)

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