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

Revision 22706, 27.2 KB checked in by AMUAMU, 11 years ago (diff)

税金設定、カートセッションへの修正その1

  • 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]['total_inctax'] = $total;
387
388                $arrRet[] = $this->cartSession[$productTypeId][$i];
389
390                // セッション変数のデータ量を抑制するため、一部の商品情報を切り捨てる
391                // XXX 上で「常に取得」するのだから、丸ごと切り捨てて良さそうにも感じる。
392                $this->adjustSessionProductsClass($this->cartSession[$productTypeId][$i]['productsClass']);
393            }
394        }
395        return $arrRet;
396    }
397
398    /**
399     * すべてのカートの内容を取得する.
400     *
401     * @return array すべてのカートの内容
402     */
403    function getAllCartList()
404    {
405        $results = array();
406        $cartKeys = $this->getKeys();
407        $i = 0;
408        foreach ($cartKeys as $key) {
409            $cartItems = $this->getCartList($key);
410            foreach ($cartItems as $itemKey => $itemValue) {
411                $cartItem =& $cartItems[$itemKey];
412                $results[$key][$i] =& $cartItem;
413                $i++;
414            }
415        }
416        return $results;
417    }
418
419    /**
420     * カート内にある商品規格IDを全て取得する.
421     *
422     * @param integer $productTypeId 商品種別ID
423     * @return array 商品規格ID の配列
424     */
425    function getAllProductClassID($productTypeId)
426    {
427        $max = $this->getMax($productTypeId);
428        $productClassIDs = array();
429        for ($i = 0; $i <= $max; $i++) {
430            if ($this->cartSession[$productTypeId][$i]['cart_no'] != '') {
431                $productClassIDs[] = $this->cartSession[$productTypeId][$i]['id'];
432            }
433        }
434        return $productClassIDs;
435    }
436
437    /**
438     * 商品種別ID を指定して, カート内の商品をすべて削除する.
439     *
440     * @param integer $productTypeId 商品種別ID
441     * @return void
442     */
443    function delAllProducts($productTypeId)
444    {
445        $max = $this->getMax($productTypeId);
446        for ($i = 0; $i <= $max; $i++) {
447            unset($this->cartSession[$productTypeId][$i]);
448        }
449    }
450
451    // 商品の削除
452    function delProduct($cart_no, $productTypeId)
453    {
454        $max = $this->getMax($productTypeId);
455        for ($i = 0; $i <= $max; $i++) {
456            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
457                unset($this->cartSession[$productTypeId][$i]);
458            }
459        }
460    }
461
462    // 数量の増加
463    function upQuantity($cart_no, $productTypeId)
464    {
465        $quantity = $this->getQuantity($cart_no, $productTypeId);
466        if (strlen($quantity + 1) <= INT_LEN) {
467            $this->setQuantity($quantity + 1, $cart_no, $productTypeId);
468        }
469    }
470
471    // 数量の減少
472    function downQuantity($cart_no, $productTypeId)
473    {
474        $quantity = $this->getQuantity($cart_no, $productTypeId);
475        if ($quantity > 1) {
476            $this->setQuantity($quantity - 1, $cart_no, $productTypeId);
477        }
478    }
479
480    /**
481     * カート番号と商品種別IDを指定して, 数量を取得する.
482     *
483     * @param integer $cart_no カート番号
484     * @param integer $productTypeId 商品種別ID
485     * @return integer 該当商品規格の数量
486     */
487    function getQuantity($cart_no, $productTypeId)
488    {
489        $max = $this->getMax($productTypeId);
490        for ($i = 0; $i <= $max; $i++) {
491            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
492                return $this->cartSession[$productTypeId][$i]['quantity'];
493            }
494        }
495    }
496
497    /**
498     * カート番号と商品種別IDを指定して, 数量を設定する.
499     *
500     * @param integer $quantity 設定する数量
501     * @param integer $cart_no カート番号
502     * @param integer $productTypeId 商品種別ID
503     * @retrun void
504     */
505    function setQuantity($quantity, $cart_no, $productTypeId)
506    {
507        $max = $this->getMax($productTypeId);
508        for ($i = 0; $i <= $max; $i++) {
509            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
510                $this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
511            }
512        }
513    }
514
515    /**
516     * カート番号と商品種別IDを指定して, 商品規格IDを取得する.
517     *
518     * @param integer $cart_no カート番号
519     * @param integer $productTypeId 商品種別ID
520     * @return integer 商品規格ID
521     */
522    function getProductClassId($cart_no, $productTypeId)
523    {
524        for ($i = 0; $i < count($this->cartSession[$productTypeId]); $i++) {
525            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
526                return $this->cartSession[$productTypeId][$i]['id'];
527            }
528        }
529    }
530
531    /**
532     * カート内の商品の妥当性をチェックする.
533     *
534     * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
535     * エラーメッセージを返す.
536     *
537     * 1. 商品種別に関連づけられた配送業者の存在チェック
538     * 2. 削除/非表示商品のチェック
539     * 3. 販売制限数のチェック
540     * 4. 在庫数チェック
541     *
542     * @param string $productTypeId 商品種別ID
543     * @return string エラーが発生した場合はエラーメッセージ
544     */
545    function checkProducts($productTypeId)
546    {
547        $objProduct = new SC_Product_Ex();
548        $objDelivery = new SC_Helper_Delivery_Ex();
549        $arrDeliv = $objDelivery->getList($productTypeId);
550        $tpl_message = '';
551
552        // カート内の情報を取得
553        $arrItems = $this->getCartList($productTypeId);
554        foreach ($arrItems as &$arrItem) {
555            $product =& $arrItem['productsClass'];
556            /*
557             * 表示/非表示商品のチェック
558             */
559            if (SC_Utils_Ex::isBlank($product) || $product['status'] != 1) {
560                $this->delProduct($arrItem['cart_no'], $productTypeId);
561                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
562            } else {
563
564                /*
565                 * 配送業者のチェック
566                 */
567                if (SC_Utils_Ex::isBlank($arrDeliv)) {
568                    $tpl_message .= '※「' . $product['name'] . '」はまだ配送の準備ができておりません。';
569                    $tpl_message .= '恐れ入りますがお問い合わせページよりお問い合わせください。' . "\n";
570                    $this->delProduct($arrItem['cart_no'], $productTypeId);
571                }
572
573                /*
574                 * 販売制限数, 在庫数のチェック
575                 */
576                $limit = $objProduct->getBuyLimit($product);
577                if (!is_null($limit) && $arrItem['quantity'] > $limit) {
578                    if ($limit > 0) {
579                        $this->setProductValue($arrItem['id'], 'quantity', $limit, $productTypeId);
580                        $total_inctax = $limit * SC_Helper_TaxRule_Ex::sfCalcIncTax($arrItem['price'],
581                            $product['product_id'],
582                            $arrItem['id'][0]);
583                        $this->setProductValue($arrItem['id'], 'total_inctax', $total_inctax, $productTypeId);
584                        $tpl_message .= '※「' . $product['name'] . '」は販売制限(または在庫が不足)しております。';
585                        $tpl_message .= "一度に数量{$limit}を超える購入はできません。\n";
586                    } else {
587                        $this->delProduct($arrItem['cart_no'], $productTypeId);
588                        $tpl_message .= '※「' . $product['name'] . "」は売り切れました。\n";
589                        continue;
590                    }
591                }
592            }
593        }
594        return $tpl_message;
595    }
596
597    /**
598     * 送料無料条件を満たすかどうかチェックする
599     *
600     * @param integer $productTypeId 商品種別ID
601     * @return boolean 送料無料の場合 true
602     */
603    function isDelivFree($productTypeId)
604    {
605        $objDb = new SC_Helper_DB_Ex();
606
607        $subtotal = $this->getAllProductsTotal($productTypeId);
608
609        // 送料無料の購入数が設定されている場合
610        if (DELIV_FREE_AMOUNT > 0) {
611            // 商品の合計数量
612            $total_quantity = $this->getTotalQuantity($productTypeId);
613
614            if ($total_quantity >= DELIV_FREE_AMOUNT) {
615                return true;
616            }
617        }
618
619        // 送料無料条件が設定されている場合
620        $arrInfo = $objDb->sfGetBasisData();
621        if ($arrInfo['free_rule'] > 0) {
622            // 小計が送料無料条件以上の場合
623            if ($subtotal >= $arrInfo['free_rule']) {
624                return true;
625            }
626        }
627
628        return false;
629    }
630
631    /**
632     * カートの内容を計算する.
633     *
634     * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
635     *
636     * - tax: 税額
637     * - subtotal: カート内商品の小計
638     * - deliv_fee: カート内商品の合計送料
639     * - total: 合計金額
640     * - payment_total: お支払い合計
641     * - add_point: 加算ポイント
642     *
643     * @param integer $productTypeId 商品種別ID
644     * @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
645     * @param integer $use_point 今回使用ポイント
646     * @param integer|array $deliv_pref 配送先都道府県ID.
647                                        複数に配送する場合は都道府県IDの配列
648     * @param integer $charge 手数料
649     * @param integer $discount 値引き
650     * @param integer $deliv_id 配送業者ID
651     * @return array カートの計算結果の配列
652     */
653    function calculate($productTypeId, &$objCustomer, $use_point = 0,
654        $deliv_pref = '', $charge = 0, $discount = 0, $deliv_id = 0
655    ) {
656
657        $results = array();
658        $total_point = $this->getAllProductsPoint($productTypeId);
659        $results['tax'] = $this->getAllProductsTax($productTypeId);
660        $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
661        $results['deliv_fee'] = 0;
662
663        $arrTaxInfo = SC_Helper_TaxRule_Ex::getTaxRule();
664        $results['order_tax_rate'] = $arrTaxInfo['tax_rate'];
665        $results['order_tax_rule'] = $arrTaxInfo['calc_rule'];
666
667        // 商品ごとの送料を加算
668        if (OPTION_PRODUCT_DELIV_FEE == 1) {
669            $cartItems = $this->getCartList($productTypeId);
670            foreach ($cartItems as $arrItem) {
671                $results['deliv_fee'] += $arrItem['productsClass']['deliv_fee'] * $arrItem['quantity'];
672            }
673        }
674
675        // 配送業者の送料を加算
676        if (OPTION_DELIV_FEE == 1
677            && !SC_Utils_Ex::isBlank($deliv_pref)
678            && !SC_Utils_Ex::isBlank($deliv_id)) {
679            $results['deliv_fee'] += SC_Helper_Delivery_Ex::getDelivFee($deliv_pref, $deliv_id);
680        }
681
682        // 送料無料チェック
683        if ($this->isDelivFree($productTypeId)) {
684            $results['deliv_fee'] = 0;
685        }
686
687        // 合計を計算
688        $results['total'] = $results['subtotal'];
689        $results['total'] += $results['deliv_fee'];
690        $results['total'] += $charge;
691        $results['total'] -= $discount;
692
693        // お支払い合計
694        $results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
695
696        // 加算ポイントの計算
697        if (USE_POINT !== false) {
698            $results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point, $use_point);
699            if ($objCustomer != '') {
700                // 誕生日月であった場合
701                if ($objCustomer->isBirthMonth()) {
702                    $results['birth_point'] = BIRTH_MONTH_POINT;
703                    $results['add_point'] += $results['birth_point'];
704                }
705            }
706            if ($results['add_point'] < 0) {
707                $results['add_point'] = 0;
708            }
709        }
710        return $results;
711    }
712
713    /**
714     * カートが保持するキー(商品種別ID)を配列で返す.
715     *
716     * @return array 商品種別IDの配列
717     */
718    function getKeys()
719    {
720        $keys = array_keys($this->cartSession);
721        // 数量が 0 の商品種別は削除する
722        foreach ($keys as $key) {
723            $quantity = $this->getTotalQuantity($key);
724            if ($quantity < 1) {
725                unset($this->cartSession[$key]);
726            }
727        }
728        return array_keys($this->cartSession);
729    }
730
731    /**
732     * カートに設定された現在のキー(商品種別ID)を登録する.
733     *
734     * @param integer $key 商品種別ID
735     * @return void
736     */
737    function registerKey($key)
738    {
739        $_SESSION['cartKey'] = $key;
740    }
741
742    /**
743     * カートに設定された現在のキー(商品種別ID)を削除する.
744     *
745     * @return void
746     */
747    function unsetKey()
748    {
749        unset($_SESSION['cartKey']);
750    }
751
752    /**
753     * カートに設定された現在のキー(商品種別ID)を取得する.
754     *
755     * @return integer 商品種別ID
756     */
757    function getKey()
758    {
759        return $_SESSION['cartKey'];
760    }
761
762    /**
763     * 複数商品種別かどうか.
764     *
765     * @return boolean カートが複数商品種別の場合 true
766     */
767    function isMultiple()
768    {
769        return count($this->getKeys()) > 1;
770    }
771
772    /**
773     * 引数の商品種別の商品がカートに含まれるかどうか.
774     *
775     * @param integer $product_type_id 商品種別ID
776     * @return boolean 指定の商品種別がカートに含まれる場合 true
777     */
778    function hasProductType($product_type_id)
779    {
780        return in_array($product_type_id, $this->getKeys());
781    }
782}
Note: See TracBrowser for help on using the repository browser.