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

Revision 23230, 6.4 KB checked in by m_uehara, 11 years ago (diff)

#2363 r23177, r23181 - r23186, r23188 - r23191, r23194, r23197, r23199 - r23218, r23220, r23223 - r23225 をマージ

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