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

Revision 20877, 24.7 KB checked in by nanasess, 13 years ago (diff)

#1237 (商品に個別に設定した送料が反映されない)

  • カートに商品投入後, 商品送料を設定しても反映されないため, SC_CartSession の商品情報はリアルタイムに取得するよう修正
  • 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                $id = $this->cartSession[$productTypeId][$i]['id'][0];
222                $point = SC_Utils_Ex::sfPrePoint($price, $point_rate, POINT_RULE, $id);
223                $total+= ($point * $quantity);
224            }
225        }
226        return $total;
227    }
228
229    // カートへの商品追加
230    function addProduct($product_class_id, $quantity) {
231        $objProduct = new SC_Product_Ex();
232        $arrProduct = $objProduct->getProductsClass($product_class_id);
233        $productTypeId = $arrProduct['product_type_id'];
234        $find = false;
235        $max = $this->getMax($productTypeId);
236        for($i = 0; $i <= $max; $i++) {
237
238            if($this->cartSession[$productTypeId][$i]['id'] == $product_class_id) {
239                $val = $this->cartSession[$productTypeId][$i]['quantity'] + $quantity;
240                if(strlen($val) <= INT_LEN) {
241                    $this->cartSession[$productTypeId][$i]['quantity'] += $quantity;
242                }
243                $find = true;
244            }
245        }
246        if(!$find) {
247            $this->cartSession[$productTypeId][$max+1]['id'] = $product_class_id;
248            $this->cartSession[$productTypeId][$max+1]['quantity'] = $quantity;
249            $this->cartSession[$productTypeId][$max+1]['cart_no'] = $this->getNextCartID($productTypeId);
250        }
251    }
252
253    // 前頁のURLを記録しておく
254    function setPrevURL($url, $excludePaths = array()) {
255        // 前頁として記録しないページを指定する。
256        $arrExclude = array(
257            "/shopping/"
258        );
259        $arrExclude = array_merge($arrExclude, $excludePaths);
260        $exclude = false;
261        // ページチェックを行う。
262        foreach($arrExclude as $val) {
263            if(preg_match("|" . preg_quote($val) . "|", $url)) {
264                $exclude = true;
265                break;
266            }
267        }
268        // 除外ページでない場合は、前頁として記録する。
269        if(!$exclude) {
270            $_SESSION['prev_url'] = $url;
271        }
272    }
273
274    // 前頁のURLを取得する
275    function getPrevURL() {
276        return isset($_SESSION['prev_url']) ? $_SESSION['prev_url'] : "";
277    }
278
279    // キーが一致した商品の削除
280    function delProductKey($keyname, $val, $productTypeId) {
281        $max = count($this->cartSession[$productTypeId]);
282        for($i = 0; $i < $max; $i++) {
283            if($this->cartSession[$productTypeId][$i][$keyname] == $val) {
284                unset($this->cartSession[$productTypeId][$i]);
285            }
286        }
287    }
288
289    function setValue($key, $val, $productTypeId) {
290        $this->cartSession[$productTypeId][$key] = $val;
291    }
292
293    function getValue($key, $productTypeId) {
294        return $this->cartSession[$productTypeId][$key];
295    }
296
297    /**
298     * 商品種別ごとにカート内商品の一覧を取得する.
299     *
300     * @param integer $productTypeId 商品種別ID
301     * @return array カート内商品一覧の配列
302     */
303    function getCartList($productTypeId) {
304        $objProduct = new SC_Product_Ex();
305        $max = $this->getMax($productTypeId);
306        $arrRet = array();
307        for($i = 0; $i <= $max; $i++) {
308            if(isset($this->cartSession[$productTypeId][$i]['cart_no'])
309               && $this->cartSession[$productTypeId][$i]['cart_no'] != "") {
310
311                // 商品情報は常に取得
312                $this->cartSession[$productTypeId][$i]['productsClass'] =&
313                        $objProduct->getDetailAndProductsClass(
314                                    $this->cartSession[$productTypeId][$i]['id']);
315
316                $price = $this->cartSession[$productTypeId][$i]['productsClass']['price02'];
317                $this->cartSession[$productTypeId][$i]['price'] = $price;
318
319                $this->cartSession[$productTypeId][$i]['point_rate'] =
320                    $this->cartSession[$productTypeId][$i]['productsClass']['point_rate'];
321
322                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];
323                $incTax = SC_Helper_DB_Ex::sfCalcIncTax($price);
324                $total = $incTax * $quantity;
325
326                $this->cartSession[$productTypeId][$i]['total_inctax'] = $total;
327
328                $arrRet[] =& $this->cartSession[$productTypeId][$i];
329            }
330        }
331        return $arrRet;
332    }
333
334    /**
335     * すべてのカートの内容を取得する.
336     *
337     * @return array すべてのカートの内容
338     */
339    function getAllCartList() {
340        $results = array();
341        $cartKeys = $this->getKeys();
342        $i = 0;
343        foreach ($cartKeys as $key) {
344            $cartItems = $this->getCartList($key);
345            foreach (array_keys($cartItems) as $itemKey) {
346                $cartItem =& $cartItems[$itemKey];
347                $results[$key][$i] =& $cartItem;
348                $i++;
349            }
350        }
351        return $results;
352    }
353
354    // カート内にある商品IDを全て取得する
355    /**
356     * @deprected getAllProductClassID を使用して下さい
357     */
358    function getAllProductID($productTypeId) {
359        $max = $this->getMax($productTypeId);
360        for($i = 0; $i <= $max; $i++) {
361            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
362                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'][0];
363            }
364        }
365        return $arrRet;
366    }
367
368    /**
369     * カート内にある商品規格IDを全て取得する.
370     *
371     * @param integer $productTypeId 商品種別ID
372     * @return array 商品規格ID の配列
373     */
374    function getAllProductClassID($productTypeId) {
375        $max = $this->getMax($productTypeId);
376        for($i = 0; $i <= $max; $i++) {
377            if($this->cartSession[$productTypeId][$i]['cart_no'] != "") {
378                $arrRet[] = $this->cartSession[$productTypeId][$i]['id'];
379            }
380        }
381        return $arrRet;
382    }
383
384    /**
385     * 商品種別ID を指定して, カート内の商品をすべて削除する.
386     *
387     * @param integer $productTypeId 商品種別ID
388     * @return void
389     */
390    function delAllProducts($productTypeId) {
391        $max = $this->getMax($productTypeId);
392        for($i = 0; $i <= $max; $i++) {
393            unset($this->cartSession[$productTypeId][$i]);
394        }
395    }
396
397    // 商品の削除
398    function delProduct($cart_no, $productTypeId) {
399        $max = $this->getMax($productTypeId);
400        for($i = 0; $i <= $max; $i++) {
401            if($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
402                unset($this->cartSession[$productTypeId][$i]);
403            }
404        }
405    }
406
407    // 数量の増加
408    function upQuantity($cart_no, $productTypeId) {
409        $quantity = $this->getQuantity($cart_no, $productTypeId);
410        if (strlen($quantity + 1) <= INT_LEN) {
411            $this->setQuantity($quantity + 1, $cart_no, $productTypeId);
412        }
413    }
414
415    // 数量の減少
416    function downQuantity($cart_no, $productTypeId) {
417        $quantity = $this->getQuantity($cart_no, $productTypeId);
418        if ($quantity > 1) {
419            $this->setQuantity($quantity - 1, $cart_no, $productTypeId);
420        }
421    }
422
423    /**
424     * カート番号と商品種別IDを指定して, 数量を取得する.
425     *
426     * @param integer $cart_no カート番号
427     * @param integer $productTypeId 商品種別ID
428     * @return integer 該当商品規格の数量
429     */
430    function getQuantity($cart_no, $productTypeId) {
431        $max = $this->getMax($productTypeId);
432        for ($i = 0; $i <= $max; $i++) {
433            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
434                return $this->cartSession[$productTypeId][$i]['quantity'];
435            }
436        }
437    }
438
439    /**
440     * カート番号と商品種別IDを指定して, 数量を設定する.
441     *
442     * @param integer $quantity 設定する数量
443     * @param integer $cart_no カート番号
444     * @param integer $productTypeId 商品種別ID
445     * @retrun void
446     */
447    function setQuantity($quantity, $cart_no, $productTypeId) {
448        $max = $this->getMax($productTypeId);
449        for ($i = 0; $i <= $max; $i++) {
450            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
451                $this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
452            }
453        }
454    }
455
456    /**
457     * カート番号と商品種別IDを指定して, 商品規格IDを取得する.
458     *
459     * @param integer $cart_no カート番号
460     * @param integer $productTypeId 商品種別ID
461     * @return integer 商品規格ID
462     */
463    function getProductClassId($cart_no, $productTypeId) {
464        for ($i = 0; $i <= $max; $i++) {
465            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
466                return $this->cartSession[$productTypeId][$i]['id'];
467            }
468        }
469    }
470
471    /**
472     * カート内の商品の妥当性をチェックする.
473     *
474     * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
475     * エラーメッセージを返す.
476     *
477     * 1. 商品種別に関連づけられた配送業者の存在チェック
478     * 2. 削除/非表示商品のチェック
479     * 3. 商品購入制限数のチェック
480     * 4. 在庫数チェック
481     *
482     * @param string $key 商品種別ID
483     * @return string エラーが発生した場合はエラーメッセージ
484     */
485    function checkProducts($productTypeId) {
486        $objProduct = new SC_Product_Ex();
487        $tpl_message = "";
488
489        // カート内の情報を取得
490        $items = $this->getCartList($productTypeId);
491        foreach (array_keys($items) as $key) {
492            $item =& $items[$key];
493            $product =& $item['productsClass'];
494
495            /*
496             * 配送業者のチェック
497             */
498            $arrDeliv = SC_Helper_Purchase_Ex::getDeliv($productTypeId);
499            if (SC_Utils_Ex::isBlank($arrDeliv)) {
500                $tpl_message .= "※「" . $product['name'] . "」はまだ配送の準備ができておりません。恐れ入りますがお問い合わせページよりお問い合わせください。\n";
501            }
502
503            /*
504             * 表示/非表示商品のチェック
505             */
506            if (SC_Utils_Ex::isBlank($product)) {
507                $this->delProduct($item['cart_no'], $productTypeId);
508                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
509            }
510
511            /*
512             * 商品購入制限数, 在庫数のチェック
513             */
514            $limit = $objProduct->getBuyLimit($product);
515            if (!is_null($limit) && $item['quantity'] > $limit) {
516                if ($limit > 0) {
517                    $this->setProductValue($item['id'], 'quantity', $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.