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

Source for file LC_Page_Mypage_Favorite.php

Documentation is available at LC_Page_Mypage_Favorite.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/mypage/LC_Page_AbstractMypage_Ex.php';
  26.  
  27. /**
  28.  * MyPage のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id: LC_Page_Mypage_Favorite.php 21256 2011-09-25 04:15:51Z Seasoft $
  33.  */
  34. class LC_Page_MyPage_Favorite extends LC_Page_AbstractMypage_Ex {
  35.  
  36.     // {{{ properties
  37.  
  38.     /** ページナンバー */
  39.     var $tpl_pageno;
  40.  
  41.     // }}}
  42.     // {{{ functions
  43.  
  44.     /**
  45.      * Page を初期化する.
  46.      *
  47.      * @return void 
  48.      */
  49.     function init({
  50.         parent::init();
  51.         $this->tpl_subtitle 'お気に入り一覧';
  52.         $this->tpl_mypageno 'favorite';
  53.     }
  54.  
  55.     /**
  56.      * Page のプロセス.
  57.      *
  58.      * @return void 
  59.      */
  60.     function process({
  61.         parent::process();
  62.     }
  63.  
  64.     /**
  65.      * Page のAction.
  66.      *
  67.      * @return void 
  68.      */
  69.     function action({
  70.         $objProduct  new SC_Product_Ex();
  71.         $objCustomer new SC_Customer_Ex();
  72.         $customer_id $objCustomer->getValue('customer_id');
  73.  
  74.         switch ($this->getMode()) {
  75.             case 'delete_favorite':
  76.                 // お気に入り削除
  77.                 $this->lfDeleteFavoriteProduct($customer_idintval($_POST['product_id']));
  78.                 break;
  79.             case 'getList':
  80.                 // スマートフォン版のもっと見るボタン用
  81.                 // ページ送り用
  82.                 if (isset($_POST['pageno'])) {
  83.                     $this->tpl_pageno = intval($_POST['pageno']);
  84.                 }
  85.                 $this->arrFavorite $this->lfGetFavoriteProduct($customer_id$this);
  86.                 $this->arrFavorite $objProduct->setPriceTaxTo($this->arrFavorite);
  87.                 echo SC_Utils_Ex::jsonEncode($this->arrFavorite);
  88.                 exit;
  89.                 break;
  90.         }
  91.  
  92.         // ページ送り用
  93.         if (isset($_POST['pageno'])) {
  94.             $this->tpl_pageno = intval($_POST['pageno']);
  95.         }
  96.         $this->arrFavorite $this->lfGetFavoriteProduct($customer_id$this);
  97.         // 1ページあたりの件数
  98.         $this->dispNumber SEARCH_PMAX;
  99.     }
  100.  
  101.     /**
  102.      * デストラクタ.
  103.      *
  104.      * @return void 
  105.      */
  106.     function destroy({
  107.         parent::destroy();
  108.     }
  109.  
  110.     /**
  111.      * お気に入りを取得する
  112.      *
  113.      * @param mixed $customer_id 
  114.      * @param mixed $objPage 
  115.      * @access private
  116.      * @return array お気に入り商品一覧
  117.      */
  118.     function lfGetFavoriteProduct($customer_id&$objPage{
  119.         $objQuery       SC_Query_Ex::getSingletonInstance();
  120.         $objProduct     new SC_Product_Ex();
  121.  
  122.         $objQuery->setOrder('create_date DESC');
  123.         $arrProductId  $objQuery->getCol('product_id''dtb_customer_favorite_products''customer_id = ?'array($customer_id));
  124.  
  125.         $objQuery       =SC_Query_Ex::getSingletonInstance();
  126.         $objQuery->setWhere($this->lfMakeWhere('alldtl.'$arrProductId));
  127.         $linemax        $objProduct->findProductCount($objQuery);
  128.  
  129.         $objPage->tpl_linemax $linemax;   // 何件が該当しました。表示用
  130.  
  131.         // ページ送りの取得
  132.         $objNavi        new SC_PageNavi_Ex($objPage->tpl_pageno$linemaxSEARCH_PMAX'fnNaviPage'NAVI_PMAX);
  133.         $this->tpl_strnavi $objNavi->strnavi// 表示文字列
  134.         $startno        $objNavi->start_row;
  135.  
  136.         $objQuery       =SC_Query_Ex::getSingletonInstance();
  137.         //$objQuery->setLimitOffset(SEARCH_PMAX, $startno);
  138.         // 取得範囲の指定(開始行番号、行数のセット)
  139.         $arrProductId  array_slice($arrProductId$startnoSEARCH_PMAX);
  140.  
  141.         $where $this->lfMakeWhere(''$arrProductId);
  142.         $where .= ' AND del_flg = 0';
  143.         $objQuery->setWhere($where$arrProductId);
  144.         $arrProducts $objProduct->lists($objQuery);
  145.  
  146.         //取得している並び順で並び替え
  147.         $arrProducts2 array();
  148.         foreach($arrProducts as $item{
  149.             $arrProducts2$item['product_id'] ] $item;
  150.         }
  151.         $arrProductsList array();
  152.         foreach($arrProductId as $product_id{
  153.             $arrProductsList[$arrProducts2[$product_id];
  154.         }
  155.  
  156.         return $arrProductsList;
  157.     }
  158.  
  159.     /* 仕方がない処理。。 */
  160.     function lfMakeWhere ($tablename$arrProductId{
  161.  
  162.         // 取得した表示すべきIDだけを指定して情報を取得。
  163.         $where "";
  164.         if (is_array($arrProductId&& !empty($arrProductId)) {
  165.             $where $tablename 'product_id IN (' implode(','$arrProductId')';
  166.         else {
  167.             // 一致させない
  168.             $where '0<>0';
  169.         }
  170.         // 在庫無し商品の非表示
  171.         if (NOSTOCK_HIDDEN === true{
  172.             $where .= ' AND (stock_max >= 1 OR stock_unlimited_max = 1)';
  173.         }
  174.         return $where;
  175.     }
  176.  
  177.     // お気に入り商品削除
  178.     function lfDeleteFavoriteProduct($customer_id$product_id{
  179.         $objQuery   new SC_Query_Ex();
  180.         $count      $objQuery->count("dtb_customer_favorite_products""customer_id = ? AND product_id = ?"array($customer_id$product_id));
  181.  
  182.         if ($count 0{
  183.             $objQuery->begin();
  184.             $objQuery->delete('dtb_customer_favorite_products'"customer_id = ? AND product_id = ?"array($customer_id$product_id));
  185.             $objQuery->commit();
  186.         }
  187.     }
  188. }

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