source: branches/version-2_5-dev/data/class/pages/rss/LC_Page_Rss_Products.php @ 20107

Revision 20107, 15.9 KB checked in by yomoro, 13 years ago (diff)

#983 リファクタリング VIEWを使わないようにする

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Date Revision
  • 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-2010 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_REALDIR . "pages/LC_Page.php");
26
27/**
28 * RSS(商品) のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Rss_Products extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = "rss/products.tpl";
47        $this->encode = "UTF-8";
48        $this->title = "商品一覧情報";
49    }
50
51    /**
52     * Page のプロセス.
53     *
54     * @return void
55     */
56    function process() {
57        $this->action();
58    }
59
60    /**
61     * Page のアクション.
62     *
63     * @return void
64     */
65    function action() {
66        $objView = new SC_SiteView();
67        $objSiteInfo = new SC_SiteInfo();
68       
69        //店舗情報をセット
70        $this->arrSiteInfo = $objSiteInfo->data;
71       
72        //商品IDを取得
73        if ( isset($_GET['product_id']) && $_GET['product_id'] != '' && is_numeric($_GET['product_id']) ) {
74            $product_id = $_GET['product_id'];
75        } else {
76            $product_id = '';
77        }
78       
79        // モードによって分岐
80        $mode = $this->getMode();
81        switch ($mode) {
82        case 'all':
83            $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
84            break;
85        case 'list':
86            if ( $product_id != '' && is_numeric($product_id) ) {
87                $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
88            } else {
89                $arrProduct = $this->lfGetProductsListData();
90            }
91            break;
92        default:
93            if ( $product_id != '' && is_numeric($product_id) ) {
94                $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
95            } else {
96                $arrProduct = $this->lfGetProductsAllData();
97            }
98            break;
99        }
100       
101        // 商品情報をセット
102        $this->arrProduct = $arrProduct;
103        $this->arrProductKeys = $this->lfGetProductKeys($arrProduct);
104       
105        //セットしたデータをテンプレートファイルに出力
106        $objView->assignobj($this);
107       
108        //キャッシュしない(念のため)
109        header("Pragma: no-cache");
110       
111        //XMLテキスト(これがないと正常にRSSとして認識してくれないツールがあるため)
112        header("Content-type: application/xml");
113        P_DETAIL_URLPATH;
114       
115        //画面表示
116        $objView->display($this->tpl_mainpage, true);
117    }
118
119    /**
120     * デストラクタ.
121     *
122     * @return void
123     */
124    function destroy() {
125        parent::destroy();
126    }
127
128    /**
129     * lfGetProductsDetailData.
130     *
131     * @param str $mode モード
132     * @param str $product_id 商品ID
133     * @return array $arrProduct 商品情報の配列を返す
134     */
135    function lfGetProductsDetailData($mode, $product_id) {
136        $objQuery = SC_Query::getSingletonInstance();
137        //商品詳細を取得
138        if ( $mode == 'all' ) {
139            $arrProduct = $this->lfGetProductsDetail($objQuery, $mode);
140        } else {
141            $arrProduct = $this->lfGetProductsDetail($objQuery, $product_id);
142        }
143        // 値の整形
144        foreach ($arrProduct as $key => $val) {
145            //販売価格を税込みに編集
146            $arrProduct[$key]['price02'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02']);
147            // 画像ファイルのURLセット
148            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image']) ) {
149                $dir = IMAGE_SAVE_RSS_URL;
150            } else {
151                $dir = IMAGE_TEMP_RSS_URL;
152            }
153            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
154            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image']) ){
155                $dir = IMAGE_SAVE_RSS_URL;
156            } else {
157                $dir = IMAGE_TEMP_RSS_URL;
158            }
159            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
160            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image']) ) {
161                $dir = IMAGE_SAVE_RSS_URL;
162            } else {
163                $dir = IMAGE_TEMP_RSS_URL;
164            }
165            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
166            // ポイント計算
167            $arrProduct[$key]['point'] = SC_Utils_Ex::sfPrePoint(
168                $arrProduct[$key]['price02'],
169                $arrProduct[$key]['point_rate'],
170                POINT_RULE,
171                $arrProduct[$key]['product_id']
172            );
173            // 在庫無制限
174            if ( $arrProduct[$key]['stock_unlimited'] == 1 ) {
175                $arrProduct[$key]['stock_unlimited'] = '在庫無制限';
176            } else {
177                $arrProduct[$key]['stock_unlimited'] = NULL;
178            }
179        }
180        return $arrProduct;
181    }
182
183    /**
184     * lfGetProductsListData.
185     *
186     * @return array $arrProduct 商品情報の配列を返す
187     */
188    function lfGetProductsListData() {
189        $objQuery = SC_Query::getSingletonInstance();
190        //商品一覧を取得
191        $arrProduct = $objQuery->getAll('SELECT product_id, name AS product_name FROM dtb_products');
192        return $arrProduct;
193    }
194
195    /**
196     * lfGetProductsAllData.
197     *
198     * @return array $arrProduct 商品情報の配列を返す
199     */
200    function lfGetProductsAllData() {
201        $objQuery = SC_Query::getSingletonInstance();
202        //商品情報を取得
203        $arrProduct = $this->lfGetProductsAllclass($objQuery);
204        // 値の整形
205        foreach ($arrProduct as $key => $val) {
206            //販売価格を税込みに編集
207            $arrProduct[$key]['price02_max'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_max']);
208            $arrProduct[$key]['price02_min'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_min']);
209            // 画像ファイルのURLセット
210            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image']) ) {
211                $dir = IMAGE_SAVE_RSS_URL;
212            } else {
213                $dir = IMAGE_TEMP_RSS_URL;
214            }
215            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
216            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image']) ) {
217                $dir = IMAGE_SAVE_RSS_URL;
218            } else {
219                $dir = IMAGE_TEMP_RSS_URL;
220            }
221            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
222            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image']) ) {
223                $dir = IMAGE_SAVE_RSS_URL;
224            } else {
225                $dir = IMAGE_TEMP_RSS_URL;
226            }
227            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
228            // ポイント計算
229            $arrProduct[$key]['point_max'] = SC_Utils_Ex::sfPrePoint(
230                $arrProduct[$key]['price02_max'],
231                $arrProduct[$key]['point_rate'],
232                POINT_RULE,
233                $arrProduct[$key]['product_id']
234            );
235            $arrProduct[$key]['point_min'] = SC_Utils_Ex::sfPrePoint(
236                $arrProduct[$key]['price02_min'],
237                $arrProduct[$key]['point_rate'],
238                POINT_RULE,
239                $arrProduct[$key]['product_id']
240            );
241        }
242        return $arrProduct;
243    }
244
245    /**
246     * 商品情報を取得する
247     *
248     * @param SC_Query $objQuery DB操作クラス
249     * @param integer $product_id 商品ID
250     * @return array $arrProduct 取得結果を配列で返す
251     */
252    function lfGetProductsDetail(&$objQuery, $product_id = 'all'){
253        $sql = '';
254        $sql .= 'SELECT ';
255        $sql .= '   prod.product_id ';
256        $sql .= '   ,prod.name AS product_name ';
257        $sql .= '   ,prod.category_id ';
258        $sql .= '   ,prod.point_rate ';
259        $sql .= '   ,prod.comment3 ';
260        $sql .= '   ,prod.main_list_comment ';
261        $sql .= '   ,prod.main_list_image ';
262        $sql .= '   ,prod.main_comment ';
263        $sql .= '   ,prod.main_image ';
264        $sql .= '   ,prod.main_large_image ';
265        $sql .= '   ,cls.product_code ';
266        $sql .= '   ,cls.price01 ';
267        $sql .= '   ,cls.price02 ';
268        $sql .= '   ,cls.stock ';
269        $sql .= '   ,cls.stock_unlimited ';
270        $sql .= '   ,cls.classcategory_id1 ';
271        $sql .= '   ,cls.classcategory_id2 ';
272        $sql .= '   ,( ';
273        $sql .= '     SELECT ';
274        $sql .= '        name ';
275        $sql .= '     FROM ';
276        $sql .= '        dtb_classcategory AS clscat ';
277        $sql .= '     WHERE ';
278        $sql .= '        clscat.classcategory_id = cls.classcategory_id1 ';
279        $sql .= '   ) AS classcategory_name1 ';
280        $sql .= '   ,( ';
281        $sql .= '     SELECT ';
282        $sql .= '        name ';
283        $sql .= '     FROM ';
284        $sql .= '        dtb_classcategory AS clscat ';
285        $sql .= '     WHERE ';
286        $sql .= '        clscat.classcategory_id = cls.classcategory_id2 ';
287        $sql .= '   ) AS classcategory_name2 ';
288        $sql .= '   ,( ';
289        $sql .= '     SELECT ';
290        $sql .= '        category_name ';
291        $sql .= '     FROM ';
292        $sql .= '        dtb_category AS cat ';
293        $sql .= '     WHERE ';
294        $sql .= '        cat.category_id = prod.category_id ';
295        $sql .= '   ) AS category_name ';
296        $sql .= '   ,prod.update_date ';
297        $sql .= ' FROM dtb_products AS prod, dtb_products_class AS cls';
298        $sql .= ' WHERE prod.product_id = cls.product_id AND prod.del_flg = 0 AND prod.status = 1';
299
300        if($product_id != 'all'){
301            $sql .= ' AND prod.product_id = ?';
302            $arrval = array($product_id);
303        }
304        $sql .= ' ORDER BY prod.product_id, cls.classcategory_id1, cls.classcategory_id2';
305        $arrProduct = $objQuery->getAll($sql, $arrval);
306        return $arrProduct;
307    }
308
309    /**
310     * 商品情報を取得する(vw_products_allclass使用)
311     *
312     * @param SC_Query $objQuery DB操作クラス
313     * @return array $arrProduct 取得結果を配列で返す
314     */
315    function lfGetProductsAllclass(&$objQuery){
316        $sql = '';
317        $sql .= ' SELECT';
318        $sql .= '     T1.product_id,';
319        $sql .= '     T1.name as product_name,';
320        $sql .= '     T1.maker_id,';
321        $sql .= '     T1.status,';
322        $sql .= '     T1.comment1,';
323        $sql .= '     T1.comment2,';
324        $sql .= '     T1.comment3,';
325        $sql .= '     T1.comment4,';
326        $sql .= '     T1.comment5,';
327        $sql .= '     T1.comment6,';
328        $sql .= '     T1.note,';
329        $sql .= '     T1.main_list_comment,';
330        $sql .= '     T1.main_list_image,';
331        $sql .= '     T1.main_comment,';
332        $sql .= '     T1.main_image,';
333        $sql .= '     T1.main_large_image,';
334        $sql .= '     T1.sub_title1,';
335        $sql .= '     T1.sub_comment1,';
336        $sql .= '     T1.sub_image1,';
337        $sql .= '     T1.sub_large_image1,';
338        $sql .= '     T1.sub_title2,';
339        $sql .= '     T1.sub_comment2,';
340        $sql .= '     T1.sub_image2,';
341        $sql .= '     T1.sub_large_image2,';
342        $sql .= '     T1.sub_title3,';
343        $sql .= '     T1.sub_comment3,';
344        $sql .= '     T1.sub_image3,';
345        $sql .= '     T1.sub_large_image3,';
346        $sql .= '     T1.sub_title4,';
347        $sql .= '     T1.sub_comment4,';
348        $sql .= '     T1.sub_image4,';
349        $sql .= '     T1.sub_large_image4,';
350        $sql .= '     T1.sub_title5,';
351        $sql .= '     T1.sub_comment5,';
352        $sql .= '     T1.sub_image5,';
353        $sql .= '     T1.sub_large_image5,';
354        $sql .= '     T1.sub_title6,';
355        $sql .= '     T1.sub_comment6,';
356        $sql .= '     T1.sub_image6,';
357        $sql .= '     T1.sub_large_image6,';
358        $sql .= '     T1.del_flg,';
359        $sql .= '     T1.creator_id,';
360        $sql .= '     T1.create_date,';
361        $sql .= '     T1.update_date,';
362        $sql .= '     T1.deliv_date_id,';
363        $sql .= '     T4.product_code_min,';
364        $sql .= '     T4.product_code_max,';
365        $sql .= '     T4.price01_min,';
366        $sql .= '     T4.price01_max,';
367        $sql .= '     T4.price02_min,';
368        $sql .= '     T4.price02_max,';
369        $sql .= '     T4.stock_min,';
370        $sql .= '     T4.stock_max,';
371        $sql .= '     T4.stock_unlimited_min,';
372        $sql .= '     T4.stock_unlimited_max,';
373        $sql .= '     T4.class_count,';
374        $sql .= '     T3.rank AS category_rank,';
375        $sql .= '     T2.category_id,';
376        $sql .= '     T2.rank AS product_rank';
377        $sql .= ' FROM';
378        $sql .= '     dtb_products AS T1';
379        $sql .= '     LEFT JOIN';
380        $sql .= '         (';
381        $sql .= '             SELECT';
382        $sql .= '                 product_id,';
383        $sql .= '                 MIN(product_code) AS product_code_min,';
384        $sql .= '                 MAX(product_code) AS product_code_max,';
385        $sql .= '                 MIN(price01) AS price01_min,';
386        $sql .= '                 MAX(price01) AS price01_max,';
387        $sql .= '                 MIN(price02) AS price02_min,';
388        $sql .= '                 MAX(price02) AS price02_max,';
389        $sql .= '                 MIN(stock) AS stock_min,';
390        $sql .= '                 MAX(stock) AS stock_max,';
391        $sql .= '                 MIN(stock_unlimited) AS stock_unlimited_min,';
392        $sql .= '                 MAX(stock_unlimited) AS stock_unlimited_max,';
393        $sql .= '                 COUNT(*) as class_count';
394        $sql .= '             FROM';
395        $sql .= '                 dtb_products_class';
396        $sql .= '             GROUP BY';
397        $sql .= '                 product_id';
398        $sql .= '         ) AS T4';
399        $sql .= '     ON';
400        $sql .= '         T1.product_id = T4.product_id';
401        $sql .= '     LEFT JOIN';
402        $sql .= '         dtb_product_categories AS T2';
403        $sql .= '     ON';
404        $sql .= '         T1.product_id = T2.product_id';
405        $sql .= '     LEFT JOIN';
406        $sql .= '         dtb_category AS T3';
407        $sql .= '     ON';
408        $sql .= '         T2.category_id = T3.category_id';
409        $sql .= ' WHERE';
410        $sql .= '     T1.del_flg = 0 AND T1.status = 1 ';
411       
412        // 在庫無し商品の非表示
413        if (NOSTOCK_HIDDEN === true) {
414            $sql .= ' AND (T4.stock_max >= 1 OR T4.stock_unlimited_max = 1)';
415        }
416       
417        $sql .= ' ORDER BY';
418        $sql .= '     T1.product_id asc';
419       
420        $arrProduct = $objQuery->getAll($sql);
421        return $arrProduct;
422       
423    }
424
425    /**
426     * lfGetProductKeys.
427     *
428     * @param array $arrProduct 商品データ配列
429     * @return array $arrProductKeys 商品情報のkey配列を返す
430     */
431    function lfGetProductKeys($arrProduct) {
432        $arrProductKeys = array();
433        $arrProduct = SC_Utils_Ex::sfswaparray($arrProduct);
434        if ( is_array($arrProduct) ) {
435            $arrProductKeys = array_keys($arrProduct);
436        }
437        return $arrProductKeys;
438    }
439
440}
441?>
Note: See TracBrowser for help on using the repository browser.