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

Revision 21001, 24.8 KB checked in by shutta, 13 years ago (diff)

refs #1383 (Myページ>現在のカゴの中 商品の小計額計算で購入制限が効いていない)

  • 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     *
299     * @param integer $productTypeId 商品種別ID
300     * @return array カート内商品一覧の配列
301     */
302    function getCartList($productTypeId) {
303        $objProduct = new SC_Product_Ex();
304        $max = $this->getMax($productTypeId);
305        $arrRet = array();
306        for($i = 0; $i <= $max; $i++) {
307            if(isset($this->cartSession[$productTypeId][$i]['cart_no'])
308               && $this->cartSession[$productTypeId][$i]['cart_no'] != "") {
309
310                // 商品情報は常に取得
311                $this->cartSession[$productTypeId][$i]['productsClass'] =&
312                        $objProduct->getDetailAndProductsClass(
313                                    $this->cartSession[$productTypeId][$i]['id']);
314
315                $price = $this->cartSession[$productTypeId][$i]['productsClass']['price02'];
316                $this->cartSession[$productTypeId][$i]['price'] = $price;
317
318                $this->cartSession[$productTypeId][$i]['point_rate'] =
319                    $this->cartSession[$productTypeId][$i]['productsClass']['point_rate'];
320
321                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
322                $incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
323                $total = $incTax * $quantity;
324
325                $this->cartSession[$productTypeId][$i]['total_inctax'] = $total;
326
327                $arrRet[] =& $this->cartSession[$productTypeId][$i];
328            }
329        }
330        return $arrRet;
331    }
332
333    /**
334     * すべてのカートの内容を取得する.
335     *
336     * @return array すべてのカートの内容
337     */
338    function getAllCartList() {
339        $results = array();
340        $cartKeys = $this->getKeys();
341        $i = 0;
342        foreach ($cartKeys as $key) {
343            $cartItems = $this->getCartList($key);
344            foreach (array_keys($cartItems) as $itemKey) {
345                $cartItem =& $cartItems[$itemKey];
346                $results[$key][$i] =& $cartItem;
347                $i++;
348            }
349        }
350        return $results;
351    }
352
353    // カート内にある商品IDを全て取得する
354    /**
355     * @deprected getAllProductClassID を使用して下さい
356     */
357    function getAllProductID($productTypeId) {
358        $max = $this->getMax($productTypeId);
359        for($i = 0; $i <= $max; $i++) {
360            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
361                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'][0];
362            }
363        }
364        return $arrRet;
365    }
366
367    /**
368     * カート内にある商品規格IDを全て取得する.
369     *
370     * @param integer $productTypeId 商品種別ID
371     * @return array 商品規格ID の配列
372     */
373    function getAllProductClassID($productTypeId) {
374        $max = $this->getMax($productTypeId);
375        for($i = 0; $i <= $max; $i++) {
376            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
377                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'];
378            }
379        }
380        return $arrRet;
381    }
382
383    /**
384     * 商品種別ID を指定して, カート内の商品をすべて削除する.
385     *
386     * @param integer $productTypeId 商品種別ID
387     * @return void
388     */
389    function delAllProducts($productTypeId) {
390        $max = $this->getMax($productTypeId);
391        for($i = 0; $i <= $max; $i++) {
392            unset($this->cartSession[$productTypeId][$i]);
393        }
394    }
395
396    // 商品の削除
397    function delProduct($cart_no, $productTypeId) {
398        $max = $this->getMax($productTypeId);
399        for($i = 0; $i <= $max; $i++) {
400            if($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
401                unset($this->cartSession[$productTypeId][$i]);
402            }
403        }
404    }
405
406    // 数量の増加
407    function upQuantity($cart_no, $productTypeId) {
408        $quantity = $this->getQuantity($cart_no, $productTypeId);
409        if (strlen($quantity + 1) <= INT_LEN) {
410            $this->setQuantity($quantity + 1, $cart_no, $productTypeId);
411        }
412    }
413
414    // 数量の減少
415    function downQuantity($cart_no, $productTypeId) {
416        $quantity = $this->getQuantity($cart_no, $productTypeId);
417        if ($quantity > 1) {
418            $this->setQuantity($quantity - 1, $cart_no, $productTypeId);
419        }
420    }
421
422    /**
423     * カート番号と商品種別IDを指定して, 数量を取得する.
424     *
425     * @param integer $cart_no カート番号
426     * @param integer $productTypeId 商品種別ID
427     * @return integer 該当商品規格の数量
428     */
429    function getQuantity($cart_no, $productTypeId) {
430        $max = $this->getMax($productTypeId);
431        for ($i = 0; $i <= $max; $i++) {
432            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
433                return $this->cartSession[$productTypeId][$i]['quantity'];
434            }
435        }
436    }
437
438    /**
439     * カート番号と商品種別IDを指定して, 数量を設定する.
440     *
441     * @param integer $quantity 設定する数量
442     * @param integer $cart_no カート番号
443     * @param integer $productTypeId 商品種別ID
444     * @retrun void
445     */
446    function setQuantity($quantity, $cart_no, $productTypeId) {
447        $max = $this->getMax($productTypeId);
448        for ($i = 0; $i <= $max; $i++) {
449            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
450                $this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
451            }
452        }
453    }
454
455    /**
456     * カート番号と商品種別IDを指定して, 商品規格IDを取得する.
457     *
458     * @param integer $cart_no カート番号
459     * @param integer $productTypeId 商品種別ID
460     * @return integer 商品規格ID
461     */
462    function getProductClassId($cart_no, $productTypeId) {
463        for ($i = 0; $i <= $max; $i++) {
464            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
465                return $this->cartSession[$productTypeId][$i]['id'];
466            }
467        }
468    }
469
470    /**
471     * カート内の商品の妥当性をチェックする.
472     *
473     * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
474     * エラーメッセージを返す.
475     *
476     * 1. 商品種別に関連づけられた配送業者の存在チェック
477     * 2. 削除/非表示商品のチェック
478     * 3. 商品購入制限数のチェック
479     * 4. 在庫数チェック
480     *
481     * @param string $key 商品種別ID
482     * @return string エラーが発生した場合はエラーメッセージ
483     */
484    function checkProducts($productTypeId) {
485        $objProduct = new SC_Product_Ex();
486        $tpl_message = "";
487
488        // カート内の情報を取得
489        $items = $this->getCartList($productTypeId);
490        foreach (array_keys($items) as $key) {
491            $item =& $items[$key];
492            $product =& $item['productsClass'];
493
494            /*
495             * 配送業者のチェック
496             */
497            $arrDeliv = SC_Helper_Purchase_Ex::getDeliv($productTypeId);
498            if (SC_Utils_Ex::isBlank($arrDeliv)) {
499                $tpl_message .= "※「" . $product['name'] . "」はまだ配送の準備ができておりません。恐れ入りますがお問い合わせページよりお問い合わせください。\n";
500            }
501
502            /*
503             * 表示/非表示商品のチェック
504             */
505            if (SC_Utils_Ex::isBlank($product)) {
506                $this->delProduct($item['cart_no'], $productTypeId);
507                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
508            }
509
510            /*
511             * 商品購入制限数, 在庫数のチェック
512             */
513            $limit = $objProduct->getBuyLimit($product);
514            if (!is_null($limit) && $item['quantity'] > $limit) {
515                if ($limit > 0) {
516                    $this->setProductValue($item['id'], 'quantity', $limit, $productTypeId);
517                    $this->setProductValue($item['id'], 'total_inctax', SC_Helper_DB_Ex::sfCalcIncTax($item['price']) * $limit, $productTypeId);
518                    $tpl_message .= "※「" . $product['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n";
519                } else {
520                    $this->delProduct($item['cart_no'], $productTypeId);
521                    $tpl_message .= "※「" . $product['name'] . "」は売り切れました。\n";
522                    continue;
523                }
524            }
525        }
526        return $tpl_message;
527    }
528
529    /**
530     * 送料無料条件を満たすかどうかチェックする
531     *
532     * @param integer $productTypeId 商品種別ID
533     * @return boolean 送料無料の場合 true
534     */
535    function isDelivFree($productTypeId) {
536        $objDb = new SC_Helper_DB_Ex();
537
538        $subtotal = $this->getAllProductsTotal($productTypeId);
539
540        // 送料無料の購入数が設定されている場合
541        if (DELIV_FREE_AMOUNT > 0) {
542            // 商品の合計数量
543            $total_quantity = $this->getTotalQuantity($productTypeId);
544
545            if($total_quantity >= DELIV_FREE_AMOUNT) {
546                return true;
547            }
548        }
549
550        // 送料無料条件が設定されている場合
551        $arrInfo = $objDb->sfGetBasisData();
552        if ($arrInfo['free_rule'] > 0) {
553            // 小計が無料条件を超えている場合
554            if($subtotal >= $arrInfo['free_rule']) {
555                return true;
556            }
557        }
558
559        return false;
560    }
561
562    /**
563     * カートの内容を計算する.
564     *
565     * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
566     *
567     * - tax: 税額
568     * - subtotal: カート内商品の小計
569     * - deliv_fee: カート内商品の合計送料
570     * - total: 合計金額
571     * - payment_total: お支払い合計
572     * - add_point: 加算ポイント
573     *
574     * @param integer $productTypeId 商品種別ID
575     * @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
576     * @param integer $use_point 今回使用ポイント
577     * @param integer|array $deliv_pref 配送先都道府県ID.
578                                        複数に配送する場合は都道府県IDの配列
579     * @param integer $charge 手数料
580     * @param integer $discount 値引
581     * @param integer $deliv_id 配送業者ID
582     * @return array カートの計算結果の配列
583     */
584    function calculate($productTypeId, &$objCustomer, $use_point = 0,
585                       $deliv_pref = "", $charge = 0, $discount = 0, $deliv_id = 0) {
586        $objDb = new SC_Helper_DB_Ex();
587
588        $total_point = $this->getAllProductsPoint($productTypeId);
589        $results['tax'] = $this->getAllProductsTax($productTypeId);
590        $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
591        $results['deliv_fee'] = 0;
592
593        // 商品ごとの送料を加算
594        if (OPTION_PRODUCT_DELIV_FEE == 1) {
595            $cartItems = $this->getCartList($productTypeId);
596            foreach ($cartItems as $item) {
597                $results['deliv_fee'] += $item['productsClass']['deliv_fee'] * $item['quantity'];
598            }
599        }
600
601        // 配送業者の送料を加算
602        if (OPTION_DELIV_FEE == 1
603            && !SC_Utils_Ex::isBlank($deliv_pref)
604            && !SC_Utils_Ex::isBlank($deliv_id)) {
605            $results['deliv_fee'] += $objDb->sfGetDelivFee($deliv_pref, $deliv_id);
606        }
607
608        // 送料無料チェック
609        if ($this->isDelivFree($productTypeId)) {
610            $results['deliv_fee'] = 0;
611        }
612
613        // 合計を計算
614        $results['total'] = $results['subtotal'];
615        $results['total'] += $results['deliv_fee'];
616        $results['total'] += $charge;
617        $results['total'] -= $discount;
618
619        // お支払い合計
620        $results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
621
622        // 加算ポイントの計算
623        if (USE_POINT !== false) {
624            $results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point,
625                                                                   $use_point);
626            if($objCustomer != "") {
627                // 誕生日月であった場合
628                if($objCustomer->isBirthMonth()) {
629                    $results['birth_point'] = BIRTH_MONTH_POINT;
630                    $results['add_point'] += $results['birth_point'];
631                }
632            }
633            if($results['add_point'] < 0) {
634                $results['add_point'] = 0;
635            }
636        }
637        return $results;
638    }
639
640    /**
641     * カートが保持するキー(商品種別ID)を配列で返す.
642     *
643     * @return array 商品種別IDの配列
644     */
645    function getKeys() {
646        $keys = array_keys($this->cartSession);
647        // 数量が 0 の商品種別は削除する
648        foreach ($keys as $key) {
649            $quantity = $this->getTotalQuantity($key);
650            if ($quantity < 1) {
651                unset($this->cartSession[$key]);
652            }
653        }
654        return array_keys($this->cartSession);
655    }
656
657    /**
658     * カートに設定された現在のキー(商品種別ID)を登録する.
659     *
660     * @param integer $key 商品種別ID
661     * @return void
662     */
663    function registerKey($key) {
664        $_SESSION['cartKey'] = $key;
665    }
666
667    /**
668     * カートに設定された現在のキー(商品種別ID)を削除する.
669     *
670     * @return void
671     */
672    function unsetKey() {
673        unset($_SESSION['cartKey']);
674    }
675
676    /**
677     * カートに設定された現在のキー(商品種別ID)を取得する.
678     *
679     * @return integer 商品種別ID
680     */
681    function getKey() {
682        return $_SESSION['cartKey'];
683    }
684
685    /**
686     * 複数配送扱いかどうか.
687     *
688     * @return boolean カートが複数配送扱いの場合 true
689     */
690    function isMultiple() {
691        return count($this->getKeys()) > 1;
692    }
693
694    /**
695     * 引数の商品種別の商品がカートに含まれるかどうか.
696     *
697     * @param integer $product_type_id 商品種別ID
698     * @return boolean 指定の商品種別がカートに含まれる場合 true
699     */
700    function hasProductType($product_type_id) {
701        return in_array($product_type_id, $this->getKeys());
702    }
703}
704?>
Note: See TracBrowser for help on using the repository browser.