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

Revision 21514, 10.9 KB checked in by Seasoft, 12 years ago (diff)

#1625 (typo修正・ソース整形・ソースコメントの改善)

  • 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-2011 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            $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
83            break;
84        case 'list':
85            if ($product_id != '' && is_numeric($product_id)) {
86                $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
87            } else {
88                $arrProducts = $this->lfGetProductsListData();
89            }
90            break;
91        default:
92            if ($product_id != '' && is_numeric($product_id)) {
93                $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
94            } else {
95                $arrProducts = $this->lfGetProductsAllData();
96            }
97            break;
98        }
99
100        // 商品情報をセット
101        $this->arrProducts = $arrProducts;
102        // 従来互換 (for 2.11)
103        $this->arrProduct = &$this->arrProducts;
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_Ex::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            );
171            // 在庫無制限
172            if ($arrProduct[$key]['stock_unlimited'] == 1) {
173                $arrProduct[$key]['stock_unlimited'] = '在庫無制限';
174            } else {
175                $arrProduct[$key]['stock_unlimited'] = NULL;
176            }
177        }
178        return $arrProduct;
179    }
180
181    /**
182     * lfGetProductsListData.
183     *
184     * @return array $arrProduct 商品情報の配列を返す
185     */
186    function lfGetProductsListData() {
187        $objQuery = SC_Query_Ex::getSingletonInstance();
188        //商品一覧を取得
189        $arrProduct = $objQuery->getAll('SELECT product_id, name AS product_name FROM dtb_products');
190        return $arrProduct;
191    }
192
193    /**
194     * lfGetProductsAllData.
195     *
196     * @return array $arrProduct 商品情報の配列を返す
197     */
198    function lfGetProductsAllData() {
199        $objQuery = SC_Query_Ex::getSingletonInstance();
200        //商品情報を取得
201        $arrProduct = $this->lfGetProductsAllclass($objQuery);
202        // 値の整形
203        foreach ($arrProduct as $key => $val) {
204            //販売価格を税込みに編集
205            $arrProduct[$key]['price02_max'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_max']);
206            $arrProduct[$key]['price02_min'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02_min']);
207            // 画像ファイルのURLセット
208            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image'])) {
209                $dir = IMAGE_SAVE_RSS_URL;
210            } else {
211                $dir = IMAGE_TEMP_RSS_URL;
212            }
213            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
214            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image'])) {
215                $dir = IMAGE_SAVE_RSS_URL;
216            } else {
217                $dir = IMAGE_TEMP_RSS_URL;
218            }
219            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
220            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image'])) {
221                $dir = IMAGE_SAVE_RSS_URL;
222            } else {
223                $dir = IMAGE_TEMP_RSS_URL;
224            }
225            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
226            // ポイント計算
227            $arrProduct[$key]['point_max'] = SC_Utils_Ex::sfPrePoint(
228                $arrProduct[$key]['price02_max'],
229                $arrProduct[$key]['point_rate']
230            );
231            $arrProduct[$key]['point_min'] = SC_Utils_Ex::sfPrePoint(
232                $arrProduct[$key]['price02_min'],
233                $arrProduct[$key]['point_rate']
234            );
235        }
236        return $arrProduct;
237    }
238
239    /**
240     * 商品情報を取得する
241     *
242     * @param SC_Query $objQuery DB操作クラス
243     * @param integer $product_id 商品ID
244     * @return array $arrProduct 取得結果を配列で返す
245     */
246    function lfGetProductsDetail(&$objQuery, $product_id = 'all') {
247        $objProduct = new SC_Product_Ex();
248
249        // --- 商品詳細の取得
250        if ($product_id == 'all') {
251            $objQuery->setOrder('product_id');
252            $arrProductLsit = $objProduct->lists($objQuery);
253        } else {
254            $arrProductLsit = $objProduct->getListByProductIds($objQuery, array($product_id));
255        }
256
257        // 各商品のカテゴリIDとランクの取得
258        $arrProduct = array();
259        foreach ($arrProductLsit as $key => $val) {
260            $sql = '';
261            $sql .= ' SELECT';
262            $sql .= '   T1.category_id,';
263            $sql .= '   T1.rank AS product_rank,';
264            $sql .= '   T2.rank AS category_rank';
265            $sql .= ' FROM';
266            $sql .= '   dtb_product_categories AS T1';
267            $sql .= ' LEFT JOIN';
268            $sql .= '   dtb_category AS T2';
269            $sql .= ' ON';
270            $sql .= '   T1.category_id = T2.category_id';
271            $sql .= ' WHERE';
272            $sql .= '   product_id = ?';
273            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
274            if (!empty($arrCategory)) {
275                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
276            }
277        }
278        return $arrProduct;
279    }
280
281    /**
282     * 商品情報を取得する(vw_products_allclass使用)
283     *
284     * @param SC_Query $objQuery DB操作クラス
285     * @return array $arrProduct 取得結果を配列で返す
286     */
287    function lfGetProductsAllclass(&$objQuery) {
288        // --- 商品一覧の取得
289        $objQuery->setWhere('del_flg = 0 AND status = 1');
290        $objQuery->setOrder('product_id');
291        $objProduct = new SC_Product_Ex();
292        $arrProductLsit = $objProduct->lists($objQuery);
293        // 各商品のカテゴリIDとランクの取得
294        $arrProduct = array();
295        foreach ($arrProductLsit as $key => $val) {
296            $sql = '';
297            $sql .= ' SELECT';
298            $sql .= '   T1.category_id,';
299            $sql .= '   T1.rank AS product_rank,';
300            $sql .= '   T2.rank AS category_rank';
301            $sql .= ' FROM';
302            $sql .= '   dtb_product_categories AS T1';
303            $sql .= ' LEFT JOIN';
304            $sql .= '   dtb_category AS T2';
305            $sql .= ' ON';
306            $sql .= '   T1.category_id = T2.category_id';
307            $sql .= ' WHERE';
308            $sql .= '   product_id = ?';
309            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
310            if (!empty($arrCategory)) {
311                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
312            }
313        }
314        return $arrProduct;
315    }
316}
Note: See TracBrowser for help on using the repository browser.