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

Revision 22553, 27.3 KB checked in by pineray, 11 years ago (diff)

#2136 dtb_deliv の処理を SC_Helper_Delivery クラスに集める.

  • 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        $objDelivery = new SC_Helper_Delivery_Ex();
511        $arrDeliv = $objDelivery->getList($productTypeId);
512        $tpl_message = '';
513
514        // カート内の情報を取得
515        $arrItems = $this->getCartList($productTypeId);
516        foreach ($arrItems as &$arrItem) {
517            $product =& $arrItem['productsClass'];
518            /*
519             * 表示/非表示商品のチェック
520             */
521            if (SC_Utils_Ex::isBlank($product) || $product['status'] != 1) {
522                $this->delProduct($arrItem['cart_no'], $productTypeId);
523                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
524            } else {
525
526                /*
527                 * 配送業者のチェック
528                 */
529                if (SC_Utils_Ex::isBlank($arrDeliv)) {
530                    $tpl_message .= '※「' . $product['name'] . '」はまだ配送の準備ができておりません。';
531                    $tpl_message .= '恐れ入りますがお問い合わせページよりお問い合わせください。' . "\n";
532                    $this->delProduct($arrItem['cart_no'], $productTypeId);
533                }
534
535                /*
536                 * 販売制限数, 在庫数のチェック
537                 */
538                $limit = $objProduct->getBuyLimit($product);
539                if (!is_null($limit) && $arrItem['quantity'] > $limit) {
540                    if ($limit > 0) {
541                        $this->setProductValue($arrItem['id'], 'quantity', $limit, $productTypeId);
542                        $total_inctax = SC_Helper_DB_Ex::sfCalcIncTax($arrItem['price']) * $limit;
543                        $this->setProductValue($arrItem['id'], 'total_inctax', $total_inctax, $productTypeId);
544                        $tpl_message .= '※「' . $product['name'] . '」は販売制限(または在庫が不足)しております。';
545                        $tpl_message .= "一度に数量{$limit}を超える購入はできません。\n";
546                    } else {
547                        $this->delProduct($arrItem['cart_no'], $productTypeId);
548                        $tpl_message .= '※「' . $product['name'] . "」は売り切れました。\n";
549                        continue;
550                    }
551                }
552            }
553        }
554        return $tpl_message;
555    }
556
557    /**
558     * 送料無料条件を満たすかどうかチェックする
559     *
560     * @param integer $productTypeId 商品種別ID
561     * @return boolean 送料無料の場合 true
562     */
563    function isDelivFree($productTypeId) {
564        $objDb = new SC_Helper_DB_Ex();
565
566        $subtotal = $this->getAllProductsTotal($productTypeId);
567
568        // 送料無料の購入数が設定されている場合
569        if (DELIV_FREE_AMOUNT > 0) {
570            // 商品の合計数量
571            $total_quantity = $this->getTotalQuantity($productTypeId);
572
573            if ($total_quantity >= DELIV_FREE_AMOUNT) {
574                return true;
575            }
576        }
577
578        // 送料無料条件が設定されている場合
579        $arrInfo = $objDb->sfGetBasisData();
580        if ($arrInfo['free_rule'] > 0) {
581            // 小計が送料無料条件以上の場合
582            if ($subtotal >= $arrInfo['free_rule']) {
583                return true;
584            }
585        }
586
587        return false;
588    }
589
590    /**
591     * カートの内容を計算する.
592     *
593     * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
594     *
595     * - tax: 税額
596     * - subtotal: カート内商品の小計
597     * - deliv_fee: カート内商品の合計送料
598     * - total: 合計金額
599     * - payment_total: お支払い合計
600     * - add_point: 加算ポイント
601     *
602     * @param integer $productTypeId 商品種別ID
603     * @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
604     * @param integer $use_point 今回使用ポイント
605     * @param integer|array $deliv_pref 配送先都道府県ID.
606                                        複数に配送する場合は都道府県IDの配列
607     * @param integer $charge 手数料
608     * @param integer $discount 値引き
609     * @param integer $deliv_id 配送業者ID
610     * @return array カートの計算結果の配列
611     */
612    function calculate($productTypeId, &$objCustomer, $use_point = 0,
613        $deliv_pref = '', $charge = 0, $discount = 0, $deliv_id = 0
614    ) {
615
616        $results = array();
617        $total_point = $this->getAllProductsPoint($productTypeId);
618        $results['tax'] = $this->getAllProductsTax($productTypeId);
619        $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
620        $results['deliv_fee'] = 0;
621
622        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
623        $results['order_tax_rate'] = $arrInfo['tax'];
624        $results['order_tax_rule'] = $arrInfo['tax_rule'];
625
626        // 商品ごとの送料を加算
627        if (OPTION_PRODUCT_DELIV_FEE == 1) {
628            $cartItems = $this->getCartList($productTypeId);
629            foreach ($cartItems as $arrItem) {
630                $results['deliv_fee'] += $arrItem['productsClass']['deliv_fee'] * $arrItem['quantity'];
631            }
632        }
633
634        // 配送業者の送料を加算
635        if (OPTION_DELIV_FEE == 1
636            && !SC_Utils_Ex::isBlank($deliv_pref)
637            && !SC_Utils_Ex::isBlank($deliv_id)) {
638            $results['deliv_fee'] += $this->sfGetDelivFee($deliv_pref, $deliv_id);
639        }
640
641        // 送料無料チェック
642        if ($this->isDelivFree($productTypeId)) {
643            $results['deliv_fee'] = 0;
644        }
645
646        // 合計を計算
647        $results['total'] = $results['subtotal'];
648        $results['total'] += $results['deliv_fee'];
649        $results['total'] += $charge;
650        $results['total'] -= $discount;
651
652        // お支払い合計
653        $results['payment_total'] = $results['total'] - $use_point * POINT_VALUE;
654
655        // 加算ポイントの計算
656        if (USE_POINT !== false) {
657            $results['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($total_point, $use_point);
658            if ($objCustomer != '') {
659                // 誕生日月であった場合
660                if ($objCustomer->isBirthMonth()) {
661                    $results['birth_point'] = BIRTH_MONTH_POINT;
662                    $results['add_point'] += $results['birth_point'];
663                }
664            }
665            if ($results['add_point'] < 0) {
666                $results['add_point'] = 0;
667            }
668        }
669        return $results;
670    }
671
672    /**
673     * カートが保持するキー(商品種別ID)を配列で返す.
674     *
675     * @return array 商品種別IDの配列
676     */
677    function getKeys() {
678        $keys = array_keys($this->cartSession);
679        // 数量が 0 の商品種別は削除する
680        foreach ($keys as $key) {
681            $quantity = $this->getTotalQuantity($key);
682            if ($quantity < 1) {
683                unset($this->cartSession[$key]);
684            }
685        }
686        return array_keys($this->cartSession);
687    }
688
689    /**
690     * カートに設定された現在のキー(商品種別ID)を登録する.
691     *
692     * @param integer $key 商品種別ID
693     * @return void
694     */
695    function registerKey($key) {
696        $_SESSION['cartKey'] = $key;
697    }
698
699    /**
700     * カートに設定された現在のキー(商品種別ID)を削除する.
701     *
702     * @return void
703     */
704    function unsetKey() {
705        unset($_SESSION['cartKey']);
706    }
707
708    /**
709     * カートに設定された現在のキー(商品種別ID)を取得する.
710     *
711     * @return integer 商品種別ID
712     */
713    function getKey() {
714        return $_SESSION['cartKey'];
715    }
716
717    /**
718     * 複数商品種別かどうか.
719     *
720     * @return boolean カートが複数商品種別の場合 true
721     */
722    function isMultiple() {
723        return count($this->getKeys()) > 1;
724    }
725
726    /**
727     * 引数の商品種別の商品がカートに含まれるかどうか.
728     *
729     * @param integer $product_type_id 商品種別ID
730     * @return boolean 指定の商品種別がカートに含まれる場合 true
731     */
732    function hasProductType($product_type_id) {
733        return in_array($product_type_id, $this->getKeys());
734    }
735
736    /**
737     * 都道府県から配送料金を取得する.
738     *
739     * @param integer|array $pref_id 都道府県ID 又は都道府県IDの配列
740     * @param integer $deliv_id 配送業者ID
741     * @return string 指定の都道府県, 配送業者の配送料金
742     */
743    function sfGetDelivFee($pref_id, $deliv_id = 0) {
744        $objQuery =& SC_Query_Ex::getSingletonInstance();
745        if (!is_array($pref_id)) {
746            $pref_id = array($pref_id);
747        }
748        $sql = <<< __EOS__
749            SELECT T1.fee AS fee
750            FROM dtb_delivfee T1
751                JOIN dtb_deliv T2
752                    ON T1.deliv_id = T2.deliv_id
753            WHERE T1.pref = ?
754                AND T1.deliv_id = ?
755                AND T2.del_flg = 0
756__EOS__;
757        $result = 0;
758        foreach ($pref_id as $pref) {
759            $result += $objQuery->getOne($sql, array($pref, $deliv_id));
760        }
761        return $result;
762    }
763
764}
Note: See TracBrowser for help on using the repository browser.