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

Revision 20459, 11.6 KB checked in by nanasess, 13 years ago (diff)

#997(冗長な dtb_baseinfo の取得)

  • SC_View のコンストラクタで取得していたのを LC_Page へ移動

#793 (非推奨機能の削除)

  • SC_SiteInfo クラスの削除
  • 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-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_EX_REALDIR . "page_extends/LC_Page_Ex.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_Ex {
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_Ex();
67       
68        //店舗情報をセット
69        $this->arrSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
70       
71        //商品IDを取得
72        if ( isset($_GET['product_id']) && $_GET['product_id'] != '' && is_numeric($_GET['product_id']) ) {
73            $product_id = $_GET['product_id'];
74        } else {
75            $product_id = '';
76        }
77       
78        // モードによって分岐
79        $mode = $this->getMode();
80        switch ($mode) {
81        case 'all':
82            $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
83            break;
84        case 'list':
85            if ( $product_id != '' && is_numeric($product_id) ) {
86                $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
87            } else {
88                $arrProduct = $this->lfGetProductsListData();
89            }
90            break;
91        default:
92            if ( $product_id != '' && is_numeric($product_id) ) {
93                $arrProduct = $this->lfGetProductsDetailData($mode, $product_id);
94            } else {
95                $arrProduct = $this->lfGetProductsAllData();
96            }
97            break;
98        }
99       
100        // 商品情報をセット
101        $this->arrProduct = $arrProduct;
102        $this->arrProductKeys = $this->lfGetProductKeys($arrProduct);
103       
104        //セットしたデータをテンプレートファイルに出力
105        $objView->assignobj($this);
106       
107        //キャッシュしない(念のため)
108        header("Pragma: no-cache");
109       
110        //XMLテキスト(これがないと正常にRSSとして認識してくれないツールがあるため)
111        header("Content-type: application/xml");
112        P_DETAIL_URLPATH;
113       
114        //画面表示
115        $objView->display($this->tpl_mainpage, true);
116    }
117
118    /**
119     * デストラクタ.
120     *
121     * @return void
122     */
123    function destroy() {
124        parent::destroy();
125    }
126
127    /**
128     * lfGetProductsDetailData.
129     *
130     * @param str $mode モード
131     * @param str $product_id 商品ID
132     * @return array $arrProduct 商品情報の配列を返す
133     */
134    function lfGetProductsDetailData($mode, $product_id) {
135        $objQuery = SC_Query::getSingletonInstance();
136        //商品詳細を取得
137        if ( $mode == 'all' ) {
138            $arrProduct = $this->lfGetProductsDetail($objQuery, $mode);
139        } else {
140            $arrProduct = $this->lfGetProductsDetail($objQuery, $product_id);
141        }
142        // 値の整形
143        foreach ($arrProduct as $key => $val) {
144            //販売価格を税込みに編集
145            $arrProduct[$key]['price02'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02']);
146            // 画像ファイルのURLセット
147            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image']) ) {
148                $dir = IMAGE_SAVE_RSS_URL;
149            } else {
150                $dir = IMAGE_TEMP_RSS_URL;
151            }
152            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
153            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image']) ){
154                $dir = IMAGE_SAVE_RSS_URL;
155            } else {
156                $dir = IMAGE_TEMP_RSS_URL;
157            }
158            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
159            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image']) ) {
160                $dir = IMAGE_SAVE_RSS_URL;
161            } else {
162                $dir = IMAGE_TEMP_RSS_URL;
163            }
164            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
165            // ポイント計算
166            $arrProduct[$key]['point'] = SC_Utils_Ex::sfPrePoint(
167                $arrProduct[$key]['price02'],
168                $arrProduct[$key]['point_rate'],
169                POINT_RULE,
170                $arrProduct[$key]['product_id']
171            );
172            // 在庫無制限
173            if ( $arrProduct[$key]['stock_unlimited'] == 1 ) {
174                $arrProduct[$key]['stock_unlimited'] = '在庫無制限';
175            } else {
176                $arrProduct[$key]['stock_unlimited'] = NULL;
177            }
178        }
179        return $arrProduct;
180    }
181
182    /**
183     * lfGetProductsListData.
184     *
185     * @return array $arrProduct 商品情報の配列を返す
186     */
187    function lfGetProductsListData() {
188        $objQuery = SC_Query::getSingletonInstance();
189        //商品一覧を取得
190        $arrProduct = $objQuery->getAll('SELECT product_id, name AS product_name FROM dtb_products');
191        return $arrProduct;
192    }
193
194    /**
195     * lfGetProductsAllData.
196     *
197     * @return array $arrProduct 商品情報の配列を返す
198     */
199    function lfGetProductsAllData() {
200        $objQuery = SC_Query::getSingletonInstance();
201        //商品情報を取得
202        $arrProduct = $this->lfGetProductsAllclass($objQuery);
203        // 値の整形
204        foreach ($arrProduct as $key => $val) {
205            //販売価格を税込みに編集
206            $arrProduct[$key]['price02_max'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_max']);
207            $arrProduct[$key]['price02_min'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_min']);
208            // 画像ファイルのURLセット
209            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image']) ) {
210                $dir = IMAGE_SAVE_RSS_URL;
211            } else {
212                $dir = IMAGE_TEMP_RSS_URL;
213            }
214            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
215            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image']) ) {
216                $dir = IMAGE_SAVE_RSS_URL;
217            } else {
218                $dir = IMAGE_TEMP_RSS_URL;
219            }
220            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
221            if ( file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image']) ) {
222                $dir = IMAGE_SAVE_RSS_URL;
223            } else {
224                $dir = IMAGE_TEMP_RSS_URL;
225            }
226            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
227            // ポイント計算
228            $arrProduct[$key]['point_max'] = SC_Utils_Ex::sfPrePoint(
229                $arrProduct[$key]['price02_max'],
230                $arrProduct[$key]['point_rate'],
231                POINT_RULE,
232                $arrProduct[$key]['product_id']
233            );
234            $arrProduct[$key]['point_min'] = SC_Utils_Ex::sfPrePoint(
235                $arrProduct[$key]['price02_min'],
236                $arrProduct[$key]['point_rate'],
237                POINT_RULE,
238                $arrProduct[$key]['product_id']
239            );
240        }
241        return $arrProduct;
242    }
243
244    /**
245     * 商品情報を取得する
246     *
247     * @param SC_Query $objQuery DB操作クラス
248     * @param integer $product_id 商品ID
249     * @return array $arrProduct 取得結果を配列で返す
250     */
251    function lfGetProductsDetail(&$objQuery, $product_id = 'all'){
252        // --- 商品詳細の取得
253        if ($product_id != 'all') {
254            $where = 'product_id = ' . $product_id;
255            $objQuery->setWhere($where);
256        }
257        $objQuery->setOrder('product_id');
258        $objProduct = new SC_Product();
259        $arrProductLsit = $objProduct->lists($objQuery);
260        // 各商品のカテゴリIDとランクの取得
261        $arrProduct = array();
262        foreach( $arrProductLsit as $key => $val ) {
263            $sql = '';
264            $sql .= ' SELECT';
265            $sql .= '   T1.category_id,';
266            $sql .= '   T1.rank AS product_rank,';
267            $sql .= '   T2.rank AS category_rank';
268            $sql .= ' FROM';
269            $sql .= '   dtb_product_categories AS T1';
270            $sql .= ' LEFT JOIN';
271            $sql .= '   dtb_category AS T2';
272            $sql .= ' ON';
273            $sql .= '   T1.category_id = T2.category_id';
274            $sql .= ' WHERE';
275            $sql .= '   product_id = ?';
276            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
277            if ( !empty($arrCategory) ) {
278                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
279            }
280        }
281        return $arrProduct;
282    }
283
284    /**
285     * 商品情報を取得する(vw_products_allclass使用)
286     *
287     * @param SC_Query $objQuery DB操作クラス
288     * @return array $arrProduct 取得結果を配列で返す
289     */
290    function lfGetProductsAllclass(&$objQuery){
291        // --- 商品一覧の取得
292        $objQuery->setOrder('product_id');
293        $objProduct = new SC_Product();
294        $arrProductLsit = $objProduct->lists($objQuery);
295        // 各商品のカテゴリIDとランクの取得
296        $arrProduct = array();
297        foreach( $arrProductLsit as $key => $val ) {
298            $sql = '';
299            $sql .= ' SELECT';
300            $sql .= '   T1.category_id,';
301            $sql .= '   T1.rank AS product_rank,';
302            $sql .= '   T2.rank AS category_rank';
303            $sql .= ' FROM';
304            $sql .= '   dtb_product_categories AS T1';
305            $sql .= ' LEFT JOIN';
306            $sql .= '   dtb_category AS T2';
307            $sql .= ' ON';
308            $sql .= '   T1.category_id = T2.category_id';
309            $sql .= ' WHERE';
310            $sql .= '   product_id = ?';
311            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
312            if ( !empty($arrCategory) ) {
313                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
314            }
315        }
316        return $arrProduct;
317    }
318
319    /**
320     * lfGetProductKeys.
321     *
322     * @param array $arrProduct 商品データ配列
323     * @return array $arrProductKeys 商品情報のkey配列を返す
324     */
325    function lfGetProductKeys($arrProduct) {
326        $arrProductKeys = array();
327        $arrProduct = SC_Utils_Ex::sfswaparray($arrProduct);
328        if ( is_array($arrProduct) ) {
329            $arrProductKeys = array_keys($arrProduct);
330        }
331        return $arrProductKeys;
332    }
333
334}
335?>
Note: See TracBrowser for help on using the repository browser.