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

Revision 22736, 27.3 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 税率チームのコミットをマージ(from camp/camp-2_13-tax)

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