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

Source for file LC_Page_Shopping_Multiple.php

Documentation is available at LC_Page_Shopping_Multiple.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_Multiple.php 21197 2011-08-17 08:42:32Z shutta $
  33.  */
  34. class LC_Page_Shopping_Multiple extends LC_Page_Ex {
  35.  
  36.     // }}}
  37.     // {{{ functions
  38.  
  39.     /**
  40.      * Page を初期化する.
  41.      *
  42.      * @return void 
  43.      */
  44.     function init({
  45.         parent::init();
  46.         $this->tpl_title "お届け先の複数指定";
  47.         $this->httpCacheControl('nocache');
  48.     }
  49.  
  50.     /**
  51.      * Page のプロセス.
  52.      *
  53.      * @return void 
  54.      */
  55.     function process({
  56.         $this->action();
  57.         $this->sendResponse();
  58.     }
  59.  
  60.     /**
  61.      * Page のプロセス.
  62.      *
  63.      * @return void 
  64.      */
  65.     function action({
  66.         $objSiteSess new SC_SiteSession_Ex();
  67.         $objCartSess new SC_CartSession_Ex();
  68.         $objPurchase new SC_Helper_Purchase_Ex();
  69.         $objCustomer new SC_Customer_Ex();
  70.         $objFormParam new SC_FormParam_Ex();
  71.  
  72.         $this->tpl_uniqid $objSiteSess->getUniqId();
  73.  
  74.         $this->addrs $this->getDelivAddrs($objCustomer$objPurchase,
  75.                                             $this->tpl_uniqid);
  76.         $this->tpl_addrmax count($this->addrs);
  77.         $this->lfInitParam($objFormParam);
  78.  
  79.         $objPurchase->verifyChangeCart($this->tpl_uniqid$objCartSess);
  80.  
  81.         switch ($this->getMode()) {
  82.             case 'confirm':
  83.                 $objFormParam->setParam($_POST);
  84.                 $this->arrErr $this->lfCheckError($objFormParam);
  85.                 if (SC_Utils_Ex::isBlank($this->arrErr)) {
  86.                     // フォームの情報を一時保存しておく
  87.                     $_SESSION['multiple_temp'$objFormParam->getHashArray();
  88.                     $this->saveMultipleShippings($this->tpl_uniqid$objFormParam,
  89.                                                  $objCustomer$objPurchase,
  90.                                                  $objCartSess);
  91.                     $objSiteSess->setRegistFlag();
  92.                     SC_Response_Ex::sendRedirect("payment.php");
  93.                     exit;
  94.                 }
  95.                 break;
  96.  
  97.             default:
  98.                 $this->setParamToSplitItems($objFormParam$objCartSess);
  99.         }
  100.  
  101.         // 前のページから戻ってきた場合
  102.         if ($_GET['from'== 'multiple'{
  103.             $objFormParam->setParam($_SESSION['multiple_temp']);
  104.         }
  105.  
  106.         $this->arrForm $objFormParam->getFormParamList();
  107.     }
  108.  
  109.     /**
  110.      * デストラクタ.
  111.      *
  112.      * @return void 
  113.      */
  114.     function destroy({
  115.         parent::destroy();
  116.     }
  117.  
  118.     /**
  119.      * フォームを初期化する.
  120.      *
  121.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  122.      * @return void 
  123.      */
  124.     function lfInitParam(&$objFormParam{
  125.         $objFormParam->addParam("商品規格ID""product_class_id"INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK"));
  126.         $objFormParam->addParam("商品名""name");
  127.         $objFormParam->addParam("規格1""class_name1");
  128.         $objFormParam->addParam("規格2""class_name2");
  129.         $objFormParam->addParam("規格分類1""classcategory_name1");
  130.         $objFormParam->addParam("規格分類2""classcategory_name2");
  131.         $objFormParam->addParam("メイン画像""main_image");
  132.         $objFormParam->addParam("メイン一覧画像""main_list_image");
  133.         $objFormParam->addParam("販売価格""price");
  134.         $objFormParam->addParam("数量"'quantity'INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK")1);
  135.         $objFormParam->addParam("配送先住所"'shipping'INT_LEN'n'array("MAX_LENGTH_CHECK""NUM_CHECK"));
  136.         $objFormParam->addParam("カート番号""cart_no"INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK"));
  137.         $objFormParam->addParam("行数""line_of_num"INT_LEN'n'array("EXIST_CHECK""MAX_LENGTH_CHECK""NUM_CHECK"));
  138.     }
  139.  
  140.     /**
  141.      * カートの商品を数量ごとに分割し, フォームに設定する.
  142.      *
  143.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  144.      * @param SC_CartSession $objCartSess SC_CartSession インスタンス
  145.      * @return void 
  146.      */
  147.     function setParamToSplitItems(&$objFormParam&$objCartSess{
  148.         $cartLists =$objCartSess->getCartList($objCartSess->getKey());
  149.         $arrItems array();
  150.         $index 0;
  151.         foreach (array_keys($cartListsas $key{
  152.             $arrProductsClass $cartLists[$key]['productsClass'];
  153.             $quantity = (int) $cartLists[$key]['quantity'];
  154.             for ($i 0$i $quantity$i++{
  155.                 foreach ($arrProductsClass as $key2 => $val{
  156.                     $arrItems[$key2][$index$val;
  157.                 }
  158.                 $arrItems['quantity'][$index1;
  159.                 $arrItems['price'][$index$cartLists[$key]['price'];
  160.                 $index++;
  161.             }
  162.         }
  163.         $objFormParam->setParam($arrItems);
  164.         $objFormParam->setValue('line_of_num'$index);
  165.     }
  166.  
  167.     /**
  168.      * 配送住所のプルダウン用連想配列を取得する.
  169.      *
  170.      * 会員ログイン済みの場合は, 会員登録住所及び追加登録住所を取得する.
  171.      * 非会員の場合は, 「お届け先の指定」画面で入力した住所を取得する.
  172.      *
  173.      * @param SC_Customer $objCustomer SC_Customer インスタンス
  174.      * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
  175.      * @param integer $uniqid 受注一時テーブルのユニークID
  176.      * @return array 配送住所のプルダウン用連想配列
  177.      */
  178.     function getDelivAddrs(&$objCustomer&$objPurchase$uniqid{
  179.         $masterData new SC_DB_MasterData();
  180.         $arrPref $masterData->getMasterData('mtb_pref');
  181.  
  182.         $arrResults array('' => '選択してください');
  183.         // 会員ログイン時
  184.         if ($objCustomer->isLoginSuccess(true)) {
  185.             $arrAddrs $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
  186.             foreach ($arrAddrs as $val{
  187.                 $other_deliv_id SC_Utils_Ex::isBlank($val['other_deliv_id']$val['other_deliv_id'];
  188.                 $arrResults[$other_deliv_id$val['name01'$val['name02']
  189.                     . " " $arrPref[$val['pref']] $val['addr01'$val['addr02'];
  190.             }
  191.         }
  192.         // 非会員
  193.         else {
  194.             $arrShippings $objPurchase->getShippingTemp();
  195.             foreach ($arrShippings as $shipping_id => $val{
  196.                 $arrResults[$shipping_id$val['shipping_name01'$val['shipping_name02']
  197.                     . " " $arrPref[$val['shipping_pref']]
  198.                     . $val['shipping_addr01'$val['shipping_addr02'];
  199.             }
  200.         }
  201.         return $arrResults;
  202.     }
  203.  
  204.     /**
  205.      * 入力チェックを行う.
  206.      *
  207.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  208.      * @return array エラー情報の配列
  209.      */
  210.     function lfCheckError(&$objFormParam{
  211.         $objCartSess new SC_CartSession_Ex();
  212.  
  213.         $objFormParam->convParam();
  214.         // 数量未入力は0に置換
  215.         $objFormParam->setValue('quantity'$objFormParam->getValue('quantity'0));
  216.  
  217.         $arrErr $objFormParam->checkError();
  218.  
  219.         $arrParams $objFormParam->getSwapArray();
  220.  
  221.         if (empty($arrErr)) {
  222.             foreach ($arrParams as $index => $arrParam{
  223.                 // 数量0で、お届け先を選択している場合
  224.                 if ($arrParam['quantity'== && !SC_Utils_Ex::isBlank($arrParam['shipping'])) {
  225.                     $arrErr['shipping'][$index'※ 数量が0の場合、お届け先を入力できません。<br />';;
  226.                 }
  227.                 // 数量の入力があり、お届け先を選択していない場合
  228.                 if ($arrParam['quantity'&& SC_Utils_Ex::isBlank($arrParam['shipping'])) {
  229.                     $arrErr['shipping'][$index'※ お届け先が入力されていません。<br />';
  230.                 }
  231.             }
  232.         }
  233.  
  234.         // 入力エラーが無い場合、カゴの中身との数量の整合を確認
  235.         if (empty($arrErr)) {
  236.             $arrQuantity array();
  237.             // 入力内容を集計
  238.             foreach ($arrParams as $arrParam{
  239.                 $product_class_id $arrParam['product_class_id'];
  240.                 $arrQuantity[$product_class_id+= $arrParam['quantity'];
  241.             }
  242.             // カゴの中身と突き合わせ
  243.             $cartLists =$objCartSess->getCartList($objCartSess->getKey());
  244.             foreach ($cartLists as $arrCartRow{
  245.                 $product_class_id $arrCartRow['id'];
  246.                 // 差異がある場合、エラーを記録
  247.                 if ($arrCartRow['quantity'!= $arrQuantity[$product_class_id]{
  248.                     foreach ($arrParams as $index => $arrParam{
  249.                         if ($arrParam['product_class_id'== $product_class_id{
  250.                             $arrErr['quantity'][$index'※ 数量合計を「' $arrCartRow['quantity'.'」にしてください。<br />';
  251.                         }
  252.                     }
  253.                 }
  254.             }
  255.         }
  256.         return $arrErr;
  257.     }
  258.  
  259.     /**
  260.      * 複数配送情報を一時保存する.
  261.      *
  262.      * 会員ログインしている場合は, その他のお届け先から住所情報を取得する.
  263.      *
  264.      * @param integer $uniqid 一時受注テーブルのユニークID
  265.      * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  266.      * @param SC_Customer $objCustomer SC_Customer インスタンス
  267.      * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
  268.      * @param SC_CartSession $objCartSess SC_CartSession インスタンス
  269.      * @return void 
  270.      */
  271.     function saveMultipleShippings($uniqid&$objFormParam&$objCustomer,
  272.                                    &$objPurchase&$objCartSess{
  273.         $objQuery =SC_Query_Ex::getSingletonInstance();
  274.  
  275.         $arrParams $objFormParam->getSwapArray();
  276.  
  277.         foreach ($arrParams as $arrParam{
  278.             $other_deliv_id $arrParam['shipping'];
  279.  
  280.             if ($objCustomer->isLoginSuccess(true)) {
  281.                 if ($other_deliv_id != 0{
  282.                     $otherDeliv $objQuery->select("*""dtb_other_deliv",
  283.                                                     "other_deliv_id = ?",
  284.                                                     array($other_deliv_id));
  285.                     foreach ($otherDeliv[0as $key => $val{
  286.                         $arrValues[$other_deliv_id]['shipping_' $key$val;
  287.                     }
  288.                 else {
  289.                     $objPurchase->copyFromCustomer($arrValues[0]$objCustomer,
  290.                                                    'shipping');
  291.                 }
  292.             else {
  293.                 $arrValues $objPurchase->getShippingTemp();
  294.             }
  295.             $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
  296.         }
  297.  
  298.         $objPurchase->clearShipmentItemTemp();
  299.  
  300.         foreach ($arrValues as $shipping_id => $arrVal{
  301.             $objPurchase->saveShippingTemp($arrVal$shipping_id);
  302.         }
  303.  
  304.         foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds{
  305.             foreach ($arrProductClassIds as $product_class_id => $quantity{
  306.                 if ($quantity == 0continue;
  307.                 $objPurchase->setShipmentItemTemp($other_deliv_id,
  308.                                                   $product_class_id,
  309.                                                   $quantity);
  310.             }
  311.         }
  312.  
  313.         // $arrValues[0] には, 購入者の情報が格納されている
  314.         $objPurchase->saveOrderTemp($uniqid$arrValues[0]$objCustomer);
  315.     }
  316. }
  317. ?>

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