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

Revision 22486, 6.3 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
#2044 (無駄な処理を改善する for 2.12.4)

  • 不必要なインスタンス化
  • 不必要な値渡し
  • 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
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
25require_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$
33 */
34class 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        $objCustomer = new SC_Customer_Ex();
71
72        $customer_id = $objCustomer->getValue('customer_id');
73
74        switch ($this->getMode()) {
75            case 'delete_favorite':
76                // お気に入り削除
77                $this->lfDeleteFavoriteProduct($customer_id, intval($_POST['product_id']));
78                break;
79
80            case 'getList':
81                // スマートフォン版のもっと見るボタン用
82                // ページ送り用
83                if (isset($_POST['pageno'])) {
84                    $this->tpl_pageno = intval($_POST['pageno']);
85                }
86                $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this);
87                SC_Product_Ex::setPriceTaxTo($this->arrFavorite);
88
89                echo SC_Utils_Ex::jsonEncode($this->arrFavorite);
90                SC_Response_Ex::actionExit();
91                break;
92
93            default:
94                break;
95        }
96
97        // ページ送り用
98        if (isset($_POST['pageno'])) {
99            $this->tpl_pageno = intval($_POST['pageno']);
100        }
101        $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this);
102        // 1ページあたりの件数
103        $this->dispNumber = SEARCH_PMAX;
104
105
106    }
107
108    /**
109     * デストラクタ.
110     *
111     * @return void
112     */
113    function destroy() {
114        parent::destroy();
115    }
116
117    /**
118     * お気に入りを取得する
119     *
120     * @param mixed $customer_id
121     * @param mixed $objPage
122     * @access private
123     * @return array お気に入り商品一覧
124     */
125    function lfGetFavoriteProduct($customer_id, &$objPage) {
126        $objQuery       = SC_Query_Ex::getSingletonInstance();
127        $objProduct     = new SC_Product_Ex();
128
129        $objQuery->setOrder('f.create_date DESC');
130        $where = 'f.customer_id = ? and p.status = 1';
131        if (NOSTOCK_HIDDEN) {
132            $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))';
133        }
134        $arrProductId  = $objQuery->getCol('f.product_id', 'dtb_customer_favorite_products f inner join dtb_products p using (product_id)', $where, array($customer_id));
135
136        $objQuery       =& SC_Query_Ex::getSingletonInstance();
137        $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProductId));
138        $linemax        = $objProduct->findProductCount($objQuery);
139
140        $objPage->tpl_linemax = $linemax;   // 何件が該当しました。表示用
141
142        // ページ送りの取得
143        $objNavi        = new SC_PageNavi_Ex($objPage->tpl_pageno, $linemax, SEARCH_PMAX, 'fnNaviPage', NAVI_PMAX);
144        $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列
145        $startno        = $objNavi->start_row;
146
147        $objQuery       =& SC_Query_Ex::getSingletonInstance();
148        //$objQuery->setLimitOffset(SEARCH_PMAX, $startno);
149        // 取得範囲の指定(開始行番号、行数のセット)
150        $arrProductId  = array_slice($arrProductId, $startno, SEARCH_PMAX);
151
152        $where = $this->lfMakeWhere('', $arrProductId);
153        $where .= ' AND del_flg = 0';
154        $objQuery->setWhere($where, $arrProductId);
155        $arrProducts = $objProduct->lists($objQuery);
156
157        //取得している並び順で並び替え
158        $arrProducts2 = array();
159        foreach ($arrProducts as $item) {
160            $arrProducts2[$item['product_id']] = $item;
161        }
162        $arrProductsList = array();
163        foreach ($arrProductId as $product_id) {
164            $arrProductsList[] = $arrProducts2[$product_id];
165        }
166
167        // 税込金額を設定する
168        SC_Product_Ex::setIncTaxToProducts($arrProductsList);
169
170        return $arrProductsList;
171    }
172
173    /* 仕方がない処理。。 */
174    function lfMakeWhere($tablename, $arrProductId) {
175
176        // 取得した表示すべきIDだけを指定して情報を取得。
177        $where = '';
178        if (is_array($arrProductId) && !empty($arrProductId)) {
179            $where = $tablename . 'product_id IN (' . implode(',', $arrProductId) . ')';
180        } else {
181            // 一致させない
182            $where = '0<>0';
183        }
184        return $where;
185    }
186
187    // お気に入り商品削除
188    function lfDeleteFavoriteProduct($customer_id, $product_id) {
189        $objQuery =& SC_Query_Ex::getSingletonInstance();
190
191        $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id));
192
193        if ($exists) {
194            $objQuery->delete('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id));
195        }
196    }
197}
Note: See TracBrowser for help on using the repository browser.