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

Revision 21864, 27.5 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

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