source: branches/version-2_11-dev/data/class/SC_CartSession.php @ 21191

Revision 21191, 25.8 KB checked in by shutta, 13 years ago (diff)

refs #1341 (MySQLでSESSIONをDB保存する際の型がTEXT型なのでデータ量によってはあふれる)
セッション中の商品情報から、不要なデータを削除するように修正。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * カートセッション管理クラス
26 *
27 * @author LOCKON CO.,LTD.
28 * @version $Id$
29 */
30class SC_CartSession {
31    /** ユニークIDを指定する. */
32    var $key_tmp;
33
34    /** カートのセッション変数. */
35    var $cartSession;
36
37    /* コンストラクタ */
38    function SC_CartSession($cartKey = 'cart') {
39        if (!isset($_SESSION[$cartKey])) {
40            $_SESSION[$cartKey] = array();
41        }
42        $this->cartSession =& $_SESSION[$cartKey];
43    }
44
45    // 商品購入処理中のロック
46    function saveCurrentCart($key_tmp, $productTypeId) {
47        $this->key_tmp = "savecart_" . $key_tmp;
48        // すでに情報がなければ現状のカート情報を記録しておく
49        if(count($_SESSION[$this->key_tmp]) == 0) {
50            $_SESSION[$this->key_tmp] = $this->cartSession[$productTypeId];
51        }
52        // 1世代古いコピー情報は、削除しておく
53        foreach($_SESSION as $k => $val) {
54            if($k != $this->key_tmp && preg_match("/^savecart_/", $k)) {
55                unset($this->cartSession[$productTypeId][$k]);
56            }
57        }
58    }
59
60    // 商品購入中の変更があったかをチェックする。
61    function getCancelPurchase($productTypeId) {
62        $ret = isset($this->cartSession[$productTypeId]['cancel_purchase'])
63            ? $this->cartSession[$productTypeId]['cancel_purchase'] : "";
64        $this->cartSession[$productTypeId]['cancel_purchase'] = false;
65        return $ret;
66    }
67
68    // 購入処理中に商品に変更がなかったかを判定
69    function checkChangeCart($productTypeId) {
70        $change = false;
71        $max = $this->getMax($productTypeId);
72        for($i = 1; $i <= $max; $i++) {
73            if ($this->cartSession[$productTypeId][$i]['quantity']
74                != $_SESSION[$this->key_tmp][$i]['quantity']) {
75
76                $change = true;
77                break;
78            }
79            if ($this->cartSession[$productTypeId][$i]['id']
80                != $_SESSION[$this->key_tmp][$i]['id']) {
81
82                $change = true;
83                break;
84            }
85        }
86        if ($change) {
87            // 一時カートのクリア
88            unset($_SESSION[$this->key_tmp]);
89            $this->cartSession[$productTypeId][$key]['cancel_purchase'] = true;
90        } else {
91            $this->cartSession[$productTypeId]['cancel_purchase'] = false;
92        }
93        return $this->cartSession[$productTypeId]['cancel_purchase'];
94    }
95
96    // 次に割り当てるカートのIDを取得する
97    function getNextCartID($productTypeId) {
98        foreach($this->cartSession[$productTypeId] as $key => $val){
99            $arrRet[] = $this->cartSession[$productTypeId][$key]['cart_no'];
100        }
101        return max($arrRet) + 1;
102    }
103
104    /**
105     * 商品ごとの合計価格
106     * XXX 実際には、「商品」ではなく、「カートの明細行(≒商品規格)」のような気がします。
107     *
108     * @param integer $id
109     * @return string 商品ごとの合計価格(税込み)
110     * @deprecated SC_CartSession::getCartList() を使用してください
111     */
112    function getProductTotal($id, $productTypeId) {
113        $max = $this->getMax($productTypeId);
114        for($i = 0; $i <= $max; $i++) {
115            if(isset($this->cartSession[$productTypeId][$i]['id'])
116               && $this->cartSession[$productTypeId][$i]['id'] == $id) {
117
118                // 税込み合計
119                $price = $this->cartSession[$productTypeId][$i]['price'];
120                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
121                $incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
122                $total = $incTax * $quantity;
123                return $total;
124            }
125        }
126        return 0;
127    }
128
129    // 値のセット
130    function setProductValue($id, $key, $val, $productTypeId) {
131        $max = $this->getMax($productTypeId);
132        for($i = 0; $i <= $max; $i++) {
133            if(isset($this->cartSession[$productTypeId][$i]['id'])
134               && $this->cartSession[$productTypeId][$i]['id'] == $id) {
135                $this->cartSession[$productTypeId][$i][$key] = $val;
136            }
137        }
138    }
139
140    // カート内商品の最大要素番号を取得する。
141    function getMax($productTypeId) {
142        $max = 0;
143        if (count($this->cartSession[$productTypeId]) > 0){
144            foreach($this->cartSession[$productTypeId] as $key => $val) {
145                if (is_numeric($key)) {
146                    if($max < $key) {
147                        $max = $key;
148                    }
149                }
150            }
151        }
152        return $max;
153    }
154
155    // カート内商品数量の合計
156    function getTotalQuantity($productTypeId) {
157        $total = 0;
158        $max = $this->getMax($productTypeId);
159        for($i = 0; $i <= $max; $i++) {
160            $total+= $this->cartSession[$productTypeId][$i]['quantity'];
161        }
162        return $total;
163    }
164
165    // 全商品の合計価格
166    function getAllProductsTotal($productTypeId) {
167        // 税込み合計
168        $total = 0;
169        $max = $this->getMax($productTypeId);
170        for($i = 0; $i <= $max; $i++) {
171
172            if (!isset($this->cartSession[$productTypeId][$i]['price'])) {
173                $this->cartSession[$productTypeId][$i]['price'] = "";
174            }
175
176            $price = $this->cartSession[$productTypeId][$i]['price'];
177
178            if (!isset($this->cartSession[$productTypeId][$i]['quantity'])) {
179                $this->cartSession[$productTypeId][$i]['quantity'] = "";
180            }
181            $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
182
183            $incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
184            $total+= ($incTax * $quantity);
185        }
186        return $total;
187    }
188
189    // 全商品の合計税金
190    function getAllProductsTax($productTypeId) {
191        // 税合計
192        $total = 0;
193        $max = $this->getMax($productTypeId);
194        for($i = 0; $i <= $max; $i++) {
195            $price = $this->cartSession[$productTypeId][$i]['price'];
196            $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
197            $tax = SC_Helper_DB_Ex::sfTax($price);
198            $total+= ($tax * $quantity);
199        }
200        return $total;
201    }
202
203    // 全商品の合計ポイント
204    function getAllProductsPoint($productTypeId) {
205        // ポイント合計
206        $total = 0;
207        if (USE_POINT !== false) {
208            $max = $this->getMax($productTypeId);
209            for($i = 0; $i <= $max; $i++) {
210                $price = $this->cartSession[$productTypeId][$i]['price'];
211                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
212
213                if (!isset($this->cartSession[$productTypeId][$i]['point_rate'])) {
214                    $this->cartSession[$productTypeId][$i]['point_rate'] = "";
215                }
216                $point_rate = $this->cartSession[$productTypeId][$i]['point_rate'];
217
218                if (!isset($this->cartSession[$productTypeId][$i]['id'][0])) {
219                    $this->cartSession[$productTypeId][$i]['id'][0] = "";
220                }
221                $point = SC_Utils_Ex::sfPrePoint($price, $point_rate);
222                $total+= ($point * $quantity);
223            }
224        }
225        return $total;
226    }
227
228    // カートへの商品追加
229    function addProduct($product_class_id, $quantity) {
230        $objProduct = new SC_Product_Ex();
231        $arrProduct = $objProduct->getProductsClass($product_class_id);
232        $productTypeId = $arrProduct['product_type_id'];
233        $find = false;
234        $max = $this->getMax($productTypeId);
235        for($i = 0; $i <= $max; $i++) {
236
237            if($this->cartSession[$productTypeId][$i]['id'] == $product_class_id) {
238                $val = $this->cartSession[$productTypeId][$i]['quantity'] + $quantity;
239                if(strlen($val) <= INT_LEN) {
240                    $this->cartSession[$productTypeId][$i]['quantity'] += $quantity;
241                }
242                $find = true;
243            }
244        }
245        if(!$find) {
246            $this->cartSession[$productTypeId][$max+1]['id'] = $product_class_id;
247            $this->cartSession[$productTypeId][$max+1]['quantity'] = $quantity;
248            $this->cartSession[$productTypeId][$max+1]['cart_no'] = $this->getNextCartID($productTypeId);
249        }
250    }
251
252    // 前頁のURLを記録しておく
253    function setPrevURL($url, $excludePaths = array()) {
254        // 前頁として記録しないページを指定する。
255        $arrExclude = array(
256            "/shopping/"
257        );
258        $arrExclude = array_merge($arrExclude, $excludePaths);
259        $exclude = false;
260        // ページチェックを行う。
261        foreach($arrExclude as $val) {
262            if(preg_match("|" . preg_quote($val) . "|", $url)) {
263                $exclude = true;
264                break;
265            }
266        }
267        // 除外ページでない場合は、前頁として記録する。
268        if(!$exclude) {
269            $_SESSION['prev_url'] = $url;
270        }
271    }
272
273    // 前頁のURLを取得する
274    function getPrevURL() {
275        return isset($_SESSION['prev_url']) ? $_SESSION['prev_url'] : "";
276    }
277
278    // キーが一致した商品の削除
279    function delProductKey($keyname, $val, $productTypeId) {
280        $max = count($this->cartSession[$productTypeId]);
281        for($i = 0; $i < $max; $i++) {
282            if($this->cartSession[$productTypeId][$i][$keyname] == $val) {
283                unset($this->cartSession[$productTypeId][$i]);
284            }
285        }
286    }
287
288    function setValue($key, $val, $productTypeId) {
289        $this->cartSession[$productTypeId][$key] = $val;
290    }
291
292    function getValue($key, $productTypeId) {
293        return $this->cartSession[$productTypeId][$key];
294    }
295
296    /**
297     * セッション中の商品情報データの調整。
298     * productsClass項目から、不必要な項目を削除する。
299     */
300    function adjustSessionProductsClass(&$arrProductsClass) {
301        $arrNecessaryItems = array(
302            'product_id'        => true,
303            'product_class_id'  => true,
304            'name'              => true,
305            'price02'           => true,
306            'point_rate'        => true,
307            'main_list_image'   => true,
308            'main_image'        => true,
309            'product_code'      => true,
310            'stock'             => true,
311            'stock_unlimited'   => true,
312            'sale_limit'        => true,
313        );
314
315        // 必要な項目以外を削除。
316        foreach (array_keys($arrProductsClass) as $key) {
317            if (!isset($arrNecessaryItems[$key])) {
318                unset($arrProductsClass[$key]);
319            }
320        }
321    }
322
323    /**
324     * 商品種別ごとにカート内商品の一覧を取得する.
325     *
326     * @param integer $productTypeId 商品種別ID
327     * @return array カート内商品一覧の配列
328     */
329    function getCartList($productTypeId) {
330        $objProduct = new SC_Product_Ex();
331        $max = $this->getMax($productTypeId);
332        $arrRet = array();
333        for($i = 0; $i <= $max; $i++) {
334            if(isset($this->cartSession[$productTypeId][$i]['cart_no'])
335               && $this->cartSession[$productTypeId][$i]['cart_no'] != "") {
336
337                // 商品情報は常に取得
338                $this->cartSession[$productTypeId][$i]['productsClass'] =&
339                        $objProduct->getDetailAndProductsClass(
340                                    $this->cartSession[$productTypeId][$i]['id']);
341
342                $this->adjustSessionProductsClass($this->cartSession[$productTypeId][$i]['productsClass']);
343
344                $price = $this->cartSession[$productTypeId][$i]['productsClass']['price02'];
345                $this->cartSession[$productTypeId][$i]['price'] = $price;
346
347                $this->cartSession[$productTypeId][$i]['point_rate'] =
348                    $this->cartSession[$productTypeId][$i]['productsClass']['point_rate'];
349
350                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
351                $incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
352                $total = $incTax * $quantity;
353
354                $this->cartSession[$productTypeId][$i]['total_inctax'] = $total;
355
356                $arrRet[] =& $this->cartSession[$productTypeId][$i];
357            }
358        }
359        return $arrRet;
360    }
361
362    /**
363     * すべてのカートの内容を取得する.
364     *
365     * @return array すべてのカートの内容
366     */
367    function getAllCartList() {
368        $results = array();
369        $cartKeys = $this->getKeys();
370        $i = 0;
371        foreach ($cartKeys as $key) {
372            $cartItems = $this->getCartList($key);
373            foreach (array_keys($cartItems) as $itemKey) {
374                $cartItem =& $cartItems[$itemKey];
375                $results[$key][$i] =& $cartItem;
376                $i++;
377            }
378        }
379        return $results;
380    }
381
382    // カート内にある商品IDを全て取得する
383    /**
384     * @deprected getAllProductClassID を使用して下さい
385     */
386    function getAllProductID($productTypeId) {
387        $max = $this->getMax($productTypeId);
388        for($i = 0; $i <= $max; $i++) {
389            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
390                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'][0];
391            }
392        }
393        return $arrRet;
394    }
395
396    /**
397     * カート内にある商品規格IDを全て取得する.
398     *
399     * @param integer $productTypeId 商品種別ID
400     * @return array 商品規格ID の配列
401     */
402    function getAllProductClassID($productTypeId) {
403        $max = $this->getMax($productTypeId);
404        for($i = 0; $i <= $max; $i++) {
405            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
406                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'];
407            }
408        }
409        return $arrRet;
410    }
411
412    /**
413     * 商品種別ID を指定して, カート内の商品をすべて削除する.
414     *
415     * @param integer $productTypeId 商品種別ID
416     * @return void
417     */
418    function delAllProducts($productTypeId) {
419        $max = $this->getMax($productTypeId);
420        for($i = 0; $i <= $max; $i++) {
421            unset($this->cartSession[$productTypeId][$i]);
422        }
423    }
424
425    // 商品の削除
426    function delProduct($cart_no, $productTypeId) {
427        $max = $this->getMax($productTypeId);
428        for($i = 0; $i <= $max; $i++) {
429            if($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
430                unset($this->cartSession[$productTypeId][$i]);
431            }
432        }
433    }
434
435    // 数量の増加
436    function upQuantity($cart_no, $productTypeId) {
437        $quantity = $this->getQuantity($cart_no, $productTypeId);
438        if (strlen($quantity + 1) <= INT_LEN) {
439            $this->setQuantity($quantity + 1, $cart_no, $productTypeId);
440        }
441    }
442
443    // 数量の減少
444    function downQuantity($cart_no, $productTypeId) {
445        $quantity = $this->getQuantity($cart_no, $productTypeId);
446        if ($quantity > 1) {
447            $this->setQuantity($quantity - 1, $cart_no, $productTypeId);
448        }
449    }
450
451    /**
452     * カート番号と商品種別IDを指定して, 数量を取得する.
453     *
454     * @param integer $cart_no カート番号
455     * @param integer $productTypeId 商品種別ID
456     * @return integer 該当商品規格の数量
457     */
458    function getQuantity($cart_no, $productTypeId) {
459        $max = $this->getMax($productTypeId);
460        for ($i = 0; $i <= $max; $i++) {
461            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
462                return $this->cartSession[$productTypeId][$i]['quantity'];
463            }
464        }
465    }
466
467    /**
468     * カート番号と商品種別IDを指定して, 数量を設定する.
469     *
470     * @param integer $quantity 設定する数量
471     * @param integer $cart_no カート番号
472     * @param integer $productTypeId 商品種別ID
473     * @retrun void
474     */
475    function setQuantity($quantity, $cart_no, $productTypeId) {
476        $max = $this->getMax($productTypeId);
477        for ($i = 0; $i <= $max; $i++) {
478            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
479                $this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
480            }
481        }
482    }
483
484    /**
485     * カート番号と商品種別IDを指定して, 商品規格IDを取得する.
486     *
487     * @param integer $cart_no カート番号
488     * @param integer $productTypeId 商品種別ID
489     * @return integer 商品規格ID
490     */
491    function getProductClassId($cart_no, $productTypeId) {
492        for ($i = 0; $i <= $max; $i++) {
493            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
494                return $this->cartSession[$productTypeId][$i]['id'];
495            }
496        }
497    }
498
499    /**
500     * カート内の商品の妥当性をチェックする.
501     *
502     * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
503     * エラーメッセージを返す.
504     *
505     * 1. 商品種別に関連づけられた配送業者の存在チェック
506     * 2. 削除/非表示商品のチェック
507     * 3. 商品購入制限数のチェック
508     * 4. 在庫数チェック
509     *
510     * @param string $key 商品種別ID
511     * @return string エラーが発生した場合はエラーメッセージ
512     */
513    function checkProducts($productTypeId) {
514        $objProduct = new SC_Product_Ex();
515        $tpl_message = "";
516
517        // カート内の情報を取得
518        $items = $this->getCartList($productTypeId);
519        foreach (array_keys($items) as $key) {
520            $item =& $items[$key];
521            $product =& $item['productsClass'];
522
523            /*
524             * 配送業者のチェック
525             */
526            $arrDeliv = SC_Helper_Purchase_Ex::getDeliv($productTypeId);
527            if (SC_Utils_Ex::isBlank($arrDeliv)) {
528                $tpl_message .= "※「" . $product['name'] . "」はまだ配送の準備ができておりません。恐れ入りますがお問い合わせページよりお問い合わせください。\n";
529            }
530
531            /*
532             * 表示/非表示商品のチェック
533             */
534            if (SC_Utils_Ex::isBlank($product)) {
535                $this->delProduct($item['cart_no'], $productTypeId);
536                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
537            }
538
539            /*
540             * 商品購入制限数, 在庫数のチェック
541             */
542            $limit = $objProduct->getBuyLimit($product);
543            if (!is_null($limit) && $item['quantity'] > $limit) {
544                if ($limit > 0) {
545                    $this->setProductValue($item['id'], 'quantity', $limit, $productTypeId);
546                    $this->setProductValue($item['id'], 'total_inctax', SC_Helper_DB_Ex::sfCalcIncTax($item['price']) * $limit, $productTypeId);
547                    $tpl_message .= "※「" . $product['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n";
548                } else {
549                    $this->delProduct($item['cart_no'], $productTypeId);
550                    $tpl_message .= "※「" . $product['name'] . "」は売り切れました。\n";
551                    continue;
552                }
553            }
554        }
555        return $tpl_message;
556    }
557
558    /**
559     * 送料無料条件を満たすかどうかチェックする
560     *
561     * @param integer $productTypeId 商品種別ID
562     * @return boolean 送料無料の場合 true
563     */
564    function isDelivFree($productTypeId) {
565        $objDb = new SC_Helper_DB_Ex();
566
567        $subtotal = $this->getAllProductsTotal($productTypeId);
568
569        // 送料無料の購入数が設定されている場合
570        if (DELIV_FREE_AMOUNT > 0) {
571            // 商品の合計数量
572            $total_quantity = $this->getTotalQuantity($productTypeId);
573
574            if($total_quantity >= DELIV_FREE_AMOUNT) {
575                return true;
576            }
577        }
578
579        // 送料無料条件が設定されている場合
580        $arrInfo = $objDb->sfGetBasisData();
581        if ($arrInfo['free_rule'] > 0) {
582            // 小計が無料条件を超えている場合
583            if($subtotal >= $arrInfo['free_rule']) {
584                return true;
585            }
586        }
587
588        return false;
589    }
590
591    /**
592     * カートの内容を計算する.
593     *
594     * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
595     *
596     * - tax: 税額
597     * - subtotal: カート内商品の小計
598     * - deliv_fee: カート内商品の合計送料
599     * - total: 合計金額
600     * - payment_total: お支払い合計
601     * - add_point: 加算ポイント
602     *
603     * @param integer $productTypeId 商品種別ID
604     * @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
605     * @param integer $use_point 今回使用ポイント
606     * @param integer|array $deliv_pref 配送先都道府県ID.
607                                        複数に配送する場合は都道府県IDの配列
608     * @param integer $charge 手数料
609     * @param integer $discount 値引
610     * @param integer $deliv_id 配送業者ID
611     * @return array カートの計算結果の配列
612     */
613    function calculate($productTypeId, &$objCustomer, $use_point = 0,
614                       $deliv_pref = "", $charge = 0, $discount = 0, $deliv_id = 0) {
615        $objDb = new SC_Helper_DB_Ex();
616
617        $total_point = $this->getAllProductsPoint($productTypeId);
618        $results['tax'] = $this->getAllProductsTax($productTypeId);
619        $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
620        $results['deliv_fee'] = 0;
621
622        // 商品ごとの送料を加算
623        if (OPTION_PRODUCT_DELIV_FEE == 1) {
624            $cartItems = $this->getCartList($productTypeId);
625            foreach ($cartItems as $item) {
626                $results['deliv_fee'] += $item['productsClass']['deliv_fee'] * $item['quantity'];
627            }
628        }
629
630        // 配送業者の送料を加算
631        if (OPTION_DELIV_FEE == 1
632            && !SC_Utils_Ex::isBlank($deliv_pref)
633            && !SC_Utils_Ex::isBlank($deliv_id)) {
634            $results['deliv_fee'] += $objDb->sfGetDelivFee($deliv_pref, $deliv_id);
635        }
636
637        // 送料無料チェック
638        if ($this->isDelivFree($productTypeId)) {
639            $results['deliv_fee'] = 0;
640        }
641
642        // 合計を計算
643        $results['total'] = $results['subtotal'];
644        $results['total'] += $results['deliv_fee'];
645        $results['total'] += $charge;
646        $results['total'] -= $discount;
647
648        // お支払い合計
649        $results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
650
651        // 加算ポイントの計算
652        if (USE_POINT !== false) {
653            $results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point,
654                                                                   $use_point);
655            if($objCustomer != "") {
656                // 誕生日月であった場合
657                if($objCustomer->isBirthMonth()) {
658                    $results['birth_point'] = BIRTH_MONTH_POINT;
659                    $results['add_point'] += $results['birth_point'];
660                }
661            }
662            if($results['add_point'] < 0) {
663                $results['add_point'] = 0;
664            }
665        }
666        return $results;
667    }
668
669    /**
670     * カートが保持するキー(商品種別ID)を配列で返す.
671     *
672     * @return array 商品種別IDの配列
673     */
674    function getKeys() {
675        $keys = array_keys($this->cartSession);
676        // 数量が 0 の商品種別は削除する
677        foreach ($keys as $key) {
678            $quantity = $this->getTotalQuantity($key);
679            if ($quantity < 1) {
680                unset($this->cartSession[$key]);
681            }
682        }
683        return array_keys($this->cartSession);
684    }
685
686    /**
687     * カートに設定された現在のキー(商品種別ID)を登録する.
688     *
689     * @param integer $key 商品種別ID
690     * @return void
691     */
692    function registerKey($key) {
693        $_SESSION['cartKey'] = $key;
694    }
695
696    /**
697     * カートに設定された現在のキー(商品種別ID)を削除する.
698     *
699     * @return void
700     */
701    function unsetKey() {
702        unset($_SESSION['cartKey']);
703    }
704
705    /**
706     * カートに設定された現在のキー(商品種別ID)を取得する.
707     *
708     * @return integer 商品種別ID
709     */
710    function getKey() {
711        return $_SESSION['cartKey'];
712    }
713
714    /**
715     * 複数配送扱いかどうか.
716     *
717     * @return boolean カートが複数配送扱いの場合 true
718     */
719    function isMultiple() {
720        return count($this->getKeys()) > 1;
721    }
722
723    /**
724     * 引数の商品種別の商品がカートに含まれるかどうか.
725     *
726     * @param integer $product_type_id 商品種別ID
727     * @return boolean 指定の商品種別がカートに含まれる場合 true
728     */
729    function hasProductType($product_type_id) {
730        return in_array($product_type_id, $this->getKeys());
731    }
732}
733?>
Note: See TracBrowser for help on using the repository browser.