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

Revision 22358, 27.3 KB checked in by undertree, 11 years ago (diff)

#1870 SC_CartSession#getAllProductID コメント通りの動作をしない
「正しく動作しない」かつ「どこからも呼ばれていない(@deprected)」メソッド getAllProductClassID を削除。

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