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

Revision 15369, 11.6 KB checked in by nanasess, 17 years ago (diff)

未定義変数の修正

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