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

Revision 23057, 10.7 KB checked in by Seasoft, 11 years ago (diff)

#2327 (SC_Helper_PageLayout#sfGetPageLayout ページ情報が取得できない場合の動作が不定)

  • 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        $this->skip_load_page_layout = true;
43        parent::init();
44        $this->tpl_mainpage = 'rss/products.tpl';
45        $this->encode = 'UTF-8';
46        $this->title = '商品一覧情報';
47    }
48
49    /**
50     * Page のプロセス.
51     *
52     * @return void
53     */
54    function process()
55    {
56        $this->action();
57    }
58
59    /**
60     * Page のアクション.
61     *
62     * @return void
63     */
64    function action()
65    {
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     * lfGetProductsDetailData.
121     *
122     * @param str $mode モード
123     * @param str $product_id 商品ID
124     * @return array $arrProduct 商品情報の配列を返す
125     */
126    function lfGetProductsDetailData($mode, $product_id)
127    {
128        $objQuery = SC_Query_Ex::getSingletonInstance();
129        //商品詳細を取得
130        if ($mode == 'all') {
131            $arrProduct = $this->lfGetProductsDetail($objQuery, $mode);
132        } else {
133            $arrProduct = $this->lfGetProductsDetail($objQuery, $product_id);
134        }
135        // 値の整形
136        foreach (array_keys($arrProduct) as $key) {
137            //販売価格を税込みに編集
138            $arrProduct[$key]['price02'] = SC_Helper_DB_Ex::sfCalcIncTax($arrProduct[$key]['price02']);
139            // 画像ファイルのURLセット
140            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image'])) {
141                $dir = IMAGE_SAVE_RSS_URL;
142            } else {
143                $dir = IMAGE_TEMP_RSS_URL;
144            }
145            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
146            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image'])) {
147                $dir = IMAGE_SAVE_RSS_URL;
148            } else {
149                $dir = IMAGE_TEMP_RSS_URL;
150            }
151            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
152            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image'])) {
153                $dir = IMAGE_SAVE_RSS_URL;
154            } else {
155                $dir = IMAGE_TEMP_RSS_URL;
156            }
157            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
158            // ポイント計算
159            $arrProduct[$key]['point'] = SC_Utils_Ex::sfPrePoint(
160                $arrProduct[$key]['price02'],
161                $arrProduct[$key]['point_rate']
162            );
163            // 在庫無制限
164            if ($arrProduct[$key]['stock_unlimited'] == 1) {
165                $arrProduct[$key]['stock_unlimited'] = '在庫無制限';
166            } else {
167                $arrProduct[$key]['stock_unlimited'] = NULL;
168            }
169        }
170
171        return $arrProduct;
172    }
173
174    /**
175     * lfGetProductsListData.
176     *
177     * @return array $arrProduct 商品情報の配列を返す
178     */
179    function lfGetProductsListData()
180    {
181        $objQuery = SC_Query_Ex::getSingletonInstance();
182        //商品一覧を取得
183        $arrProduct = $objQuery->getAll('SELECT product_id, name AS product_name FROM dtb_products');
184
185        return $arrProduct;
186    }
187
188    /**
189     * lfGetProductsAllData.
190     *
191     * @return array $arrProduct 商品情報の配列を返す
192     */
193    function lfGetProductsAllData()
194    {
195        $objQuery = SC_Query_Ex::getSingletonInstance();
196        //商品情報を取得
197        $arrProduct = $this->lfGetProductsAllclass($objQuery);
198        // 値の整形
199        foreach (array_keys($arrProduct) as $key) {
200            // 画像ファイルのURLセット
201            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_list_image'])) {
202                $dir = IMAGE_SAVE_RSS_URL;
203            } else {
204                $dir = IMAGE_TEMP_RSS_URL;
205            }
206            $arrProduct[$key]['main_list_image'] = $dir . $arrProduct[$key]['main_list_image'];
207            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_image'])) {
208                $dir = IMAGE_SAVE_RSS_URL;
209            } else {
210                $dir = IMAGE_TEMP_RSS_URL;
211            }
212            $arrProduct[$key]['main_image'] = $dir . $arrProduct[$key]['main_image'];
213            if (file_exists(IMAGE_SAVE_REALDIR . $arrProduct[$key]['main_large_image'])) {
214                $dir = IMAGE_SAVE_RSS_URL;
215            } else {
216                $dir = IMAGE_TEMP_RSS_URL;
217            }
218            $arrProduct[$key]['main_large_image'] = $dir . $arrProduct[$key]['main_large_image'];
219            // ポイント計算
220            $arrProduct[$key]['point_max'] = SC_Utils_Ex::sfPrePoint(
221                $arrProduct[$key]['price02_max'],
222                $arrProduct[$key]['point_rate']
223            );
224            $arrProduct[$key]['point_min'] = SC_Utils_Ex::sfPrePoint(
225                $arrProduct[$key]['price02_min'],
226                $arrProduct[$key]['point_rate']
227            );
228        }
229
230        return $arrProduct;
231    }
232
233    /**
234     * 商品情報を取得する
235     *
236     * @param SC_Query $objQuery DB操作クラス
237     * @param integer $product_id 商品ID
238     * @return array $arrProduct 取得結果を配列で返す
239     */
240    function lfGetProductsDetail(&$objQuery, $product_id = 'all')
241    {
242        $objProduct = new SC_Product_Ex();
243
244        // --- 商品詳細の取得
245        if ($product_id == 'all') {
246            $objQuery->setOrder('product_id');
247            $arrProductLsit = $objProduct->lists($objQuery);
248        } else {
249            $arrProductLsit = $objProduct->getListByProductIds($objQuery, array($product_id));
250        }
251
252        // 各商品のカテゴリIDとランクの取得
253        $arrProduct = array();
254        foreach ($arrProductLsit as $key => $val) {
255            $sql = '';
256            $sql .= ' SELECT';
257            $sql .= '   T1.category_id,';
258            $sql .= '   T1.rank AS product_rank,';
259            $sql .= '   T2.rank AS category_rank';
260            $sql .= ' FROM';
261            $sql .= '   dtb_product_categories AS T1';
262            $sql .= ' LEFT JOIN';
263            $sql .= '   dtb_category AS T2';
264            $sql .= ' ON';
265            $sql .= '   T1.category_id = T2.category_id';
266            $sql .= ' WHERE';
267            $sql .= '   product_id = ?';
268            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
269            if (!empty($arrCategory)) {
270                $arrProduct[$key] = array_merge($val, $arrCategory[0]);
271            }
272        }
273
274        return $arrProduct;
275    }
276
277    /**
278     * 商品情報を取得する(vw_products_allclass使用)
279     *
280     * @param SC_Query $objQuery DB操作クラス
281     * @return array $arrProduct 取得結果を配列で返す
282     */
283    function lfGetProductsAllclass(&$objQuery)
284    {
285        // --- 商品一覧の取得
286        $objProduct = new SC_Product_Ex();
287        $objQuery->setWhere($objProduct->getProductDispConditions());
288        $objQuery->setOrder('product_id');
289        $arrProductLsit = $objProduct->lists($objQuery);
290        // 各商品のカテゴリIDとランクの取得
291        $arrProducts = array();
292        foreach ($arrProductLsit as $key => $val) {
293            $sql = '';
294            $sql .= ' SELECT';
295            $sql .= '   T1.category_id,';
296            $sql .= '   T1.rank AS product_rank,';
297            $sql .= '   T2.rank AS category_rank';
298            $sql .= ' FROM';
299            $sql .= '   dtb_product_categories AS T1';
300            $sql .= ' LEFT JOIN';
301            $sql .= '   dtb_category AS T2';
302            $sql .= ' ON';
303            $sql .= '   T1.category_id = T2.category_id';
304            $sql .= ' WHERE';
305            $sql .= '   product_id = ?';
306            $arrCategory = $objQuery->getAll($sql, array($val['product_id']));
307            if (!empty($arrCategory)) {
308                $arrProducts[$key] = array_merge($val, $arrCategory[0]);
309            }
310        }
311
312        // 税込金額を設定する
313        SC_Product_Ex::setIncTaxToProducts($arrProducts);
314
315        return $arrProducts;
316    }
317}
Note: See TracBrowser for help on using the repository browser.