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

Revision 22857, 10.8 KB checked in by Seasoft, 11 years ago (diff)

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

  • 主に空白・空白行の調整。
  • 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/LC_Page_Ex.php';
25
26/**
27 * RSS(商品) のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Rss_Products extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'rss/products.tpl';
44        $this->encode = 'UTF-8';
45        $this->title = '商品一覧情報';
46    }
47
48    /**
49     * Page のプロセス.
50     *
51     * @return void
52     */
53    function process()
54    {
55        $this->action();
56    }
57
58    /**
59     * Page のアクション.
60     *
61     * @return void
62     */
63    function action()
64    {
65        $objView = new SC_SiteView_Ex();
66
67        //店舗情報をセット
68        $this->arrSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
69
70        //商品IDを取得
71        if (isset($_GET['product_id']) && $_GET['product_id'] != '' && is_numeric($_GET['product_id'])) {
72            $product_id = $_GET['product_id'];
73        } else {
74            $product_id = '';
75        }
76
77        // モードによって分岐
78        $mode = $this->getMode();
79        switch ($mode) {
80            case 'all':
81                $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
82                break;
83            case 'list':
84                if ($product_id != '' && is_numeric($product_id)) {
85                    $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
86                } else {
87                    $arrProducts = $this->lfGetProductsListData();
88                }
89                break;
90            default:
91                if ($product_id != '' && is_numeric($product_id)) {
92                    $arrProducts = $this->lfGetProductsDetailData($mode, $product_id);
93                } else {
94                    $arrProducts = $this->lfGetProductsAllData();
95                }
96                break;
97        }
98
99        // 商品情報をセット
100        $this->arrProducts = $arrProducts;
101        // 従来互換 (for 2.11)
102        $this->arrProduct = &$this->arrProducts;
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    {
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    {
137        $objQuery = SC_Query_Ex::getSingletonInstance();
138        //商品詳細を取得
139        if ($mode == 'all') {
140            $arrProduct = $this->lfGetProductsDetail($objQuery, $mode);
141        } else {
142            $arrProduct = $this->lfGetProductsDetail($objQuery, $product_id);
143        }
144        // 値の整形
145        foreach ($arrProduct as $key => $val) {
146            //販売価格を税込みに編集
147            $arrProduct[$key]['price02'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02']);
148            // 画像ファイルのURLセット
149            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image'])) {
150                $dir = IMAGE_SAVE_RSS_URL;
151            } else {
152                $dir = IMAGE_TEMP_RSS_URL;
153            }
154            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
155            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image'])) {
156                $dir = IMAGE_SAVE_RSS_URL;
157            } else {
158                $dir = IMAGE_TEMP_RSS_URL;
159            }
160            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
161            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image'])) {
162                $dir = IMAGE_SAVE_RSS_URL;
163            } else {
164                $dir = IMAGE_TEMP_RSS_URL;
165            }
166            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
167            // ポイント計算
168            $arrProduct[$key]['point'] = SC_Utils_Ex::sfPrePoint(
169                $arrProduct[$key]['price02'],
170                $arrProduct[$key]['point_rate']
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
180        return $arrProduct;
181    }
182
183    /**
184     * lfGetProductsListData.
185     *
186     * @return array $arrProduct 商品情報の配列を返す
187     */
188    function lfGetProductsListData()
189    {
190        $objQuery = SC_Query_Ex::getSingletonInstance();
191        //商品一覧を取得
192        $arrProduct = $objQuery->getAll('SELECT product_id, name AS product_name FROM dtb_products');
193
194        return $arrProduct;
195    }
196
197    /**
198     * lfGetProductsAllData.
199     *
200     * @return array $arrProduct 商品情報の配列を返す
201     */
202    function lfGetProductsAllData()
203    {
204        $objQuery = SC_Query_Ex::getSingletonInstance();
205        //商品情報を取得
206        $arrProduct = $this->lfGetProductsAllclass($objQuery);
207        // 値の整形
208        foreach ($arrProduct as $key => $val) {
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            );
233            $arrProduct[$key]['point_min'] = SC_Utils_Ex::sfPrePoint(
234                $arrProduct[$key]['price02_min'],
235                $arrProduct[$key]['point_rate']
236            );
237        }
238
239        return $arrProduct;
240    }
241
242    /**
243     * 商品情報を取得する
244     *
245     * @param SC_Query $objQuery DB操作クラス
246     * @param integer $product_id 商品ID
247     * @return array $arrProduct 取得結果を配列で返す
248     */
249    function lfGetProductsDetail(&$objQuery, $product_id = 'all')
250    {
251        $objProduct = new SC_Product_Ex();
252
253        // --- 商品詳細の取得
254        if ($product_id == 'all') {
255            $objQuery->setOrder('product_id');
256            $arrProductLsit = $objProduct->lists($objQuery);
257        } else {
258            $arrProductLsit = $objProduct->getListByProductIds($objQuery, array($product_id));
259        }
260
261        // 各商品のカテゴリIDとランクの取得
262        $arrProduct = array();
263        foreach ($arrProductLsit as $key => $val) {
264            $sql = '';
265            $sql .= ' SELECT';
266            $sql .= '   T1.category_id,';
267            $sql .= '   T1.rank AS product_rank,';
268            $sql .= '   T2.rank AS category_rank';
269            $sql .= ' FROM';
270            $sql .= '   dtb_product_categories AS T1';
271            $sql .= ' LEFT JOIN';
272            $sql .= '   dtb_category AS T2';
273            $sql .= ' ON';
274            $sql .= '   T1.category_id = T2.category_id';
275            $sql .= ' WHERE';
276            $sql .= '   product_id = ?';
277            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
278            if (!empty($arrCategory)) {
279                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
280            }
281        }
282
283        return $arrProduct;
284    }
285
286    /**
287     * 商品情報を取得する(vw_products_allclass使用)
288     *
289     * @param SC_Query $objQuery DB操作クラス
290     * @return array $arrProduct 取得結果を配列で返す
291     */
292    function lfGetProductsAllclass(&$objQuery)
293    {
294        // --- 商品一覧の取得
295        $objProduct = new SC_Product_Ex();
296        $objQuery->setWhere($objProduct->getProductDispConditions());
297        $objQuery->setOrder('product_id');
298        $arrProductLsit = $objProduct->lists($objQuery);
299        // 各商品のカテゴリIDとランクの取得
300        $arrProducts = array();
301        foreach ($arrProductLsit as $key => $val) {
302            $sql = '';
303            $sql .= ' SELECT';
304            $sql .= '   T1.category_id,';
305            $sql .= '   T1.rank AS product_rank,';
306            $sql .= '   T2.rank AS category_rank';
307            $sql .= ' FROM';
308            $sql .= '   dtb_product_categories AS T1';
309            $sql .= ' LEFT JOIN';
310            $sql .= '   dtb_category AS T2';
311            $sql .= ' ON';
312            $sql .= '   T1.category_id = T2.category_id';
313            $sql .= ' WHERE';
314            $sql .= '   product_id = ?';
315            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
316            if (!empty($arrCategory)) {
317                $arrProducts[$key] = array_merge($val, $arrCategory[0]);
318            }
319        }
320
321        // 税込金額を設定する
322        SC_Product_Ex::setIncTaxToProducts($arrProducts);
323
324        return $arrProducts;
325    }
326}
Note: See TracBrowser for help on using the repository browser.