1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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 | /* [名称] SC_Product |
---|
25 | * [概要] 商品クラス |
---|
26 | */ |
---|
27 | class SC_Product { |
---|
28 | |
---|
29 | /** 規格名一覧 */ |
---|
30 | var $arrClassName; |
---|
31 | /** 規格分類名一覧 */ |
---|
32 | var $arrClassCatName; |
---|
33 | var $classCategories = array(); |
---|
34 | var $stock_find; |
---|
35 | /** 規格1クラス名 */ |
---|
36 | var $className1 = ''; |
---|
37 | /** 規格2クラス名 */ |
---|
38 | var $className2 = ''; |
---|
39 | /** 規格1が設定されている */ |
---|
40 | var $classCat1_find; |
---|
41 | /** 規格2が設定されている */ |
---|
42 | var $classCat2_find; |
---|
43 | var $classCats1; |
---|
44 | |
---|
45 | function SC_Product($arrProductId = null) { |
---|
46 | $objDb = new SC_Helper_DB_Ex(); |
---|
47 | |
---|
48 | // 規格名一覧 |
---|
49 | $this->arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
50 | // 規格分類名一覧 |
---|
51 | $this->arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
52 | $this->arrClassCatName[''] = '選択してください'; |
---|
53 | |
---|
54 | if (!is_null($arrProductId)) { |
---|
55 | $this->setProductId($arrProductId); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | function setProductId($arrProductId) { |
---|
60 | |
---|
61 | // 商品規格情報の取得 |
---|
62 | $rows = $this->lfGetProductsClass($arrProductId); |
---|
63 | |
---|
64 | $arrProductsClass = array(); |
---|
65 | foreach ($rows as $row) { |
---|
66 | $productId = $row['product_id']; |
---|
67 | $arrProductsClass[$productId][] = $row; |
---|
68 | } |
---|
69 | unset($rows); |
---|
70 | |
---|
71 | foreach ($arrProductsClass as $productId => $arrProductClass) { |
---|
72 | $classCats1 = array(); |
---|
73 | $classCats1[''] = '選択してください'; |
---|
74 | |
---|
75 | // 規格1クラス名 |
---|
76 | $this->className1[$productId] = |
---|
77 | isset($this->arrClassName[$arrProductClass[0]['class_id1']]) |
---|
78 | ? $this->arrClassName[$arrProductClass[0]['class_id1']] |
---|
79 | : ''; |
---|
80 | |
---|
81 | // 規格2クラス名 |
---|
82 | $this->className2[$productId] = |
---|
83 | isset($this->arrClassName[$arrProductClass[0]['class_id2']]) |
---|
84 | ? $this->arrClassName[$arrProductClass[0]['class_id2']] |
---|
85 | : ''; |
---|
86 | |
---|
87 | // 規格1が設定されている |
---|
88 | $this->classCat1_find[$productId] = ($arrProductClass[0]['classcategory_id1'] != '0'); |
---|
89 | // 規格2が設定されている |
---|
90 | $this->classCat2_find[$productId] = ($arrProductClass[0]['classcategory_id2'] != '0'); |
---|
91 | |
---|
92 | $this->stock_find[$productId] = false; |
---|
93 | $classCategories = array(); |
---|
94 | $classCategories['']['']['name'] = '選択してください'; |
---|
95 | foreach ($arrProductClass as $productsClass) { |
---|
96 | $productsClass1 = $productsClass['classcategory_id1']; |
---|
97 | $productsClass2 = $productsClass['classcategory_id2']; |
---|
98 | $classCategories[$productsClass1]['']['name'] = '選択してください'; |
---|
99 | |
---|
100 | // 在庫 |
---|
101 | $stock_find_class = ($productsClass['stock_unlimited'] || $productsClass['stock'] > 0); |
---|
102 | |
---|
103 | $classCategories[$productsClass1][$productsClass2]['name'] = $this->arrClassCatName[$productsClass2] |
---|
104 | . ($stock_find_class ? '' : ' (品切れ中)'); |
---|
105 | |
---|
106 | $classCategories[$productsClass1][$productsClass2]['stock_find'] = $stock_find_class; |
---|
107 | |
---|
108 | if ($stock_find_class) { |
---|
109 | $this->stock_find[$productId] = true; |
---|
110 | } |
---|
111 | |
---|
112 | if (!in_array($classcat_id1, $classCats1)) { |
---|
113 | $classCats1[$productsClass1] = $this->arrClassCatName[$productsClass1] |
---|
114 | . ($productsClass2 == 0 && !$stock_find_class ? ' (品切れ中)' : ''); |
---|
115 | } |
---|
116 | |
---|
117 | // 価格 |
---|
118 | $classCategories[$productsClass1][$productsClass2]['price01'] |
---|
119 | = strlen($productsClass['price01']) |
---|
120 | ? number_format(SC_Helper_DB_Ex::sfPreTax($productsClass['price01'])) |
---|
121 | : ''; |
---|
122 | |
---|
123 | $classCategories[$productsClass1][$productsClass2]['price02'] |
---|
124 | = strlen($productsClass['price02']) |
---|
125 | ? number_format(SC_Helper_DB_Ex::sfPreTax($productsClass['price02'])) |
---|
126 | : ''; |
---|
127 | |
---|
128 | // ポイント |
---|
129 | // XXX sfPrePoint() の第4パラメータは、処理にバグがあるため現状省略している。(http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=3540&forum=1&post_id=13853#forumpost13853) |
---|
130 | $classCategories[$productsClass1][$productsClass2]['point'] |
---|
131 | = SC_Utils_Ex::sfPrePoint($productsClass['price02'], $productsClass['point_rate']); |
---|
132 | } |
---|
133 | |
---|
134 | $this->classCategories[$productId] = $classCategories; |
---|
135 | |
---|
136 | // 規格1 |
---|
137 | $this->classCats1[$productId] = $classCats1; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | /* 商品規格情報の取得 */ |
---|
142 | function lfGetProductsClass($arrProductId) { |
---|
143 | $arrProductId = (Array) $arrProductId; |
---|
144 | |
---|
145 | if (empty($arrProductId)) { |
---|
146 | return array(); |
---|
147 | } |
---|
148 | |
---|
149 | // 商品規格取得 |
---|
150 | $objQuery = new SC_Query(); |
---|
151 | $col = "product_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, price01, price02, point_rate"; |
---|
152 | $table = "vw_product_class AS prdcls"; |
---|
153 | $where = 'product_id IN (' . implode(', ', array_pad(array(), count($arrProductId), '?')) . ')'; |
---|
154 | $objQuery->setorder("product_id, rank1 DESC, rank2 DESC"); |
---|
155 | $arrRet = $objQuery->select($col, $table, $where, $arrProductId); |
---|
156 | |
---|
157 | return $arrRet; |
---|
158 | } |
---|
159 | } |
---|
160 | ?> |
---|