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

Revision 21693, 11.4 KB checked in by h_yoshimoto, 12 years ago (diff)

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