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

Revision 21743, 10.8 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

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