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

Revision 22218, 27.5 KB checked in by kim, 11 years ago (diff)

#1730 r22197r22215 で差し戻したものを、逆マージ。

  • 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     * @deprected getAllProductClassID を使用して下さい
392     */
393    function getAllProductID($productTypeId) {
394        trigger_error('正しく動作しないメソッドが呼び出されました。', E_USER_ERROR);
395    }
396
397    /**
398     * カート内にある商品規格IDを全て取得する.
399     *
400     * @param integer $productTypeId 商品種別ID
401     * @return array 商品規格ID の配列
402     */
403    function getAllProductClassID($productTypeId) {
404        $max = $this->getMax($productTypeId);
405        $productClassIDs = array();
406        for ($i = 0; $i <= $max; $i++) {
407            if ($this->cartSession[$productTypeId][$i]['cart_no'] != '') {
408                $productClassIDs[] = $this->cartSession[$productTypeId][$i]['id'];
409            }
410        }
411        return $productClassIDs;
412    }
413
414    /**
415     * 商品種別ID を指定して, カート内の商品をすべて削除する.
416     *
417     * @param integer $productTypeId 商品種別ID
418     * @return void
419     */
420    function delAllProducts($productTypeId) {
421        $max = $this->getMax($productTypeId);
422        for ($i = 0; $i <= $max; $i++) {
423            unset($this->cartSession[$productTypeId][$i]);
424        }
425    }
426
427    // 商品の削除
428    function delProduct($cart_no, $productTypeId) {
429        $max = $this->getMax($productTypeId);
430        for ($i = 0; $i <= $max; $i++) {
431            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
432                unset($this->cartSession[$productTypeId][$i]);
433            }
434        }
435    }
436
437    // 数量の増加
438    function upQuantity($cart_no, $productTypeId) {
439        $quantity = $this->getQuantity($cart_no, $productTypeId);
440        if (strlen($quantity + 1) <= INT_LEN) {
441            $this->setQuantity($quantity + 1, $cart_no, $productTypeId);
442        }
443    }
444
445    // 数量の減少
446    function downQuantity($cart_no, $productTypeId) {
447        $quantity = $this->getQuantity($cart_no, $productTypeId);
448        if ($quantity > 1) {
449            $this->setQuantity($quantity - 1, $cart_no, $productTypeId);
450        }
451    }
452
453    /**
454     * カート番号と商品種別IDを指定して, 数量を取得する.
455     *
456     * @param integer $cart_no カート番号
457     * @param integer $productTypeId 商品種別ID
458     * @return integer 該当商品規格の数量
459     */
460    function getQuantity($cart_no, $productTypeId) {
461        $max = $this->getMax($productTypeId);
462        for ($i = 0; $i <= $max; $i++) {
463            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
464                return $this->cartSession[$productTypeId][$i]['quantity'];
465            }
466        }
467    }
468
469    /**
470     * カート番号と商品種別IDを指定して, 数量を設定する.
471     *
472     * @param integer $quantity 設定する数量
473     * @param integer $cart_no カート番号
474     * @param integer $productTypeId 商品種別ID
475     * @retrun void
476     */
477    function setQuantity($quantity, $cart_no, $productTypeId) {
478        $max = $this->getMax($productTypeId);
479        for ($i = 0; $i <= $max; $i++) {
480            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
481                $this->cartSession[$productTypeId][$i]['quantity'] = $quantity;
482            }
483        }
484    }
485
486    /**
487     * カート番号と商品種別IDを指定して, 商品規格IDを取得する.
488     *
489     * @param integer $cart_no カート番号
490     * @param integer $productTypeId 商品種別ID
491     * @return integer 商品規格ID
492     */
493    function getProductClassId($cart_no, $productTypeId) {
494        for ($i = 0; $i < count($this->cartSession[$productTypeId]); $i++) {
495            if ($this->cartSession[$productTypeId][$i]['cart_no'] == $cart_no) {
496                return $this->cartSession[$productTypeId][$i]['id'];
497            }
498        }
499    }
500
501    /**
502     * カート内の商品の妥当性をチェックする.
503     *
504     * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
505     * エラーメッセージを返す.
506     *
507     * 1. 商品種別に関連づけられた配送業者の存在チェック
508     * 2. 削除/非表示商品のチェック
509     * 3. 販売制限数のチェック
510     * 4. 在庫数チェック
511     *
512     * @param string $productTypeId 商品種別ID
513     * @return string エラーが発生した場合はエラーメッセージ
514     */
515    function checkProducts($productTypeId) {
516        $objProduct = new SC_Product_Ex();
517        $tpl_message = '';
518
519        // カート内の情報を取得
520        $arrItems = $this->getCartList($productTypeId);
521        foreach ($arrItems as &$arrItem) {
522            $product =& $arrItem['productsClass'];
523            /*
524             * 表示/非表示商品のチェック
525             */
526            if (SC_Utils_Ex::isBlank($product) || $product['status'] != 1) {
527                $this->delProduct($arrItem['cart_no'], $productTypeId);
528                $tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
529            } else {
530
531                /*
532                 * 配送業者のチェック
533                 */
534                $arrDeliv = SC_Helper_Purchase_Ex::getDeliv($productTypeId);
535                if (SC_Utils_Ex::isBlank($arrDeliv)) {
536                    $tpl_message .= '※「' . $product['name'] . '」はまだ配送の準備ができておりません。';
537                    $tpl_message .= '恐れ入りますがお問い合わせページよりお問い合わせください。' . "\n";
538                    $this->delProduct($arrItem['cart_no'], $productTypeId);
539                }
540
541                /*
542                 * 販売制限数, 在庫数のチェック
543                 */
544                $limit = $objProduct->getBuyLimit($product);
545                if (!is_null($limit) && $arrItem['quantity'] > $limit) {
546                    if ($limit > 0) {
547                        $this->setProductValue($arrItem['id'], 'quantity', $limit, $productTypeId);
548                        $total_inctax = SC_Helper_DB_Ex::sfCalcIncTax($arrItem['price']) * $limit;
549                        $this->setProductValue($arrItem['id'], 'total_inctax', $total_inctax, $productTypeId);
550                        $tpl_message .= '※「' . $product['name'] . '」は販売制限(または在庫が不足)しております。';
551                        $tpl_message .= "一度に数量{$limit}を超える購入はできません。\n";
552                    } else {
553                        $this->delProduct($arrItem['cart_no'], $productTypeId);
554                        $tpl_message .= '※「' . $product['name'] . "」は売り切れました。\n";
555                        continue;
556                    }
557                }
558            }
559        }
560        return $tpl_message;
561    }
562
563    /**
564     * 送料無料条件を満たすかどうかチェックする
565     *
566     * @param integer $productTypeId 商品種別ID
567     * @return boolean 送料無料の場合 true
568     */
569    function isDelivFree($productTypeId) {
570        $objDb = new SC_Helper_DB_Ex();
571
572        $subtotal = $this->getAllProductsTotal($productTypeId);
573
574        // 送料無料の購入数が設定されている場合
575        if (DELIV_FREE_AMOUNT > 0) {
576            // 商品の合計数量
577            $total_quantity = $this->getTotalQuantity($productTypeId);
578
579            if ($total_quantity >= DELIV_FREE_AMOUNT) {
580                return true;
581            }
582        }
583
584        // 送料無料条件が設定されている場合
585        $arrInfo = $objDb->sfGetBasisData();
586        if ($arrInfo['free_rule'] > 0) {
587            // 小計が送料無料条件以上の場合
588            if ($subtotal >= $arrInfo['free_rule']) {
589                return true;
590            }
591        }
592
593        return false;
594    }
595
596    /**
597     * カートの内容を計算する.
598     *
599     * カートの内容を計算し, 下記のキーを保持する連想配列を返す.
600     *
601     * - tax: 税額
602     * - subtotal: カート内商品の小計
603     * - deliv_fee: カート内商品の合計送料
604     * - total: 合計金額
605     * - payment_total: お支払い合計
606     * - add_point: 加算ポイント
607     *
608     * @param integer $productTypeId 商品種別ID
609     * @param SC_Customer $objCustomer ログイン中の SC_Customer インスタンス
610     * @param integer $use_point 今回使用ポイント
611     * @param integer|array $deliv_pref 配送先都道府県ID.
612                                        複数に配送する場合は都道府県IDの配列
613     * @param integer $charge 手数料
614     * @param integer $discount 値引き
615     * @param integer $deliv_id 配送業者ID
616     * @return array カートの計算結果の配列
617     */
618    function calculate($productTypeId, &$objCustomer, $use_point = 0,
619        $deliv_pref = '', $charge = 0, $discount = 0, $deliv_id = 0
620    ) {
621
622        $results = array();
623        $total_point = $this->getAllProductsPoint($productTypeId);
624        $results['tax'] = $this->getAllProductsTax($productTypeId);
625        $results['subtotal'] = $this->getAllProductsTotal($productTypeId);
626        $results['deliv_fee'] = 0;
627
628        $arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
629        $results['order_tax_rate'] = $arrInfo['tax'];
630        $results['order_tax_rule'] = $arrInfo['tax_rule'];
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.