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

Source for file LC_Page_Shopping_Payment.php

Documentation is available at LC_Page_Shopping_Payment.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_Shopping_Payment.php 21185 2011-08-11 10:37:10Z shutta $
  33.  */
  34. class LC_Page_Shopping_Payment extends LC_Page_Ex {
  35.  
  36.     // {{{ properties
  37.  
  38.     /** フォームパラメーターの配列 */
  39.     var $objFormParam;
  40.  
  41.     /** 会員情報のインスタンス */
  42.     var $objCustomer;
  43.  
  44.     // }}}
  45.     // {{{ functions
  46.  
  47.     /**
  48.      * Page を初期化する.
  49.      *
  50.      * @return void 
  51.      */
  52.     function init({
  53.         parent::init();
  54.         $this->tpl_onload "fnCheckInputPoint();";
  55.         $this->tpl_title "お支払方法・お届け時間等の指定";
  56.         $masterData new SC_DB_MasterData();
  57.         $this->arrPref $masterData->getMasterData('mtb_pref');
  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.         $objSiteSess new SC_SiteSession_Ex();
  78.         $objCartSess new SC_CartSession_Ex();
  79.         $objPurchase new SC_Helper_Purchase_Ex();
  80.         $objCustomer new SC_Customer_Ex();
  81.         $objFormParam new SC_FormParam_Ex();
  82.  
  83.         $this->is_multiple $objPurchase->isMultiple();
  84.  
  85.         // カートの情報を取得
  86.         $this->arrShipping $objPurchase->getShippingTemp($this->is_multiple);
  87.  
  88.         $this->tpl_uniqid $objSiteSess->getUniqId();
  89.         $cart_key $objCartSess->getKey();
  90.         $this->cartKey $cart_key;
  91.         $objPurchase->verifyChangeCart($this->tpl_uniqid$objCartSess);
  92.  
  93.         // 配送業者を取得
  94.         $this->arrDeliv $objPurchase->getDeliv($cart_key);
  95.         $this->is_single_deliv $this->isSingleDeliv($this->arrDeliv);
  96.  
  97.         // 会員情報の取得
  98.         if ($objCustomer->isLoginSuccess(true)) {
  99.             $this->tpl_login '1';
  100.             $this->tpl_user_point $objCustomer->getValue('point');
  101.             $this->name01 $objCustomer->getValue('name01');
  102.             $this->name02 $objCustomer->getValue('name02');
  103.         }
  104.  
  105.         // 戻り URL の設定
  106.         $this->tpl_back_url $this->getPreviousURL($objCustomer->isLoginSuccess(true)$cart_key$this->is_multiple);
  107.  
  108.         $arrOrderTemp $objPurchase->getOrderTemp($this->tpl_uniqid);
  109.         // 正常に受注情報が格納されていない場合はカート画面へ戻す
  110.         if (SC_Utils_Ex::isBlank($arrOrderTemp)) {
  111.             SC_Response_Ex::sendRedirect(CART_URLPATH);
  112.             exit;
  113.         }
  114.  
  115.         // カート内商品の妥当性チェック
  116.         $this->tpl_message $objCartSess->checkProducts($cart_key);
  117.         if (strlen($this->tpl_message>= 1{
  118.             SC_Response_Ex::sendRedirect(CART_URLPATH);
  119.             exit;
  120.         }
  121.  
  122.         /*
  123.          * 購入金額の取得
  124.          * ここでは送料を加算しない
  125.          */
  126.         $this->arrPrices $objCartSess->calculate($cart_key$objCustomer);
  127.  
  128.         // お届け日一覧の取得
  129.         $this->arrDelivDate $objPurchase->getDelivDate($objCartSess$cart_key);
  130.  
  131.         switch($this->getMode()) {
  132.         /*
  133.          * 配送業者選択時のアクション
  134.          * モバイル端末以外の場合は, JSON 形式のデータを出力し, ajax で取得する.
  135.          */
  136.         case 'select_deliv':
  137.             $this->setFormParams($objFormParam$arrOrderTemptrue$this->arrShipping);
  138.             $objFormParam->setParam($_POST);
  139.             $this->arrErr $objFormParam->checkError();
  140.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  141.                 $deliv_id $objFormParam->getValue('deliv_id');
  142.                 $arrSelectedDeliv $this->getSelectedDeliv($objPurchase$objCartSess$deliv_id);
  143.                 $arrSelectedDeliv['error'false;
  144.             else {
  145.                 $arrSelectedDeliv array('error' => true);
  146.                 $this->tpl_mainpage 'shopping/select_deliv.tpl'// モバイル用
  147.             }
  148.  
  149.             if (SC_Display_Ex::detectDevice(!= DEVICE_TYPE_MOBILE{
  150.                 echo SC_Utils_Ex::jsonEncode($arrSelectedDeliv);
  151.                 exit;
  152.             else {
  153.                 $this->arrPayment $arrSelectedDeliv['arrPayment'];
  154.                 $this->arrDelivTime $arrSelectedDeliv['arrDelivTime'];
  155.             }
  156.             break;
  157.  
  158.         // 登録処理
  159.         case 'confirm':
  160.             // パラメーター情報の初期化
  161.             $this->setFormParams($objFormParam$_POSTfalse$this->arrShipping);
  162.  
  163.             $deliv_id $objFormParam->getValue('deliv_id');
  164.             $arrSelectedDeliv $this->getSelectedDeliv($objPurchase$objCartSess$deliv_id);
  165.             $this->arrPayment $arrSelectedDeliv['arrPayment'];
  166.             $this->arrDelivTime $arrSelectedDeliv['arrDelivTime'];
  167.  
  168.             $this->arrErr $this->lfCheckError($objFormParam$this->arrPrices['subtotal']$this->tpl_user_point);
  169.  
  170.             if (SC_Utils_Ex::isBlank($this->arrErr)) {
  171.                 $this->saveShippings($objFormParam$this->arrDelivTime);
  172.                 $this->lfRegistData($this->tpl_uniqid$objFormParam->getDbArray()$objPurchase$this->arrPayment);
  173.  
  174.                 // 正常に登録されたことを記録しておく
  175.                 $objSiteSess->setRegistFlag();
  176.                 // 確認ページへ移動
  177.                 SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URLPATH);
  178.                 exit;
  179.             else {
  180.                 // 受注一時テーブルからの情報を格納
  181.                 $this->img_show $arrSelectedDeliv['img_show'];
  182.                 $objFormParam->setParam($objPurchase->getOrderTemp($this->tpl_uniqid));
  183.             }
  184.             break;
  185.  
  186.         // 前のページに戻る
  187.         case 'return':
  188.  
  189.             // 正常な推移であることを記録しておく
  190.             $objSiteSess->setRegistFlag();
  191.             SC_Response_Ex::sendRedirect(SHOPPING_URL);
  192.             exit;
  193.             break;
  194.  
  195.         default:
  196.             // FIXME 前のページから戻ってきた場合は別パラメーター(mode)で処理分岐する必要があるのかもしれない
  197.             $this->setFormParams($objFormParam$arrOrderTempfalse$this->arrShipping);
  198.  
  199.             if (!$this->is_single_deliv{
  200.                 $deliv_id $objFormParam->getValue('deliv_id');
  201.             else {
  202.                 $deliv_id $this->arrDeliv[0]['deliv_id'];
  203.             }
  204.  
  205.             if (!SC_Utils_Ex::isBlank($deliv_id)) {
  206.                 $objFormParam->setValue('deliv_id'$deliv_id);
  207.                 $arrSelectedDeliv $this->getSelectedDeliv($objPurchase$objCartSess$deliv_id);
  208.                 $this->arrPayment $arrSelectedDeliv['arrPayment'];
  209.                 $this->arrDelivTime $arrSelectedDeliv['arrDelivTime'];
  210.                 $this->img_show $arrSelectedDeliv['img_show'];
  211.             }
  212.             break;
  213.         }
  214.  
  215.         // モバイル用 ポストバック処理
  216.         if (SC_Display_Ex::detectDevice(== DEVICE_TYPE_MOBILE
  217.             && SC_Utils_Ex::isBlank($this->arrErr)) {
  218.             $this->tpl_mainpage $this->getMobileMainpage($this->is_single_deliv$this->getMode());
  219.         }
  220.  
  221.         $this->arrForm $objFormParam->getFormParamList();
  222.     }
  223.  
  224.     /**
  225.      * デストラクタ.
  226.      *
  227.      * @return void 
  228.      */
  229.     function destroy({
  230.         parent::destroy();
  231.     }
  232.  
  233.     /**
  234.      * パラメーターの初期化を行い, 初期値を設定する.
  235.      *
  236.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  237.      * @param array $arrParam 設定する値の配列
  238.      * @param boolean $deliv_only deliv_id チェックのみの場合 true
  239.      * @param array $arrShipping 配送先情報の配列
  240.      */
  241.     function setFormParams(&$objFormParam$arrParam$deliv_only&$arrShipping{
  242.         $this->lfInitParam($objFormParam$deliv_only$arrShipping);
  243.         $objFormParam->setParam($arrParam);
  244.         $objFormParam->convParam();
  245.     }
  246.  
  247.     /**
  248.      * パラメーター情報の初期化を行う.
  249.      *
  250.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  251.      * @param boolean $deliv_only 必須チェックは deliv_id のみの場合 true
  252.      * @param array $arrShipping 配送先情報の配列
  253.      * @return void 
  254.      */
  255.     function lfInitParam(&$objFormParam$deliv_only&$arrShipping{
  256.         $objFormParam->addParam("配送業者""deliv_id"INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK"));
  257.         $objFormParam->addParam("ポイント""use_point"INT_LEN'n'array("MAX_LENGTH_CHECK""NUM_CHECK""ZERO_START"));
  258.         $objFormParam->addParam("その他お問い合わせ"'message'LTEXT_LEN'KVa'array("SPTAB_CHECK""MAX_LENGTH_CHECK"));
  259.         $objFormParam->addParam("ポイントを使用する""point_check"INT_LEN'n'array("MAX_LENGTH_CHECK""NUM_CHECK")'2');
  260.  
  261.         if ($deliv_only{
  262.             $objFormParam->addParam("お支払い方法""payment_id"INT_LEN'n'array("MAX_LENGTH_CHECK""NUM_CHECK"));
  263.         else {
  264.             $objFormParam->addParam("お支払い方法""payment_id"INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK"));
  265.  
  266.             foreach ($arrShipping as $val{
  267.                 $objFormParam->addParam("お届け時間""deliv_time_id" $val['shipping_id']INT_LEN'n'array("MAX_LENGTH_CHECK""NUM_CHECK"));
  268.                 $objFormParam->addParam("お届け日""deliv_date" $val['shipping_id']STEXT_LEN'KVa'array("MAX_LENGTH_CHECK"));
  269.             }
  270.         }
  271.  
  272.         $objFormParam->setParam($arrParam);
  273.         $objFormParam->convParam();
  274.     }
  275.  
  276.     /**
  277.      * 入力内容のチェックを行なう.
  278.      *
  279.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  280.      * @param integer $subtotal 購入金額の小計
  281.      * @param integer $max_point 会員の保持ポイント
  282.      * @return array 入力チェック結果の配列
  283.      */
  284.     function lfCheckError(&$objFormParam$subtotal$max_point{
  285.         // 入力データを渡す。
  286.         $arrForm =  $objFormParam->getHashArray();
  287.         $objErr new SC_CheckError_Ex($arrForm);
  288.         $objErr->arrErr $objFormParam->checkError();
  289.  
  290.         if (USE_POINT === false{
  291.             return $objErr->arrErr;
  292.         }
  293.  
  294.         if($arrForm['point_check'== '1'{
  295.             $objErr->doFunc(array("ポイントを使用する""point_check")array("EXIST_CHECK"));
  296.             $objErr->doFunc(array("ポイント""use_point")array("EXIST_CHECK"));
  297.             if($max_point == ""{
  298.                 $max_point 0;
  299.             }
  300.             // FIXME mobile 互換のため br は閉じない...
  301.             if($arrForm['use_point'$max_point{
  302.                 $objErr->arrErr['use_point'"※ ご利用ポイントが所持ポイントを超えています。<br>";
  303.             }
  304.             if(($arrForm['use_point'POINT_VALUE$subtotal{
  305.                 $objErr->arrErr['use_point'"※ ご利用ポイントがご購入金額を超えています。<br>";
  306.             }
  307.         }
  308.         return $objErr->arrErr;
  309.     }
  310.  
  311.     /**
  312.      * 配送情報を保存する.
  313.      *
  314.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  315.      * @param array $arrDelivTime 配送時間の配列
  316.      */
  317.     function saveShippings(&$objFormParam$arrDelivTime{
  318.         $deliv_id $objFormParam->getValue('deliv_id');
  319.  
  320.         /* TODO
  321.          * SC_Purchase::getShippingTemp() で取得して,
  322.          * リファレンスで代入すると, セッションに添字を追加できない?
  323.          */
  324.         foreach (array_keys($_SESSION['shipping']as $key{
  325.             $shipping_id $_SESSION['shipping'][$key]['shipping_id'];
  326.             $time_id $objFormParam->getValue('deliv_time_id' $shipping_id);
  327.             $_SESSION['shipping'][$key]['deliv_id'$deliv_id;
  328.             $_SESSION['shipping'][$key]['time_id'$time_id;
  329.             $_SESSION['shipping'][$key]['shipping_time'$arrDelivTime[$time_id];
  330.             $_SESSION['shipping'][$key]['shipping_date'$objFormParam->getValue('deliv_date' $shipping_id);
  331.         }
  332.     }
  333.  
  334.     /**
  335.      * 受注一時テーブルへ登録を行う.
  336.      *
  337.      * @param integer $uniqid 受注一時テーブルのユニークID
  338.      * @param array $arrForm フォームの入力値
  339.      * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
  340.      * @param array $arrPayment お支払い方法の配列
  341.      * @return void 
  342.      */
  343.     function lfRegistData($uniqid$arrForm&$objPurchase$arrPayment{
  344.  
  345.         $arrForm['order_temp_id'$uniqid;
  346.         $arrForm['update_date''CURRENT_TIMESTAMP';
  347.  
  348.         if($arrForm['point_check'!= '1'{
  349.             $arrForm['use_point'0;
  350.         }
  351.  
  352.         foreach ($arrPayment as $payment{
  353.             if ($arrForm['payment_id'== $payment['payment_id']{
  354.                 $arrForm['charge'$payment['charge'];
  355.                 $arrForm['payment_method'$payment['payment_method'];
  356.                 break;
  357.             }
  358.         }
  359.         $objPurchase->saveOrderTemp($uniqid$arrForm);
  360.     }
  361.  
  362.     /**
  363.      * 配送業者IDから, 支払い方法, お届け時間の配列を取得する.
  364.      *
  365.      * 結果の連想配列の添字の値は以下の通り
  366.      * - 'arrDelivTime' - お届け時間の配列
  367.      * - 'arrPayment' - 支払い方法の配列
  368.      * - 'img_show' - 支払い方法の画像の有無
  369.      *
  370.      * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
  371.      * @param SC_CartSession $objCartSess SC_CartSession インスタンス
  372.      * @param integer $deliv_id 配送業者ID
  373.      * @return array 支払い方法, お届け時間を格納した配列
  374.      */
  375.     function getSelectedDeliv(&$objPurchase&$objCartSess$deliv_id{
  376.         $arrResults array();
  377.         $arrResults['arrDelivTime'$objPurchase->getDelivTime($deliv_id);
  378.         $total $objCartSess->getAllProductsTotal($objCartSess->getKey(),
  379.                                                    $deliv_id);
  380.         $arrResults['arrPayment'$objPurchase->getPaymentsByPrice($total,
  381.                                                                      $deliv_id);
  382.         $arrResults['img_show'$this->hasPaymentImage($arrResults['arrPayment']);
  383.         return $arrResults;
  384.     }
  385.  
  386.     /**
  387.      * 支払い方法の画像があるかどうか.
  388.      *
  389.      * @param array $arrPayment 支払い方法の配列
  390.      * @return boolean 支払い方法の画像がある場合 true
  391.      */
  392.     function hasPaymentImage($arrPayment{
  393.         foreach ($arrPayment as $val{
  394.             if (!SC_Utils_Ex::isBlank($val['payment_image'])) {
  395.                 return true;
  396.             }
  397.         }
  398.         return false;
  399.     }
  400.  
  401.     /**
  402.      * 配送業者が1社のみかどうか.
  403.      *
  404.      * @param array $arrDeliv 配送業者の配列
  405.      * @return boolean 配送業者が1社のみの場合 true
  406.      */
  407.     function isSingleDeliv($arrDeliv{
  408.         if (count($arrDeliv== 1{
  409.             return true;
  410.         else {
  411.             return false;
  412.         }
  413.     }
  414.  
  415.     /**
  416.      * 前に戻るボタンの URL を取得する.
  417.      *
  418.      * @param boolean $is_login ユーザーがログインしている場合 true
  419.      * @param integer $product_type_id 商品種別ID
  420.      * @param boolean $is_multiple 複数配送の場合 true
  421.      * @return string 前に戻るボタンの URL
  422.      */
  423.     function getPreviousURL($is_login false$product_type_id$is_multiple{
  424.         if ($is_multiple{
  425.             return MULTIPLE_URLPATH '?from=multiple';
  426.         }
  427.         if ($is_login{
  428.             if ($product_type_id == PRODUCT_TYPE_DOWNLOAD{
  429.                 return CART_URLPATH;
  430.             else {
  431.                 return DELIV_URLPATH;
  432.             }
  433.         else {
  434.             return SHOPPING_URL "?from=nonmember";
  435.         }
  436.     }
  437.  
  438.     /**
  439.      * モバイル用テンプレートのパスを取得する.
  440.      *
  441.      * @param boolean $is_single_deliv 配送業者が1社の場合 true
  442.      * @param string $mode フォームパラメーター 'mode' の文字列
  443.      * @return string モバイル用テンプレートのパス
  444.      */
  445.     function getMobileMainpage($is_single_deliv true$mode{
  446.         switch($mode{
  447.         case 'select_deliv':
  448.             return 'shopping/payment.tpl';
  449.             break;
  450.  
  451.         case 'confirm':
  452.         case 'return':
  453.         default:
  454.             if ($is_single_deliv{
  455.                 return 'shopping/payment.tpl';
  456.             else {
  457.                 return 'shopping/select_deliv.tpl';
  458.             }
  459.         }
  460.     }
  461. }
  462. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:20 +0900 by Seasoft