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

Revision 21247, 26.0 KB checked in by Ringo, 13 years ago (diff)

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