source: branches/version-2_12-dev/data/class/SC_CartSession.php @ 22567

Revision 22567, 26.6 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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