1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 |
---|
25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * カテゴリ一覧 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Products_CategoryList extends LC_Page { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Page のプロセス. |
---|
50 | * |
---|
51 | * @return void |
---|
52 | */ |
---|
53 | function process() { |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * モバイルページを初期化する. |
---|
58 | * |
---|
59 | * @return void |
---|
60 | */ |
---|
61 | function mobileInit() { |
---|
62 | $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . 'products/category_list.tpl'; |
---|
63 | $this->tpl_title = 'カテゴリ一覧ページ'; |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Page のプロセス(モバイル). |
---|
68 | * |
---|
69 | * @return void |
---|
70 | */ |
---|
71 | function mobileProcess() { |
---|
72 | $objView = new SC_MobileView(); |
---|
73 | |
---|
74 | // レイアウトデザインを取得 |
---|
75 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
76 | $objLayout->sfGetPageLayout($this, false, DEF_LAYOUT); |
---|
77 | |
---|
78 | // カテゴリー情報を取得する。 |
---|
79 | $this->lfGetCategories(@$_GET['category_id'], true, $this); |
---|
80 | |
---|
81 | $objView->assignobj($this); |
---|
82 | $objView->display(SITE_FRAME); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * デストラクタ. |
---|
87 | * |
---|
88 | * @return void |
---|
89 | */ |
---|
90 | function destroy() { |
---|
91 | parent::destroy(); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * 選択されたカテゴリーとその子カテゴリーの情報を取得し、 |
---|
96 | * ページオブジェクトに格納する。 |
---|
97 | * |
---|
98 | * @param string $category_id カテゴリーID |
---|
99 | * @param boolean $count_check 有効な商品がないカテゴリーを除くかどうか |
---|
100 | * @param object &$objPage ページオブジェクト |
---|
101 | * @return void |
---|
102 | */ |
---|
103 | function lfGetCategories($category_id, $count_check = false, &$objPage) { |
---|
104 | $objDb = new SC_Helper_DB_Ex(); |
---|
105 | // カテゴリーの正しいIDを取得する。 |
---|
106 | $arrCategory_id = $objDb->sfGetCategoryId('', $category_id); |
---|
107 | $category_id = $arrCategory_id[0]; |
---|
108 | if ($category_id == 0) { |
---|
109 | SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true); |
---|
110 | } |
---|
111 | |
---|
112 | $arrCategory = null; // 選択されたカテゴリー |
---|
113 | $arrChildren = array(); // 子カテゴリー |
---|
114 | |
---|
115 | $arrAll = $objDb->sfGetCatTree($category_id, $count_check); |
---|
116 | foreach ($arrAll as $category) { |
---|
117 | // 選択されたカテゴリーの場合 |
---|
118 | if ($category['category_id'] == $category_id) { |
---|
119 | $arrCategory = $category; |
---|
120 | continue; |
---|
121 | } |
---|
122 | |
---|
123 | // 関係のないカテゴリーはスキップする。 |
---|
124 | if ($category['parent_category_id'] != $category_id) { |
---|
125 | continue; |
---|
126 | } |
---|
127 | |
---|
128 | // 子カテゴリーの場合は、孫カテゴリーが存在するかどうかを調べる。 |
---|
129 | $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']); |
---|
130 | $category['has_children'] = count($arrGrandchildrenID) > 0; |
---|
131 | $arrChildren[] = $category; |
---|
132 | } |
---|
133 | |
---|
134 | if (!isset($arrCategory)) { |
---|
135 | SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true); |
---|
136 | } |
---|
137 | |
---|
138 | // 子カテゴリーの商品数を合計する。 |
---|
139 | $children_product_count = 0; |
---|
140 | foreach ($arrChildren as $category) { |
---|
141 | $children_product_count += $category['product_count']; |
---|
142 | } |
---|
143 | |
---|
144 | // 選択されたカテゴリーに直属の商品がある場合は、子カテゴリーの先頭に追加する。 |
---|
145 | if ($arrCategory['product_count'] > $children_product_count) { |
---|
146 | $arrCategory['product_count'] -= $children_product_count; // 子カテゴリーの商品数を除く。 |
---|
147 | $arrCategory['has_children'] = false; // 商品一覧ページに遷移させるため。 |
---|
148 | array_unshift($arrChildren, $arrCategory); |
---|
149 | } |
---|
150 | |
---|
151 | // 結果を格納する。 |
---|
152 | $objPage->arrCategory = $arrCategory; |
---|
153 | $objPage->arrChildren = $arrChildren; |
---|
154 | } |
---|
155 | } |
---|
156 | ?> |
---|