Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Cart.php

Documentation is available at LC_Page_Cart.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 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. // {{{ requires
  25. require_once CLASS_EX_REALDIR 'page_extends/LC_Page_Ex.php';
  26.  
  27. /**
  28.  * カート のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id: LC_Page_Cart.php 21252 2011-09-22 08:48:32Z nanasess $
  33.  */
  34. class LC_Page_Cart extends LC_Page_Ex {
  35.  
  36.     // {{{ properties
  37.  
  38.     /** 商品規格情報の配列 */
  39.     var $arrData;
  40.  
  41.     /** 動作モード */
  42.     var $mode;
  43.  
  44.     // }}}
  45.     // {{{ functions
  46.  
  47.     /**
  48.      * Page を初期化する.
  49.      *
  50.      * @return void 
  51.      */
  52.     function init({
  53.         parent::init();
  54.         $this->tpl_title "現在のカゴの中";
  55.         $masterData new SC_DB_MasterData_Ex();
  56.         $this->arrProductType $masterData->getMasterData("mtb_product_type");
  57.  
  58.     }
  59.  
  60.     /**
  61.      * Page のプロセス.
  62.      *
  63.      * @return void 
  64.      */
  65.     function process({
  66.         parent::process();
  67.         $this->action();
  68.         $this->sendResponse();
  69.     }
  70.  
  71.     /**
  72.      * Page のアクション.
  73.      *
  74.      * @return void 
  75.      */
  76.     function action({
  77.         $objCartSess new SC_CartSession_Ex();
  78.         $objSiteSess new SC_SiteSession_Ex();
  79.         $objCustomer new SC_Customer_Ex();
  80.  
  81.         $objFormParam $this->lfInitParam($_REQUEST);
  82.         $this->mode = $this->getMode();
  83.  
  84.         $this->cartKeys $objCartSess->getKeys();
  85.         foreach ($this->cartKeys as $key{
  86.             // 商品購入中にカート内容が変更された。
  87.             if($objCartSess->getCancelPurchase($key)) {
  88.                 $this->tpl_message "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。";
  89.             }
  90.         }
  91.         $this->cartItems =$objCartSess->getAllCartList();
  92.  
  93.         $cart_no $objFormParam->getValue('cart_no');
  94.         $cartKey $objFormParam->getValue('cartKey');
  95.  
  96.         switch($this->mode{
  97.         case 'confirm':
  98.             // カート内情報の取得
  99.             $cartList $objCartSess->getCartList($cartKey);
  100.             // カート商品が1件以上存在する場合
  101.             if(count($cartList0{
  102.                 // カートを購入モードに設定
  103.                 $this->lfSetCurrentCart($objSiteSess$objCartSess$cartKey);
  104.                 // 購入ページへ
  105.                 SC_Response_Ex::sendRedirect(SHOPPING_URL);
  106.                 exit;
  107.             }
  108.             break;
  109.         case 'up'://1個追加
  110.             $objCartSess->upQuantity($cart_no$cartKey);
  111.             SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id'))true);
  112.             exit;
  113.             break;
  114.         case 'down'://1個減らす
  115.             $objCartSess->downQuantity($cart_no$cartKey);
  116.             SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id'))true);
  117.             exit;
  118.             break;
  119.         case 'setQuantity'://数量変更
  120.             $objCartSess->setQuantity($objFormParam->getValue('quantity')$cart_no$cartKey);
  121.             SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id'))true);
  122.             exit;
  123.             break;
  124.         case 'delete'://カートから削除
  125.             $objCartSess->delProduct($cart_no$cartKey);
  126.             SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id'))true);
  127.             exit;
  128.             break;
  129.         default:
  130.             break;
  131.         }
  132.         $this->arrInfo SC_Helper_DB_Ex::sfGetBasisData();
  133.         $totalIncTax 0;
  134.         foreach (array_keys($this->cartKeysas $index{
  135.             $key $this->cartKeys[$index];
  136.             // カート集計処理
  137.             $this->tpl_message $objCartSess->checkProducts($key);
  138.             $this->tpl_total_inctax[$key$objCartSess->getAllProductsTotal($key);
  139.             $totalIncTax += $this->tpl_total_inctax[$key];
  140.             $this->tpl_total_tax[$key$objCartSess->getAllProductsTax($key);
  141.             // ポイント合計
  142.             $this->tpl_total_point[$key$objCartSess->getAllProductsPoint($key);
  143.  
  144.             $this->arrData[$key$objCartSess->calculate($key$objCustomer);
  145.  
  146.             // 送料無料チェック
  147.             $this->arrData[$key]['is_deliv_free'$objCartSess->isDelivFree($key);
  148.  
  149.             // 送料無料までの金額を計算
  150.             $this->tpl_deliv_free[$key$this->arrInfo['free_rule'$this->tpl_total_inctax[$key];
  151.             if (SC_Utils_Ex::isBlank($key)) {
  152.                 unset($this->cartKeys[$index]);
  153.             }
  154.         }
  155.  
  156.         //商品の合計金額をセット
  157.         $this->tpl_all_total_inctax $totalIncTax;
  158.         
  159.         $this->tpl_category_id $objFormParam->getValue('category_id');
  160.  
  161.         // ログイン判定
  162.         if($objCustomer->isLoginSuccess(true)) {
  163.             $this->tpl_login true;
  164.             $this->tpl_user_point $objCustomer->getValue('point');
  165.             $this->tpl_name $objCustomer->getValue('name01');
  166.         }
  167.  
  168.         // 前頁のURLを取得
  169.         // TODO: SC_CartSession::setPrevURL()利用不可。
  170.         $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
  171.         $this->tpl_prev_url (isset($_SESSION['cart_prev_url'])) $_SESSION['cart_prev_url''';
  172.     }
  173.  
  174.     /**
  175.      * デストラクタ.
  176.      *
  177.      * @return void 
  178.      */
  179.     function destroy({
  180.         parent::destroy();
  181.     }
  182.  
  183.     /**
  184.      * ユーザ入力値の処理
  185.      *
  186.      * @return object 
  187.      */
  188.     function lfInitParam($arrRequest{
  189.         $objFormParam new SC_FormParam_Ex();
  190.         $objFormParam->addParam("カートキー"'cartKey'INT_LEN'n'array('NUM_CHECK',"MAX_LENGTH_CHECK"));
  191.         $objFormParam->addParam("カートナンバー""cart_no"INT_LEN'n'array("NUM_CHECK""MAX_LENGTH_CHECK"));
  192.         // PC版での値引き継ぎ用
  193.         $objFormParam->addParam("カテゴリID""category_id"INT_LEN'n'array("NUM_CHECK""MAX_LENGTH_CHECK"));
  194.         // スマートフォン版での数量変更用
  195.         $objFormParam->addParam("数量"'quantity'INT_LEN'n'array("EXIST_CHECK""ZERO_CHECK""NUM_CHECK""MAX_LENGTH_CHECK"));
  196.         // 値の取得
  197.         $objFormParam->setParam($arrRequest);
  198.         // 入力値の変換
  199.         $objFormParam->convParam();
  200.         return $objFormParam;
  201.     }
  202.  
  203.     /**
  204.      * order_temp_id の更新
  205.      *
  206.      * @return 
  207.      */
  208.     function lfUpdateOrderTempid($pre_uniqid,$uniqid){
  209.         $sqlval['order_temp_id'$uniqid;
  210.         $where "order_temp_id = ?";
  211.         $objQuery =SC_Query_Ex::getSingletonInstance();
  212.         $res $objQuery->update("dtb_order_temp"$sqlval$wherearray($pre_uniqid));
  213.         if($res != 1){
  214.             return false;
  215.         }
  216.         return true;
  217.     }
  218.  
  219.     /**
  220.      * 前頁のURLを取得
  221.      *
  222.      * @return void 
  223.      */
  224.     function lfGetCartPrevUrl(&$session,$referer){
  225.         if (!preg_match("/cart/"$referer)) {
  226.             if (!empty($session['cart_referer_url'])) {
  227.                 $session['cart_prev_url'$session['cart_referer_url'];
  228.                 unset($session['cart_referer_url']);
  229.             else {
  230.                 if (preg_match("/entry/"$referer)) {
  231.                     $session['cart_prev_url'HTTPS_URL 'entry/kiyaku.php';
  232.                 else {
  233.                     $session['cart_prev_url'$referer;
  234.                 }
  235.             }
  236.         }
  237.         // 妥当性チェック
  238.         if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
  239.             $session['cart_prev_url''';
  240.         }
  241.     }
  242.  
  243.     /**
  244.      * カートを購入モードに設定
  245.      *
  246.      * @return void 
  247.      */
  248.     function lfSetCurrentCart(&$objSiteSess&$objCartSess$cartKey){
  249.         // 正常に登録されたことを記録しておく
  250.         $objSiteSess->setRegistFlag();
  251.         $pre_uniqid $objSiteSess->getUniqId();
  252.         // 注文一時IDの発行
  253.         $objSiteSess->setUniqId();
  254.         $uniqid $objSiteSess->getUniqId();
  255.         // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
  256.         if($pre_uniqid != ""{
  257.             $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
  258.         }
  259.         // カートを購入モードに設定
  260.         $objCartSess->registerKey($cartKey);
  261.         $objCartSess->saveCurrentCart($uniqid$cartKey);
  262.     }
  263. }
  264. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:54 +0900 by Seasoft