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

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