source: branches/feature-module-update/data/class/SC_CartSession.php @ 16010

Revision 16010, 11.8 KB checked in by nanasess, 19 years ago (diff)

未定義変数の修正

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
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        SC_Utils::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 = isset($_SESSION[$this->key]['cancel_purchase'])
39            ? $_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        foreach($_SESSION[$this->key] as $key => $val){
71            $arrRet[] = $_SESSION[$this->key][$key]['cart_no'];
72        }
73        return (max($arrRet) + 1);
74    }
75
76    // 商品ごとの合計価格
77    function getProductTotal($arrInfo, $id) {
78        $max = $this->getMax();
79        for($i = 0; $i <= $max; $i++) {
80            if(isset($_SESSION[$this->key][$i]['id'])
81               && $_SESSION[$this->key][$i]['id'] == $id) {
82
83                // 税込み合計
84                $price = $_SESSION[$this->key][$i]['price'];
85                $quantity = $_SESSION[$this->key][$i]['quantity'];
86                $pre_tax = SC_Utils_Ex::sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']);
87                $total = $pre_tax * $quantity;
88                return $total;
89            }
90        }
91        return 0;
92    }
93
94    // 値のセット
95    function setProductValue($id, $key, $val) {
96        $max = $this->getMax();
97        for($i = 0; $i <= $max; $i++) {
98            if(isset($_SESSION[$this->key][$i]['id'])
99               && $_SESSION[$this->key][$i]['id'] == $id) {
100                $_SESSION[$this->key][$i][$key] = $val;
101            }
102        }
103    }
104
105    // カート内商品の最大要素番号を取得する。
106    function getMax() {
107        $cnt = 0;
108        $pos = 0;
109        $max = 0;
110        if (count($_SESSION[$this->key]) > 0){
111            foreach($_SESSION[$this->key] as $key => $val) {
112                if (is_numeric($key)) {
113                    if($max < $key) {
114                        $max = $key;
115                    }
116                }
117            }
118        }
119        return ($max);
120    }
121
122    // カート内商品数の合計
123    function getTotalQuantity() {
124        $total = 0;
125        $max = $this->getMax();
126        for($i = 0; $i <= $max; $i++) {
127            $total+= $_SESSION[$this->key][$i]['quantity'];
128        }
129        return $total;
130    }
131
132
133    // 全商品の合計価格
134    function getAllProductsTotal($arrInfo) {
135        // 税込み合計
136        $total = 0;
137        $max = $this->getMax();
138        for($i = 0; $i <= $max; $i++) {
139
140            if (!isset($_SESSION[$this->key][$i]['price'])) {
141                $_SESSION[$this->key][$i]['price'] = "";
142            }
143            $price = $_SESSION[$this->key][$i]['price'];
144
145            if (!isset($_SESSION[$this->key][$i]['quantity'])) {
146                $_SESSION[$this->key][$i]['quantity'] = "";
147            }
148            $quantity = $_SESSION[$this->key][$i]['quantity'];
149
150            $pre_tax = SC_Utils::sfPreTax($price, $arrInfo['tax'], $arrInfo['tax_rule']);
151            $total+= ($pre_tax * $quantity);
152        }
153        return $total;
154    }
155
156    // 全商品の合計税金
157    function getAllProductsTax($arrInfo) {
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            $tax = SC_Utils_Ex::sfTax($price, $arrInfo['tax'], $arrInfo['tax_rule']);
165            $total+= ($tax * $quantity);
166        }
167        return $total;
168    }
169
170    // 全商品の合計ポイント
171    function getAllProductsPoint() {
172        // ポイント合計
173        $total = 0;
174        $max = $this->getMax();
175        for($i = 0; $i <= $max; $i++) {
176            $price = $_SESSION[$this->key][$i]['price'];
177            $quantity = $_SESSION[$this->key][$i]['quantity'];
178
179            if (!isset($_SESSION[$this->key][$i]['point_rate'])) {
180                $_SESSION[$this->key][$i]['point_rate'] = "";
181            }
182            $point_rate = $_SESSION[$this->key][$i]['point_rate'];
183
184            if (!isset($_SESSION[$this->key][$i]['id'][0])) {
185                $_SESSION[$this->key][$i]['id'][0] = "";
186            }
187            $id = $_SESSION[$this->key][$i]['id'][0];
188            $point = SC_Utils_Ex::sfPrePoint($price, $point_rate, POINT_RULE, $id);
189            $total+= ($point * $quantity);
190        }
191        return $total;
192    }
193
194    // カートへの商品追加
195    function addProduct($id, $quantity, $campaign_id = "") {
196        $find = false;
197        $max = $this->getMax();
198        for($i = 0; $i <= $max; $i++) {
199
200            if($_SESSION[$this->key][$i]['id'] == $id) {
201                $val = $_SESSION[$this->key][$i]['quantity'] + $quantity;
202                if(strlen($val) <= INT_LEN) {
203                    $_SESSION[$this->key][$i]['quantity']+= $quantity;
204                    if(!empty($campaign_id)){
205                        $_SESSION[$this->key][$i]['campaign_id'] = $campaign_id;
206                        $_SESSION[$this->key][$i]['is_campaign'] = true;
207                    }
208                }
209                $find = true;
210            }
211        }
212        if(!$find) {
213            $_SESSION[$this->key][$max+1]['id'] = $id;
214            $_SESSION[$this->key][$max+1]['quantity'] = $quantity;
215            $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID();
216            if(!empty($campaign_id)){
217                $_SESSION[$this->key][$max+1]['campaign_id'] = $campaign_id;
218                $_SESSION[$this->key][$max+1]['is_campaign'] = true;
219            }
220        }
221    }
222
223    // 前頁のURLを記録しておく
224    function setPrevURL($url) {
225        // 前頁として記録しないページを指定する。
226        $arrExclude = array(
227            "detail_image.php",
228            "/shopping/"
229        );
230        $exclude = false;
231        // ページチェックを行う。
232        foreach($arrExclude as $val) {
233            if(ereg($val, $url)) {
234                $exclude = true;
235                break;
236            }
237        }
238        // 除外ページでない場合は、前頁として記録する。
239        if(!$exclude) {
240            $_SESSION[$this->key]['prev_url'] = $url;
241        }
242    }
243
244    // 前頁のURLを取得する
245    function getPrevURL() {
246        return isset($_SESSION[$this->key]['prev_url'])
247            ? $_SESSION[$this->key]['prev_url'] : "";
248    }
249
250    // キーが一致した商品の削除
251    function delProductKey($keyname, $val) {
252        $max = count($_SESSION[$this->key]);
253        for($i = 0; $i < $max; $i++) {
254            if($_SESSION[$this->key][$i][$keyname] == $val) {
255                unset($_SESSION[$this->key][$i]);
256            }
257        }
258    }
259
260    function setValue($key, $val) {
261        $_SESSION[$this->key][$key] = $val;
262    }
263
264    function getValue($key) {
265        return $_SESSION[$this->key][$key];
266    }
267
268    function getCartList() {
269        $max = $this->getMax();
270        $arrRet = array();
271        for($i = 0; $i <= $max; $i++) {
272            if(isset($_SESSION[$this->key][$i]['cart_no'])
273               && $_SESSION[$this->key][$i]['cart_no'] != "") {
274                $arrRet[] = $_SESSION[$this->key][$i];
275            }
276        }
277        return $arrRet;
278    }
279
280    // カート内にある商品IDを全て取得する
281    function getAllProductID() {
282        $max = $this->getMax();
283        for($i = 0; $i <= $max; $i++) {
284            if($_SESSION[$this->key][$i]['cart_no'] != "") {
285                $arrRet[] = $_SESSION[$this->key][$i]['id'][0];
286            }
287        }
288        return $arrRet;
289    }
290
291    function delAllProducts() {
292        $max = $this->getMax();
293        for($i = 0; $i <= $max; $i++) {
294            unset($_SESSION[$this->key][$i]);
295        }
296    }
297
298    // 商品の削除
299    function delProduct($cart_no) {
300        $max = $this->getMax();
301        for($i = 0; $i <= $max; $i++) {
302            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
303                unset($_SESSION[$this->key][$i]);
304            }
305        }
306    }
307
308    // 個数の増加
309    function upQuantity($cart_no) {
310        $max = $this->getMax();
311        for($i = 0; $i <= $max; $i++) {
312            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
313                if(strlen($_SESSION[$this->key][$i]['quantity'] + 1) <= INT_LEN) {
314                    $_SESSION[$this->key][$i]['quantity']++;
315                }
316            }
317        }
318    }
319
320    // 個数の減少
321    function downQuantity($cart_no) {
322        $max = $this->getMax();
323        for($i = 0; $i <= $max; $i++) {
324            if($_SESSION[$this->key][$i]['cart_no'] == $cart_no) {
325                if($_SESSION[$this->key][$i]['quantity'] > 1) {
326                    $_SESSION[$this->key][$i]['quantity']--;
327                }
328            }
329        }
330    }
331
332    // 全商品の合計送料
333    function getAllProductsDelivFee() {
334        // ポイント合計
335        $total = 0;
336        $max = $this->getMax();
337        for($i = 0; $i <= $max; $i++) {
338            $deliv_fee = $_SESSION[$this->key][$i]['deliv_fee'];
339            $quantity = $_SESSION[$this->key][$i]['quantity'];
340            $total+= ($deliv_fee * $quantity);
341        }
342        return $total;
343    }
344
345    // カートの中の売り切れチェック
346    function chkSoldOut($arrCartList, $is_mobile = false){
347        foreach($arrCartList as $key => $val){
348            if($val['quantity'] == 0){
349                // 売り切れ商品をカートから削除する
350                $this->delProduct($val['cart_no']);
351                sfDispSiteError(SOLD_OUT, "", true, "", $is_mobile);
352            }
353        }
354    }
355
356    /**
357     * カートの中のキャンペーン商品のチェック
358     * @param integer $campaign_id キャンペーンID
359     * @return boolean True:キャンペーン商品有り False:キャンペーン商品無し
360     */
361    function chkCampaign($campaign_id){
362        $max = $this->getMax();
363        for($i = 0; $i <= $max; $i++) {
364            if($_SESSION[$this->key][$i]['is_campaign'] and $_SESSION[$this->key][$i]['campaign_id'] == $campaign_id) return true;
365        }
366
367        return false;
368    }
369
370}
371?>
Note: See TracBrowser for help on using the repository browser.