source: branches/version-2_13-dev/data/class/SC_CartSession.php @ 22960

Revision 22960, 27.8 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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