source: branches/version-2_13-dev/data/class/pages/mypage/LC_Page_Mypage_Favorite.php @ 23066

Revision 23066, 6.1 KB checked in by pineray, 11 years ago (diff)

#2342 JavaScript?のグローバルな宣言を減らす
eccubeオブジェクト内の階層を減らす.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[17162]1<?php
2/*
3 * This file is part of EC-CUBE
4 *
[22206]5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
[17162]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
[20534]24require_once CLASS_EX_REALDIR . 'page_extends/mypage/LC_Page_AbstractMypage_Ex.php';
[17162]25
26/**
27 * MyPage のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
[20116]31 * @version $Id$
[17162]32 */
[23038]33class LC_Page_Mypage_Favorite extends LC_Page_AbstractMypage_Ex
[22567]34{
[17162]35    /** ページナンバー */
36    var $tpl_pageno;
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
[22567]43    function init()
44    {
[17162]45        parent::init();
[17519]46        $this->tpl_subtitle = 'お気に入り一覧';
[17162]47        $this->tpl_mypageno = 'favorite';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
[22567]55    function process()
56    {
[19661]57        parent::process();
58    }
[17162]59
[19661]60    /**
61     * Page のAction.
62     *
63     * @return void
64     */
[22567]65    function action()
66    {
[22486]67        $objCustomer = new SC_Customer_Ex();
[21596]68
[20146]69        $customer_id = $objCustomer->getValue('customer_id');
[20041]70
[20044]71        switch ($this->getMode()) {
[21047]72            case 'delete_favorite':
73                // お気に入り削除
[21128]74                $this->lfDeleteFavoriteProduct($customer_id, intval($_POST['product_id']));
[21047]75                break;
[22486]76
[21047]77            case 'getList':
78                // スマートフォン版のもっと見るボタン用
79                // ページ送り用
[21128]80                if (isset($_POST['pageno'])) {
81                    $this->tpl_pageno = intval($_POST['pageno']);
82                }
83                $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this);
[22486]84                SC_Product_Ex::setPriceTaxTo($this->arrFavorite);
[21596]85
[21128]86                echo SC_Utils_Ex::jsonEncode($this->arrFavorite);
[21743]87                SC_Response_Ex::actionExit();
[21047]88                break;
[22486]89
90            default:
91                break;
[17162]92        }
93
[18069]94        // ページ送り用
[17162]95        if (isset($_POST['pageno'])) {
[21128]96            $this->tpl_pageno = intval($_POST['pageno']);
[17162]97        }
[20146]98        $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this);
[21047]99        // 1ページあたりの件数
100        $this->dispNumber = SEARCH_PMAX;
[20146]101    }
[17162]102
[20146]103    /**
104     * お気に入りを取得する
105     *
106     * @param mixed $customer_id
107     * @param mixed $objPage
108     * @access private
109     * @return array お気に入り商品一覧
110     */
[22567]111    function lfGetFavoriteProduct($customer_id, &$objPage)
112    {
[20507]113        $objQuery       = SC_Query_Ex::getSingletonInstance();
[20487]114        $objProduct     = new SC_Product_Ex();
[17162]115
[22232]116        $objQuery->setOrder('f.create_date DESC');
117        $where = 'f.customer_id = ? and p.status = 1';
[22025]118        if (NOSTOCK_HIDDEN) {
119            $where .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = dtb_customer_favorite_products.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))';
120        }
[22232]121        $arrProductId  = $objQuery->getCol('f.product_id', 'dtb_customer_favorite_products f inner join dtb_products p using (product_id)', $where, array($customer_id));
[17162]122
[20507]123        $objQuery       =& SC_Query_Ex::getSingletonInstance();
[21256]124        $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProductId));
[20146]125        $linemax        = $objProduct->findProductCount($objQuery);
126
127        $objPage->tpl_linemax = $linemax;   // 何件が該当しました。表示用
128
[17162]129        // ページ送りの取得
[23066]130        $objNavi        = new SC_PageNavi_Ex($objPage->tpl_pageno, $linemax, SEARCH_PMAX, 'eccube.movePage', NAVI_PMAX);
[20562]131        $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列
[20146]132        $startno        = $objNavi->start_row;
[17162]133
[20507]134        $objQuery       =& SC_Query_Ex::getSingletonInstance();
[20146]135        //$objQuery->setLimitOffset(SEARCH_PMAX, $startno);
[17162]136        // 取得範囲の指定(開始行番号、行数のセット)
[21256]137        $arrProductId  = array_slice($arrProductId, $startno, SEARCH_PMAX);
[17162]138
[21256]139        $where = $this->lfMakeWhere('', $arrProductId);
[21223]140        $where .= ' AND del_flg = 0';
[21256]141        $objQuery->setWhere($where, $arrProductId);
142        $arrProducts = $objProduct->lists($objQuery);
[17162]143
[20146]144        //取得している並び順で並び替え
145        $arrProducts2 = array();
[21441]146        foreach ($arrProducts as $item) {
[21708]147            $arrProducts2[$item['product_id']] = $item;
[20146]148        }
149        $arrProductsList = array();
[21441]150        foreach ($arrProductId as $product_id) {
[20146]151            $arrProductsList[] = $arrProducts2[$product_id];
152        }
[17162]153
[21708]154        // 税込金額を設定する
155        SC_Product_Ex::setIncTaxToProducts($arrProductsList);
156
[20146]157        return $arrProductsList;
[17162]158    }
159
[20146]160    /* 仕方がない処理。。 */
[22567]161    function lfMakeWhere($tablename, $arrProductId)
162    {
[20146]163        // 取得した表示すべきIDだけを指定して情報を取得。
[21514]164        $where = '';
[21256]165        if (is_array($arrProductId) && !empty($arrProductId)) {
166            $where = $tablename . 'product_id IN (' . implode(',', $arrProductId) . ')';
[20146]167        } else {
168            // 一致させない
169            $where = '0<>0';
170        }
[22856]171
[20146]172        return $where;
[17162]173    }
174
175    // お気に入り商品削除
[22567]176    function lfDeleteFavoriteProduct($customer_id, $product_id)
177    {
[21376]178        $objQuery =& SC_Query_Ex::getSingletonInstance();
[17162]179
[21514]180        $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id));
[21376]181
182        if ($exists) {
[21514]183            $objQuery->delete('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id));
[17162]184        }
185    }
186}
Note: See TracBrowser for help on using the repository browser.