Source for file LC_Page_Products_Detail.php

Documentation is available at LC_Page_Products_Detail.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php");
  26.  
  27. if (file_exists(MODULE_PATH . "mdl_gmopg/inc/function.php")) {
  28.     require_once(MODULE_PATH . "mdl_gmopg/inc/function.php");
  29. }
  30. /**
  31.  * 商品詳細 のページクラス.
  32.  *
  33.  * @package Page
  34.  * @author LOCKON CO.,LTD.
  35.  * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $
  36.  */
  37. class LC_Page_Products_Detail extends LC_Page {
  38.  
  39.     /** ステータス */
  40.     var $arrSTATUS;
  41.  
  42.     /** ステータス画像 */
  43.     var $arrSTATUS_IMAGE;
  44.  
  45.     /** 発送予定日 */
  46.     var $arrDELIVERYDATE;
  47.  
  48.     /** おすすめレベル */
  49.     var $arrRECOMMEND;
  50.  
  51.     /** フォームパラメータ */
  52.     var $objFormParam;
  53.  
  54.     /** アップロードファイル */
  55.     var $objUpFile;
  56.  
  57.     // }}}
  58.     // {{{ functions
  59.  
  60.     /**
  61.      * Page を初期化する.
  62.      *
  63.      * @return void 
  64.      */
  65.     function init() {
  66.         parent::init();
  67.         $masterData = new SC_DB_MasterData_Ex();
  68.         $this->arrSTATUS = $masterData->getMasterData("mtb_status");
  69.         $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
  70.         $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
  71.         $this->arrRECOMMEND = $masterData->getMasterData("mtb_recommend");
  72.     }
  73.  
  74.     /**
  75.      * Page のプロセス.
  76.      *
  77.      * @return void 
  78.      */
  79.     function process() {
  80.         $objView = new SC_SiteView();
  81.         $objCustomer = new SC_Customer();
  82.         $objQuery = new SC_Query();
  83.         $objDb = new SC_Helper_DB_Ex();
  84.  
  85.         // レイアウトデザインを取得
  86.         $helper = new SC_Helper_PageLayout_Ex();
  87.         $helper->sfGetPageLayout($this, false, "products/detail.php");
  88.  
  89.         if(isset($_POST['mode']) && $_POST['favorite_product_id'] != "" && $_POST['mode'] == "add_favorite") {
  90.             // 値の正当性チェック
  91.             if(!SC_Utils_Ex::sfIsInt($_POST['favorite_product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $_POST['favorite_product_id'], "del_flg = 0 AND status = 1")) {
  92.                 SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
  93.                 exit;
  94.             } else {
  95.                 $this->arrErr = $this->lfCheckError();
  96.                 if(count($this->arrErr) == 0) {
  97.                     $customer_id = $objCustomer->getValue('customer_id');
  98.                     $this->lfRegistFavoriteProduct($customer_id, $_POST['favorite_product_id']);
  99.                 }
  100.             }
  101.         }
  102.  
  103.         // パラメータ管理クラス
  104.         $this->objFormParam = new SC_FormParam();
  105.         // パラメータ情報の初期化
  106.         $this->lfInitParam();
  107.         // POST値の取得
  108.         $this->objFormParam->setParam($_POST);
  109.  
  110.         // ファイル管理クラス
  111.         $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
  112.         // ファイル情報の初期化
  113.         $this->lfInitFile();
  114.  
  115.         // 管理機能からの確認の場合は、非公開の商品も表示する。
  116.         if(isset($_GET['admin']) && $_GET['admin'] == 'on') {
  117.             SC_Utils_Ex::sfIsSuccess(new SC_Session());
  118.             $status = true;
  119.             $where = "del_flg = 0";
  120.         } else {
  121.             $status = false;
  122.             $where = "del_flg = 0 AND status = 1";
  123.         }
  124.  
  125.         if(isset($_POST['mode']) && $_POST['mode'] != "") {
  126.             $tmp_id = $_POST['product_id'];
  127.         } else {
  128.             $tmp_id = $_GET['product_id'];
  129.         }
  130.  
  131.         // 値の正当性チェック
  132.         if(!SC_Utils_Ex::sfIsInt($_GET['product_id'])
  133.                 || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, $where)) {
  134.             SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
  135.         }
  136.         // ログイン判定
  137.         if($objCustomer->isLoginSuccess()) {
  138.             //お気に入りボタン表示
  139.             $this->tpl_login = true;
  140.  
  141.         /* 閲覧ログ機能は現在未使用
  142.  
  143.             $table = "dtb_customer_reading";
  144.             $where = "customer_id = ? ";
  145.             $arrval[] = $objCustomer->getValue('customer_id');
  146.             //顧客の閲覧商品数
  147.             $rpcnt = $objQuery->count($table, $where, $arrval);
  148.  
  149.             //閲覧数が設定数以下
  150.             if ($rpcnt < CUSTOMER_READING_MAX){
  151.                 //閲覧履歴に新規追加
  152.                 lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
  153.             } else {
  154.                 //閲覧履歴の中で一番古いものを削除して新規追加
  155.                 $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
  156.                 $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
  157.                 $where = "customer_id = ? AND update_date = ? ";
  158.                 $arrval = array($objCustomer->getValue("customer_id"), $old);
  159.                 //削除
  160.                 $objQuery->delete($table, $where, $arrval);
  161.                 //追加
  162.                 lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
  163.             }
  164.         */
  165.         }
  166.  
  167.  
  168.         // 規格選択セレクトボックスの作成
  169.         $this->lfMakeSelect($tmp_id);
  170.  
  171.         // 商品IDをFORM内に保持する。
  172.         $this->tpl_product_id = $tmp_id;
  173.  
  174.         if (!isset($_POST['mode'])) $_POST['mode'] = "";
  175.  
  176.         switch($_POST['mode']) {
  177.         case 'cart':
  178.             // 入力値の変換
  179.             $this->objFormParam->convParam();
  180.             $this->arrErr = $this->lfCheckError();
  181.             if(count($this->arrErr) == 0) {
  182.                 $objCartSess = new SC_CartSession();
  183.                 $classcategory_id1 = $_POST['classcategory_id1'];
  184.                 $classcategory_id2 = $_POST['classcategory_id2'];
  185.  
  186.                 if (!empty($_POST['gmo_oneclick'])) {
  187.                     $objCartSess->delAllProducts();
  188.                 }
  189.  
  190.                 // 規格1が設定されていない場合
  191.                 if(!$this->tpl_classcat_find1) {
  192.                     $classcategory_id1 = '0';
  193.                 }
  194.  
  195.                 // 規格2が設定されていない場合
  196.                 if(!$this->tpl_classcat_find2) {
  197.                     $classcategory_id2 = '0';
  198.                 }
  199.  
  200.                 $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
  201.                 $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
  202.  
  203.                 if (!empty($_POST['gmo_oneclick'])) {
  204.                     $objSiteSess = new SC_SiteSession;
  205.                     $objSiteSess->setRegistFlag();
  206.                     $objCartSess->saveCurrentCart($objSiteSess->getUniqId());
  207.  
  208.                     $this->sendRedirect($this->getLocation(
  209.                         URL_DIR . 'user_data/gmopg_oneclick_confirm.php', array(), true));
  210.                     exit;
  211.                 }
  212.  
  213.                 $this->sendRedirect($this->getLocation(URL_CART_TOP));
  214.                 exit;
  215.             }
  216.             break;
  217.  
  218.         default:
  219.             break;
  220.         }
  221.  
  222.         $objQuery = new SC_Query();
  223.         // DBから商品情報を取得する。
  224.         $arrRet = $objQuery->select("*, (SELECT count(*) FROM dtb_customer_favorite_products WHERE product_id = alldtl.product_id AND customer_id = ?) AS favorite_count", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($objCustomer->getValue('customer_id'), $tmp_id));
  225.         $this->arrProduct = $arrRet[0];
  226.  
  227.         // 商品コードの取得
  228.         $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
  229.         $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
  230.         $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
  231.         $this->arrProductCode = $arrProductCode["product_code"];
  232.  
  233.         // 購入制限数を取得
  234.         if($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
  235.           $this->tpl_sale_limit = SALE_LIMIT_MAX;
  236.         } else {
  237.           $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
  238.         }
  239.         
  240.         // サブタイトルを取得
  241.         $this->tpl_subtitle = $this->arrProduct['name'];
  242.         
  243.         // 関連カテゴリを取得
  244.         $this->arrRelativeCat = $objDb->sfGetMultiCatTree($tmp_id);
  245.         
  246.         // 画像ファイル指定がない場合の置換処理
  247.         $this->arrProduct['main_list_image']
  248.             = SC_Utils_Ex::sfNoImageMainList($this->arrProduct['main_list_image']);
  249.         $this->arrProduct['main_image']
  250.             = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
  251.         
  252.         $this->lfSetFile();
  253.         // 支払方法の取得
  254.         $this->arrPayment = $this->lfGetPayment();
  255.         // 入力情報を渡す
  256.         $this->arrForm = $this->objFormParam->getFormParamList();
  257.         //レビュー情報の取得
  258.         $this->arrReview = $this->lfGetReviewData($tmp_id);
  259.         // トラックバック情報の取得
  260.  
  261.         // トラックバック機能の稼働状況チェック
  262.         if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
  263.             $this->arrTrackbackView = "OFF";
  264.         } else {
  265.             $this->arrTrackbackView = "ON";
  266.             $this->arrTrackback = $this->lfGetTrackbackData($tmp_id);
  267.         }
  268.         $this->trackback_url = TRACKBACK_TO_URL . $tmp_id;
  269.         //関連商品情報表示
  270.         $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
  271.         //この商品を買った人はこんな商品も買っています
  272.         $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
  273.  
  274.         // 拡大画像のウィンドウサイズをセット
  275.         if (isset($this->arrFile["main_large_image"])) {
  276.             $image_path = IMAGE_SAVE_DIR . basename($this->arrFile["main_large_image"]["filepath"]);
  277.         } else {
  278.             $image_path = "";
  279.         }
  280.  
  281.         list($large_width, $large_height) = getimagesize($image_path);
  282.         $this->tpl_large_width = $large_width + 60;
  283.         $this->tpl_large_height = $large_height + 80;
  284.  
  285.         $this->lfConvertParam();
  286.  
  287.         $objView->assignobj($this);
  288.         $objView->display(SITE_FRAME);
  289.     }
  290.  
  291.     /**
  292.      * デストラクタ.
  293.      *
  294.      * @return void 
  295.      */
  296.     function destroy() {
  297.         parent::destroy();
  298.     }
  299.  
  300.     /**
  301.      * モバイルページを初期化する.
  302.      *
  303.      * @return void 
  304.      */
  305.     function mobileInit() {
  306.         $this->init();
  307.         $this->tpl_mainpage = "products/detail.tpl";
  308.     }
  309.  
  310.     /**
  311.      * Page のプロセス(モバイル).
  312.      *
  313.      * FIXME 要リファクタリング
  314.      *
  315.      * @return void 
  316.      */
  317.     function mobileProcess() {
  318.         $objView = new SC_MobileView();
  319.         $objCustomer = new SC_Customer();
  320.         $objQuery = new SC_Query();
  321.         $objDb = new SC_Helper_DB_Ex();
  322.  
  323.         // パラメータ管理クラス
  324.         $this->objFormParam = new SC_FormParam();
  325.         // パラメータ情報の初期化
  326.         $this->lfInitParam();
  327.         // POST値の取得
  328.         $this->objFormParam->setParam($_POST);
  329.  
  330.         // ファイル管理クラス
  331.         $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
  332.         // ファイル情報の初期化
  333.         $this->lfInitFile();
  334.  
  335.         if (!isset($_POST['mode'])) $_POST['mode'] = "";
  336.  
  337.         if(!empty($_POST['mode'])) {
  338.             $tmp_id = $_POST['product_id'];
  339.         } else {
  340.             $tmp_id = $_GET['product_id'];
  341.         }
  342.  
  343.         // 値の正当性チェック
  344.         if(!SC_Utils_Ex::sfIsInt($tmp_id)
  345.                 || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, 'del_flg = 0 AND status = 1')) {
  346.             SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
  347.         }
  348.  
  349.         // ログイン判定
  350.         if($objCustomer->isLoginSuccess(true)) {
  351.             //お気に入りボタン表示
  352.             $this->tpl_login = true;
  353.  
  354.             /* 閲覧ログ機能は現在未使用
  355.  
  356.                $table = "dtb_customer_reading";
  357.                $where = "customer_id = ? ";
  358.                $arrval[] = $objCustomer->getValue('customer_id');
  359.                //顧客の閲覧商品数
  360.                $rpcnt = $objQuery->count($table, $where, $arrval);
  361.  
  362.                //閲覧数が設定数以下
  363.                if ($rpcnt < CUSTOMER_READING_MAX){
  364.                //閲覧履歴に新規追加
  365.                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
  366.                } else {
  367.                //閲覧履歴の中で一番古いものを削除して新規追加
  368.                $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
  369.                $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
  370.                $where = "customer_id = ? AND update_date = ? ";
  371.                $arrval = array($objCustomer->getValue("customer_id"), $old);
  372.                //削除
  373.                $objQuery->delete($table, $where, $arrval);
  374.                //追加
  375.                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
  376.                }
  377.             */
  378.         }
  379.  
  380.  
  381.         // 規格選択セレクトボックスの作成
  382.         $this->lfMakeSelectMobile($this, $tmp_id);
  383.  
  384.         // 商品IDをFORM内に保持する。
  385.         $this->tpl_product_id = $tmp_id;
  386.  
  387.         switch($_POST['mode']) {
  388.         case 'select':
  389.             // 規格1が設定されている場合
  390.             if($this->tpl_classcat_find1) {
  391.                 // templateの変更
  392.                 $this->tpl_mainpage = "products/select_find1.tpl";
  393.                 break;
  394.             }
  395.  
  396.         case 'select2':
  397.             $this->arrErr = $this->lfCheckError();
  398.  
  399.             // 規格1が設定されている場合
  400.             if($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
  401.                 // templateの変更
  402.                 $this->tpl_mainpage = "products/select_find1.tpl";
  403.                 break;
  404.             }
  405.  
  406.             // 規格2が設定されている場合
  407.             if($this->tpl_classcat_find2) {
  408.                 $this->arrErr = array();
  409.  
  410.                 $this->tpl_mainpage = "products/select_find2.tpl";
  411.                 break;
  412.             }
  413.  
  414.         case 'selectItem':
  415.             $this->arrErr = $this->lfCheckError();
  416.  
  417.             // 規格1が設定されている場合
  418.             if($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
  419.                 // templateの変更
  420.                 $this->tpl_mainpage = "products/select_find2.tpl";
  421.                 break;
  422.             }
  423.             // 商品数の選択を行う
  424.             $this->tpl_mainpage = "products/select_item.tpl";
  425.             break;
  426.  
  427.         case 'cart':
  428.             // 入力値の変換
  429.             $this->objFormParam->convParam();
  430.             $this->arrErr = $this->lfCheckError();
  431.             if(count($this->arrErr) == 0) {
  432.                 $objCartSess = new SC_CartSession();
  433.                 $classcategory_id1 = $_POST['classcategory_id1'];
  434.                 $classcategory_id2 = $_POST['classcategory_id2'];
  435.  
  436.                 // 規格1が設定されていない場合
  437.                 if(!$this->tpl_classcat_find1) {
  438.                     $classcategory_id1 = '0';
  439.                 }
  440.  
  441.                 // 規格2が設定されていない場合
  442.                 if(!$this->tpl_classcat_find2) {
  443.                     $classcategory_id2 = '0';
  444.                 }
  445.  
  446.                 $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
  447.                 $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
  448.                 $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true);
  449.                 exit;
  450.             }
  451.             break;
  452.  
  453.         default:
  454.             break;
  455.         }
  456.  
  457.         $objQuery = new SC_Query();
  458.         // DBから商品情報を取得する。
  459.         $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id));
  460.         $this->arrProduct = $arrRet[0];
  461.  
  462.         // 商品コードの取得
  463.         $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
  464.         $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
  465.         $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
  466.         $this->arrProductCode = $arrProductCode["product_code"];
  467.  
  468.         // 購入制限数を取得
  469.         if($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
  470.             $this->tpl_sale_limit = SALE_LIMIT_MAX;
  471.         } else {
  472.             $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
  473.         }
  474.  
  475.         // サブタイトルを取得
  476.         $this->tpl_subtitle = $this->arrProduct["name"];
  477.         
  478.         // 画像ファイル指定がない場合の置換処理
  479.         $this->arrProduct['main_list_image']
  480.             = SC_Utils_Ex::sfNoImageMainList($this->arrProduct['main_list_image']);
  481.         $this->arrProduct['main_image']
  482.             = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
  483.         
  484.         // ファイル情報のセット
  485.         $this->lfSetFile();
  486.         // 支払方法の取得
  487.         $this->arrPayment = $this->lfGetPayment();
  488.         // 入力情報を渡す
  489.         $this->arrForm = $this->objFormParam->getFormParamList();
  490.         //レビュー情報の取得
  491.         $this->arrReview = $this->lfGetReviewData($tmp_id);
  492.         // タイトルに商品名を入れる
  493.         $this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
  494.         //関連商品情報表示
  495.         $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
  496.         //この商品を買った人はこんな商品も買っています
  497.         $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
  498.  
  499.         // 拡大画像のウィンドウサイズをセット
  500.         if (!empty($this->arrFile["main_large_image"])) {
  501.             list($large_width, $large_height) = getimagesize(IMAGE_SAVE_DIR . basename($this->arrFile["main_large_image"]["filepath"]));
  502.         }
  503.         $this->tpl_large_width = isset($large_width) ? $large_width + 60 : 0;
  504.         $this->tpl_large_height = isset($large_height) ? $large_height + 80 : 0;
  505.  
  506.         $objView->assignobj($this);
  507.         $objView->display(SITE_FRAME);
  508.     }
  509.  
  510.     /* ファイル情報の初期化 */
  511.     function lfInitFile() {
  512.         $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg','gif'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
  513.         $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
  514.         $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg'), IMAGE_SIZE, false, LARGE_IMAGE_HEIGHT, LARGE_IMAGE_HEIGHT);
  515.         for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
  516.             $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);
  517.             $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg'), IMAGE_SIZE, false, LARGE_SUBIMAGE_HEIGHT, LARGE_SUBIMAGE_HEIGHT);
  518.         }
  519.         $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg'), IMAGE_SIZE, false, NORMAL_IMAGE_HEIGHT, NORMAL_IMAGE_HEIGHT);
  520.         $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
  521.     }
  522.  
  523.     /* 規格選択セレクトボックスの作成 */
  524.     function lfMakeSelect($product_id) {
  525.  
  526.         $objDb = new SC_Helper_DB_Ex();
  527.         $classcat_find1 = false;
  528.         $classcat_find2 = false;
  529.         // 在庫ありの商品の有無
  530.         $stock_find = false;
  531.  
  532.         // 規格名一覧
  533.         $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
  534.         // 規格分類名一覧
  535.         $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
  536.         // 商品規格情報の取得
  537.         $arrProductsClass = $this->lfGetProductsClass($product_id);
  538.  
  539.         // 規格1クラス名の取得
  540.         $this->tpl_class_name1 = isset($arrClassName[$arrProductsClass[0]['class_id1']])
  541.                                         ? $arrClassName[$arrProductsClass[0]['class_id1']] : "";
  542.         // 規格2クラス名の取得
  543.         $this->tpl_class_name2 = isset($arrClassName[$arrProductsClass[0]['class_id2']])
  544.                                         ? $arrClassName[$arrProductsClass[0]['class_id2']] : "";
  545.  
  546.         // すべての組み合わせ数
  547.         $count = count($arrProductsClass);
  548.  
  549.         $classcat_id1 = "";
  550.  
  551.         $arrSele = array();
  552.         $arrList = array();
  553.  
  554.         $list_id = 0;
  555.         $arrList[0] = "\tlist0 = new Array('選択してください'";
  556.         $arrVal[0] = "\tval0 = new Array(''";
  557.  
  558.         for ($i = 0; $i < $count; $i++) {
  559.             // 在庫のチェック
  560.             if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
  561.                 continue;
  562.             }
  563.  
  564.             $stock_find = true;
  565.  
  566.             // 規格1のセレクトボックス用
  567.             if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
  568.                 $arrList[$list_id].=");\n";
  569.                 $arrVal[$list_id].=");\n";
  570.                 $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
  571.                 $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
  572.                 $list_id++;
  573.             }
  574.  
  575.             // 規格2のセレクトボックス用
  576.             $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
  577.  
  578.             // セレクトボックス表示値
  579.             if (!isset($arrList[$list_id])) $arrList[$list_id] = "";
  580.             if($arrList[$list_id] == "") {
  581.                 $arrList[$list_id] = "\tlist".$list_id." = new Array('選択してください', '".$arrClassCatName[$classcat_id2]."'";
  582.             } else {
  583.                 $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
  584.             }
  585.  
  586.             // セレクトボックスPOST値
  587.             if (!isset($arrVal[$list_id])) $arrVal[$list_id] = "";
  588.             if($arrVal[$list_id] == "") {
  589.                 $arrVal[$list_id] = "\tval".$list_id." = new Array('', '".$classcat_id2."'";
  590.             } else {
  591.                 $arrVal[$list_id].= ", '".$classcat_id2."'";
  592.             }
  593.         }
  594.  
  595.         $arrList[$list_id].=");\n";
  596.         $arrVal[$list_id].=");\n";
  597.  
  598.         // 規格1
  599.         $this->arrClassCat1 = $arrSele;
  600.  
  601.         $lists = "\tlists = new Array(";
  602.         $no = 0;
  603.  
  604.         foreach($arrList as $val) {
  605.             $this->tpl_javascript.= $val;
  606.             if ($no != 0) {
  607.                 $lists.= ",list".$no;
  608.             } else {
  609.                 $lists.= "list".$no;
  610.             }
  611.             $no++;
  612.         }
  613.         $this->tpl_javascript.=$lists.");\n";
  614.  
  615.         $vals = "\tvals = new Array(";
  616.         $no = 0;
  617.  
  618.         foreach($arrVal as $val) {
  619.             $this->tpl_javascript.= $val;
  620.             if ($no != 0) {
  621.                 $vals.= ",val".$no;
  622.             } else {
  623.                 $vals.= "val".$no;
  624.             }
  625.             $no++;
  626.         }
  627.         $this->tpl_javascript.=$vals.");\n";
  628.  
  629.         // 選択されている規格2ID
  630.         if (!isset($_POST['classcategory_id2'])) $_POST['classcategory_id2'] = "";
  631.         $this->tpl_onload = "lnSetSelect('form1', 'classcategory_id1', 'classcategory_id2', '" . htmlspecialchars($_POST['classcategory_id2'], ENT_QUOTES) . "');";
  632.  
  633.         // 規格1が設定されている
  634.         if($arrProductsClass[0]['classcategory_id1'] != '0') {
  635.             $classcat_find1 = true;
  636.         }
  637.  
  638.         // 規格2が設定されている
  639.         if($arrProductsClass[0]['classcategory_id2'] != '0') {
  640.             $classcat_find2 = true;
  641.         }
  642.  
  643.         $this->tpl_classcat_find1 = $classcat_find1;
  644.         $this->tpl_classcat_find2 = $classcat_find2;
  645.         $this->tpl_stock_find = $stock_find;
  646.     }
  647.  
  648.     /* 規格選択セレクトボックスの作成
  649.      * FIXME 要リファクタリング
  650.      */
  651.     function lfMakeSelectMobile(&$objPage, $product_id) {
  652.  
  653.         $objDb = new SC_Helper_DB_Ex();
  654.         $classcat_find1 = false;
  655.         $classcat_find2 = false;
  656.         // 在庫ありの商品の有無
  657.         $stock_find = false;
  658.  
  659.         // 規格名一覧
  660.         $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
  661.         // 規格分類名一覧
  662.         $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
  663.         // 商品規格情報の取得
  664.         $arrProductsClass = $this->lfGetProductsClass($product_id);
  665.  
  666.         // 規格1クラス名の取得
  667.         $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
  668.         // 規格2クラス名の取得
  669.         $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
  670.  
  671.         // すべての組み合わせ数
  672.         $count = count($arrProductsClass);
  673.  
  674.         $classcat_id1 = "";
  675.  
  676.         $arrSele1 = array();
  677.         $arrSele2 = array();
  678.  
  679.         for ($i = 0; $i < $count; $i++) {
  680.             // 在庫のチェック
  681.             if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
  682.                 continue;
  683.             }
  684.  
  685.             $stock_find = true;
  686.  
  687.             // 規格1のセレクトボックス用
  688.             if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
  689.                 $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
  690.                 $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
  691.             }
  692.  
  693.             // 規格2のセレクトボックス用
  694.             if($arrProductsClass[$i]['classcategory_id1'] == $_POST['classcategory_id1'] and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
  695.                 $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
  696.                 $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
  697.             }
  698.         }
  699.  
  700.         // 規格1
  701.         $objPage->arrClassCat1 = $arrSele1;
  702.         $objPage->arrClassCat2 = $arrSele2;
  703.  
  704.         // 規格1が設定されている
  705.         if($arrProductsClass[0]['classcategory_id1'] != '0') {
  706.             $classcat_find1 = true;
  707.         }
  708.  
  709.         // 規格2が設定されている
  710.         if($arrProductsClass[0]['classcategory_id2'] != '0') {
  711.             $classcat_find2 = true;
  712.         }
  713.  
  714.         $objPage->tpl_classcat_find1 = $classcat_find1;
  715.         $objPage->tpl_classcat_find2 = $classcat_find2;
  716.         $objPage->tpl_stock_find = $stock_find;
  717.     }
  718.  
  719.     /* パラメータ情報の初期化 */
  720.     function lfInitParam() {
  721.         $this->objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
  722.         $this->objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
  723.         $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
  724.     }
  725.  
  726.     /* 商品規格情報の取得 */
  727.     function lfGetProductsClass($product_id) {
  728.         $arrRet = array();
  729.         if(SC_Utils_Ex::sfIsInt($product_id)) {
  730.             // 商品規格取得
  731.             $objQuery = new SC_Query();
  732.             $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
  733.             $table = "vw_product_class AS prdcls";
  734.             $where = "product_id = ?";
  735.             $objQuery->setorder("rank1 DESC, rank2 DESC");
  736.             $arrRet = $objQuery->select($col, $table, $where, array($product_id));
  737.         }
  738.         return $arrRet;
  739.     }
  740.  
  741.     /* 登録済み関連商品の読み込み */
  742.     function lfPreGetRecommendProducts($product_id) {
  743.         $arrRecommend = array();
  744.         $objQuery = new SC_Query();
  745.         $objQuery->setorder("rank DESC");
  746.         $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
  747.         $max = count($arrRet);
  748.         $no = 0;
  749.         $from = "vw_products_allclass AS T1 "
  750.                 . " JOIN ("
  751.                 . " SELECT max(T2.rank) AS product_rank, "
  752.                 . "        T2.product_id"
  753.                 . "   FROM dtb_product_categories T2  "
  754.                 . " GROUP BY product_id) AS T3 USING (product_id)";
  755.         $objQuery->setorder("T3.product_rank DESC");
  756.         for($i = 0; $i < $max; $i++) {
  757.             $where = "del_flg = 0 AND T3.product_id = ? AND status = 1";
  758.             $arrProductInfo = $objQuery->select("DISTINCT main_list_image, price02_min, price02_max, price01_min, price01_max, name, point_rate, T3.product_rank", $from, $where, array($arrRet[$i]['recommend_product_id']));
  759.  
  760.             if(count($arrProductInfo) > 0) {
  761.                 $arrRecommend[$no] = $arrProductInfo[0];
  762.                 $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
  763.                 $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
  764.                 $no++;
  765.             }
  766.         }
  767.         return $arrRecommend;
  768.     }
  769.  
  770.     /* 入力内容のチェック */
  771.     function lfCheckError() {
  772.         if ($_POST['mode'] == "add_favorite") {
  773.             $objCustomer = new SC_Customer();
  774.             $objErr = new SC_CheckError();
  775.             $customer_id = $objCustomer->getValue('customer_id');
  776.             if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
  777.                 $objErr->arrErr['add_favorite'.$favorite_product_id] = "※ この商品は既にお気に入りに追加されています。<br />";
  778.             }
  779.         } else {
  780.             // 入力データを渡す。
  781.             $arrRet =  $this->objFormParam->getHashArray();
  782.             $objErr = new SC_CheckError($arrRet);
  783.             $objErr->arrErr = $this->objFormParam->checkError();
  784.  
  785.             // 複数項目チェック
  786.             if ($this->tpl_classcat_find1) {
  787.                 $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
  788.             }
  789.             if ($this->tpl_classcat_find2) {
  790.                 $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
  791.             }
  792.         }
  793.  
  794.         return $objErr->arrErr;
  795.     }
  796.  
  797.     //閲覧履歴新規登録
  798.     function lfRegistReadingData($tmp_id, $customer_id){
  799.         $objQuery = new SC_Query;
  800.         $sqlval['customer_id'] = $customer_id;
  801.         $sqlval['reading_product_id'] = $tmp_id;
  802.         $sqlval['create_date'] = 'NOW()';
  803.         $sqlval['update_date'] = 'NOW()';
  804.         $objQuery->insert("dtb_customer_reading", $sqlval);
  805.     }
  806.  
  807.     //この商品を買った人はこんな商品も買っています FIXME
  808.     function lfGetRelateProducts($tmp_id) {
  809.         $objQuery = new SC_Query;
  810.         //自動抽出
  811.         $objQuery->setorder("random()");
  812.         //表示件数の制限
  813.         $objQuery->setlimit(RELATED_PRODUCTS_MAX);
  814.         //検索条件
  815.         $col = "name, main_list_image, price01_min, price02_min, price01_max, price02_max, point_rate";
  816.         $from = "vw_products_allclass AS allcls ";
  817.         $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? ";
  818.         $arrval[] = $tmp_id;
  819.         //結果の取得
  820.         $arrProducts = $objQuery->select($col, $from, $where, $arrval);
  821.  
  822.         return $arrProducts;
  823.     }
  824.  
  825.     //商品ごとのレビュー情報を取得する
  826.     function lfGetReviewData($id) {
  827.         $objQuery = new SC_Query;
  828.         //商品ごとのレビュー情報を取得する
  829.         $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
  830.         $from = "dtb_review";
  831.         $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
  832.         $arrval[] = $id;
  833.         $arrReview = $objQuery->select($col, $from, $where, $arrval);
  834.         return $arrReview;
  835.     }
  836.  
  837.     /*
  838.      * 商品ごとのトラックバック情報を取得する
  839.      *
  840.      * @param $product_id
  841.      * @return $arrTrackback
  842.      */
  843.     function lfGetTrackbackData($product_id) {
  844.  
  845.         $arrTrackback = array();
  846.  
  847.         $objQuery = new SC_Query;
  848.         //商品ごとのトラックバック情報を取得する
  849.         $col = "blog_name, url, title, excerpt, title, create_date";
  850.         $from = "dtb_trackback";
  851.         $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
  852.         $arrval[] = $product_id;
  853.         $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
  854.         return $arrTrackback;
  855.     }
  856.  
  857.     //支払方法の取得
  858.     //payment_id    1:クレジット 2:ショッピングローン
  859.     function lfGetPayment() {
  860.         $objQuery = new SC_Query;
  861.         $col = "payment_id, rule, payment_method";
  862.         $from = "dtb_payment";
  863.         $where = "del_flg = 0";
  864.         $order = "payment_id";
  865.         $objQuery->setorder($order);
  866.         $arrRet = $objQuery->select($col, $from, $where);
  867.         return $arrRet;
  868.     }
  869.  
  870.     function lfConvertParam() {
  871.         if (!isset($this->arrForm['quantity']['value'])) $this->arrForm['quantity']['value'] = "";
  872.         $value = $this->arrForm['quantity']['value'];
  873.         $this->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
  874.     }
  875.  
  876.     /*
  877.      * ファイルの情報をセットする
  878.      *
  879.      */
  880.     function lfSetFile() {
  881.         // DBからのデータを引き継ぐ
  882.         $this->objUpFile->setDBFileList($this->arrProduct);
  883.         // ファイル表示用配列を渡す
  884.         $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
  885.  
  886.         // サブ画像の有無を判定
  887.         $this->subImageFlag = false;
  888.         for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
  889.             if ($this->arrFile["sub_image" . $i]["filepath"] != "") {
  890.                 $this->subImageFlag = true;
  891.             }
  892.         }
  893.     }
  894.  
  895.     /*
  896.      * お気に入り商品登録
  897.      */
  898.     function lfRegistFavoriteProduct($customer_id, $product_id) {
  899.         $objQuery = new SC_Query();
  900.         $objConn = new SC_DbConn();
  901.         $count = $objConn->getOne("SELECT COUNT(*) FROM dtb_customer_favorite_products WHERE customer_id = ? AND product_id = ?", array($customer_id, $product_id));
  902.  
  903.         if ($count == 0) {
  904.             $sqlval['customer_id'] = $customer_id;
  905.             $sqlval['product_id'] = $product_id;
  906.  
  907.             $objQuery->begin();
  908.             $objQuery->insert('dtb_customer_favorite_products', $sqlval);
  909.             $objQuery->commit();
  910.         }
  911.     }
  912.  
  913. }
  914. ?>

Documentation generated on Tue, 28 Apr 2009 18:12:41 +0900 by phpDocumentor 1.4.2