[18277] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[18277] | 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 | |
---|
[18863] | 24 | /** |
---|
| 25 | * 商品を扱うサービスクラス. |
---|
| 26 | * |
---|
| 27 | * @author LOCKON CO.,LTD. |
---|
| 28 | * @author Kentaro Ohkouchi |
---|
| 29 | * @version $Id$ |
---|
[18277] | 30 | */ |
---|
| 31 | class SC_Product { |
---|
| 32 | |
---|
| 33 | /** 規格名一覧 */ |
---|
| 34 | var $arrClassName; |
---|
| 35 | /** 規格分類名一覧 */ |
---|
| 36 | var $arrClassCatName; |
---|
| 37 | var $classCategories = array(); |
---|
| 38 | var $stock_find; |
---|
| 39 | /** 規格1クラス名 */ |
---|
| 40 | var $className1 = ''; |
---|
| 41 | /** 規格2クラス名 */ |
---|
| 42 | var $className2 = ''; |
---|
| 43 | /** 規格1が設定されている */ |
---|
| 44 | var $classCat1_find; |
---|
| 45 | /** 規格2が設定されている */ |
---|
| 46 | var $classCat2_find; |
---|
| 47 | var $classCats1; |
---|
[19662] | 48 | /** 検索用並び替え条件配列 */ |
---|
| 49 | var $arrOrderData; |
---|
[19688] | 50 | |
---|
[19662] | 51 | /** |
---|
| 52 | * 商品検索結果の並び順を指定する。 |
---|
| 53 | * |
---|
| 54 | * ただし指定できるテーブルはproduct_idを持っているテーブルであることが必要. |
---|
| 55 | * |
---|
| 56 | * @param string $col 並び替えの基準とするフィールド |
---|
| 57 | * @param string $table 並び替えの基準とするフィールドがあるテーブル |
---|
| 58 | * @param string $order 並び替えの順序 ASC / DESC |
---|
| 59 | * @return void |
---|
| 60 | */ |
---|
| 61 | function setProductsOrder($col, $table = 'dtb_products', $order = 'ASC') { |
---|
| 62 | $this->arrOrderData = array('col' => $col, 'table' => $table, 'order' => $order); |
---|
| 63 | } |
---|
[18815] | 64 | |
---|
| 65 | /** |
---|
[19662] | 66 | * SC_Queryインスタンスに設定された検索条件を元に並び替え済みの検索結果商品IDの配列を取得する。 |
---|
[18815] | 67 | * |
---|
| 68 | * 検索条件は, SC_Query::getWhere() 関数で設定しておく必要があります. |
---|
| 69 | * |
---|
| 70 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
| 71 | * @param array $arrVal 検索パラメータの配列 |
---|
| 72 | * @return array 商品IDの配列 |
---|
| 73 | */ |
---|
[19662] | 74 | function findProductIdsOrder(&$objQuery, $arrVal = array(), $where) { |
---|
[18815] | 75 | $table = <<< __EOS__ |
---|
| 76 | dtb_products AS alldtl |
---|
[19662] | 77 | JOIN dtb_products_class AS T1 |
---|
| 78 | ON alldtl.product_id = T1.product_id |
---|
[18815] | 79 | JOIN dtb_product_categories AS T2 |
---|
| 80 | ON alldtl.product_id = T2.product_id |
---|
| 81 | JOIN dtb_category |
---|
| 82 | ON T2.category_id = dtb_category.category_id |
---|
| 83 | __EOS__; |
---|
[19662] | 84 | $objQuery->setGroupBy('alldtl.product_id'); |
---|
| 85 | if(is_array($this->arrOrderData) and $objQuery->order == ""){ |
---|
| 86 | $o_col = $this->arrOrderData['col']; |
---|
| 87 | $o_table = $this->arrOrderData['table']; |
---|
| 88 | $o_order = $this->arrOrderData['order']; |
---|
| 89 | $order = <<< __EOS__ |
---|
| 90 | ( |
---|
| 91 | SELECT $o_col |
---|
| 92 | FROM |
---|
| 93 | $o_table as T2 |
---|
| 94 | WHERE T2.product_id = alldtl.product_id |
---|
| 95 | ORDER BY T2.$o_col $o_order |
---|
| 96 | LIMIT 1 |
---|
| 97 | ) $o_order, product_id |
---|
| 98 | __EOS__; |
---|
| 99 | $objQuery->setOrder($order); |
---|
| 100 | } |
---|
[18815] | 101 | $results = $objQuery->select('alldtl.product_id', $table, "", $arrVal, |
---|
| 102 | MDB2_FETCHMODE_ORDERED); |
---|
| 103 | foreach ($results as $val) { |
---|
| 104 | $resultValues[] = $val[0]; |
---|
[18277] | 105 | } |
---|
[19662] | 106 | return $resultValues; |
---|
[18277] | 107 | } |
---|
| 108 | |
---|
[18815] | 109 | /** |
---|
[19662] | 110 | * SC_Queryインスタンスに設定された検索条件をもとに対象商品数を取得する. |
---|
| 111 | * |
---|
| 112 | * 検索条件は, SC_Query::getWhere() 関数で設定しておく必要があります. |
---|
| 113 | * |
---|
| 114 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
| 115 | * @param array $arrVal 検索パラメータの配列 |
---|
| 116 | * @return array 対象商品ID数 |
---|
| 117 | */ |
---|
| 118 | function findProductCount(&$objQuery, $arrVal = array()) { |
---|
| 119 | $table = <<< __EOS__ |
---|
| 120 | dtb_products AS alldtl |
---|
| 121 | JOIN dtb_product_categories AS T2 |
---|
| 122 | ON alldtl.product_id = T2.product_id |
---|
| 123 | JOIN dtb_category |
---|
| 124 | ON T2.category_id = dtb_category.category_id |
---|
| 125 | __EOS__; |
---|
| 126 | $objQuery->setGroupBy('alldtl.product_id'); |
---|
| 127 | $sql_base = $objQuery->getSql('alldtl.product_id',$table); |
---|
| 128 | return $objQuery->getOne( "SELECT count(*) FROM ( $sql_base ) as t" , $arrVal); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
[18815] | 132 | * SC_Queryインスタンスに設定された検索条件をもとに商品一覧の配列を取得する. |
---|
| 133 | * |
---|
| 134 | * 主に SC_Product::findProductIds() で取得した商品IDを検索条件にし, |
---|
| 135 | * SC_Query::setOrder() や SC_Query::setLimitOffset() を設定して, 商品一覧 |
---|
| 136 | * の配列を取得する. |
---|
| 137 | * |
---|
| 138 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
| 139 | * @param array $arrVal 検索パラメータ(ソート条件)の配列 |
---|
| 140 | * @return array 商品一覧の配列 |
---|
| 141 | */ |
---|
| 142 | function lists(&$objQuery, $arrVal = array()) { |
---|
| 143 | $col = <<< __EOS__ |
---|
| 144 | product_id |
---|
| 145 | ,product_code_min |
---|
| 146 | ,product_code_max |
---|
| 147 | ,name |
---|
| 148 | ,comment1 |
---|
| 149 | ,comment2 |
---|
| 150 | ,comment3 |
---|
| 151 | ,main_list_comment |
---|
| 152 | ,main_image |
---|
| 153 | ,main_list_image |
---|
| 154 | ,price01_min |
---|
| 155 | ,price01_max |
---|
| 156 | ,price02_min |
---|
| 157 | ,price02_max |
---|
| 158 | ,stock_min |
---|
| 159 | ,stock_max |
---|
| 160 | ,stock_unlimited_min |
---|
| 161 | ,stock_unlimited_max |
---|
| 162 | ,deliv_date_id |
---|
| 163 | ,status |
---|
| 164 | ,del_flg |
---|
| 165 | ,update_date |
---|
| 166 | __EOS__; |
---|
[19662] | 167 | $res = $objQuery->select($col, $this->alldtlSQL($objQuery->where), |
---|
[18815] | 168 | "", $arrVal); |
---|
[19662] | 169 | return $res; |
---|
[18815] | 170 | } |
---|
| 171 | |
---|
| 172 | /** |
---|
| 173 | * 商品詳細を取得する. |
---|
| 174 | * |
---|
| 175 | * @param integer $productId 商品ID |
---|
| 176 | * @return array 商品詳細情報の配列 |
---|
| 177 | */ |
---|
| 178 | function getDetail($productId) { |
---|
| 179 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 180 | $result = $objQuery->select("*", $this->alldtlSQL("product_id = ?"), |
---|
| 181 | "product_id = ?", |
---|
| 182 | array($productId, $productId)); |
---|
| 183 | return $result[0]; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /** |
---|
[18829] | 187 | * 商品詳細情報と商品規格を取得する. |
---|
| 188 | * |
---|
| 189 | * @param integer $productClassId 商品規格ID |
---|
| 190 | * @return array 商品詳細情報と商品規格の配列 |
---|
| 191 | */ |
---|
| 192 | function getDetailAndProductsClass($productClassId) { |
---|
| 193 | $result = $this->getProductsClass($productClassId); |
---|
| 194 | $result = array_merge($result, $this->getDetail($result['product_id'])); |
---|
| 195 | return $result; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
[18815] | 199 | * 商品IDに紐づく商品規格を自分自身に設定する. |
---|
| 200 | * |
---|
| 201 | * 引数の商品IDの配列に紐づく商品規格を取得し, 自分自身のフィールドに |
---|
| 202 | * 設定する. |
---|
| 203 | * |
---|
| 204 | * @param array $arrProductId 商品ID の配列 |
---|
| 205 | * @return void |
---|
| 206 | */ |
---|
| 207 | function setProductsClassByProductIds($arrProductId) { |
---|
| 208 | |
---|
[20048] | 209 | $arrProductsClass = array(); |
---|
[18815] | 210 | foreach ($arrProductId as $productId) { |
---|
[20048] | 211 | $arrProductClass = $this->getProductsClassFullByProductId($productId); |
---|
[18815] | 212 | |
---|
[18277] | 213 | $classCats1 = array(); |
---|
| 214 | $classCats1[''] = '選択してください'; |
---|
[18815] | 215 | |
---|
[18277] | 216 | // 規格1クラス名 |
---|
| 217 | $this->className1[$productId] = |
---|
[18815] | 218 | isset($arrProductClass[0]['class_name1']) |
---|
| 219 | ? $arrProductClass[0]['class_name1'] |
---|
[18277] | 220 | : ''; |
---|
| 221 | |
---|
| 222 | // 規格2クラス名 |
---|
| 223 | $this->className2[$productId] = |
---|
[18815] | 224 | isset($arrProductClass[0]['class_name2']) |
---|
| 225 | ? $arrProductClass[0]['class_name2'] |
---|
[18277] | 226 | : ''; |
---|
[18815] | 227 | |
---|
[18277] | 228 | // 規格1が設定されている |
---|
[18815] | 229 | $this->classCat1_find[$productId] = (!SC_Utils_Ex::isBlank($arrProductClass[0]['classcategory_id1'])); |
---|
[18277] | 230 | // 規格2が設定されている |
---|
[18815] | 231 | $this->classCat2_find[$productId] = (!SC_Utils_Ex::isBlank($arrProductClass[0]['classcategory_id2'])); |
---|
[18277] | 232 | |
---|
| 233 | $this->stock_find[$productId] = false; |
---|
| 234 | $classCategories = array(); |
---|
| 235 | $classCategories['']['']['name'] = '選択してください'; |
---|
[18829] | 236 | $classCategories['']['']['product_class_id'] = $arrProductClass[0]['product_class_id']; |
---|
[18882] | 237 | // 商品種別 |
---|
| 238 | $classCategories['']['']['product_type'] = $arrProductClass[0]['product_type_id']; |
---|
[18829] | 239 | $this->product_class_id[$productId] = $arrProductClass[0]['product_class_id']; |
---|
[18882] | 240 | // 商品種別 |
---|
| 241 | $this->product_type[$productId] = $arrProductClass[0]['product_type_id']; |
---|
[18277] | 242 | foreach ($arrProductClass as $productsClass) { |
---|
[20048] | 243 | $classCats2 = array(); |
---|
[18277] | 244 | $productsClass1 = $productsClass['classcategory_id1']; |
---|
| 245 | $productsClass2 = $productsClass['classcategory_id2']; |
---|
| 246 | // 在庫 |
---|
| 247 | $stock_find_class = ($productsClass['stock_unlimited'] || $productsClass['stock'] > 0); |
---|
[18815] | 248 | |
---|
[20048] | 249 | $classCats2['classcategory_id2'] = $productsClass2; |
---|
| 250 | $classCats2['name'] = $productsClass['classcategory_name2'] . ($stock_find_class ? '' : ' (品切れ中)'); |
---|
[18815] | 251 | |
---|
[20048] | 252 | $classCats2['stock_find'] = $stock_find_class; |
---|
[18815] | 253 | |
---|
[18277] | 254 | if ($stock_find_class) { |
---|
| 255 | $this->stock_find[$productId] = true; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | if (!in_array($classcat_id1, $classCats1)) { |
---|
[18852] | 259 | $classCats1[$productsClass1] = $productsClass['classcategory_name1'] |
---|
[18277] | 260 | . ($productsClass2 == 0 && !$stock_find_class ? ' (品切れ中)' : ''); |
---|
| 261 | } |
---|
[18815] | 262 | |
---|
[18277] | 263 | // 価格 |
---|
[20048] | 264 | $classCats2['price01'] |
---|
[18277] | 265 | = strlen($productsClass['price01']) |
---|
[19680] | 266 | ? number_format(SC_Helper_DB_Ex::sfCalcIncTax($productsClass['price01'])) |
---|
[18277] | 267 | : ''; |
---|
[18815] | 268 | |
---|
[20048] | 269 | $classCats2['price02'] |
---|
[18277] | 270 | = strlen($productsClass['price02']) |
---|
[19680] | 271 | ? number_format(SC_Helper_DB_Ex::sfCalcIncTax($productsClass['price02'])) |
---|
[18277] | 272 | : ''; |
---|
[18815] | 273 | |
---|
[18277] | 274 | // ポイント |
---|
| 275 | // XXX sfPrePoint() の第4パラメータは、処理にバグがあるため現状省略している。(http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=3540&forum=1&post_id=13853#forumpost13853) |
---|
[20048] | 276 | $classCats2['point'] |
---|
[18277] | 277 | = SC_Utils_Ex::sfPrePoint($productsClass['price02'], $productsClass['point_rate']); |
---|
[18815] | 278 | |
---|
[18278] | 279 | // 商品コード |
---|
[20048] | 280 | $classCats2['product_code'] = $productsClass['product_code']; |
---|
[18829] | 281 | // 商品規格ID |
---|
[20048] | 282 | $classCats2['product_class_id'] = $productsClass['product_class_id']; |
---|
[18882] | 283 | // 商品種別 |
---|
[20048] | 284 | $classCats2['product_type'] = $productsClass['product_type_id']; |
---|
| 285 | |
---|
| 286 | // #929(GC8 規格のプルダウン順序表示不具合)対応のため、2次キーは「#」を前置 |
---|
| 287 | $classCategories[$productsClass1]['#'] = array( |
---|
| 288 | 'classcategory_id2' => '', |
---|
| 289 | 'name' => '選択してください', |
---|
| 290 | ); |
---|
| 291 | $classCategories[$productsClass1]['#' . $productsClass2] = $classCats2; |
---|
[18277] | 292 | } |
---|
[18815] | 293 | |
---|
[18277] | 294 | $this->classCategories[$productId] = $classCategories; |
---|
[18815] | 295 | |
---|
[18277] | 296 | // 規格1 |
---|
| 297 | $this->classCats1[$productId] = $classCats1; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
[18815] | 301 | /** |
---|
[18829] | 302 | * SC_Query インスタンスに設定された検索条件を使用して商品規格を取得する. |
---|
[18815] | 303 | * |
---|
[18829] | 304 | * @param SC_Query $objQuery SC_Queryインスタンス |
---|
| 305 | * @param array $params 検索パラメータの配列 |
---|
[18815] | 306 | * @return array 商品規格の配列 |
---|
| 307 | */ |
---|
[18829] | 308 | function getProductsClassByQuery(&$objQuery, $params) { |
---|
[18815] | 309 | // 末端の規格を取得 |
---|
| 310 | $col = <<< __EOS__ |
---|
| 311 | T1.product_id, |
---|
| 312 | T1.stock, |
---|
| 313 | T1.stock_unlimited, |
---|
| 314 | T1.price01, |
---|
| 315 | T1.price02, |
---|
| 316 | T1.point_rate, |
---|
| 317 | T1.product_code, |
---|
| 318 | T1.product_class_id, |
---|
| 319 | T1.del_flg, |
---|
[18882] | 320 | T1.product_type_id, |
---|
[18819] | 321 | T1.down_filename, |
---|
| 322 | T1.down_realfilename, |
---|
[18815] | 323 | T2.class_combination_id, |
---|
| 324 | T2.parent_class_combination_id, |
---|
| 325 | T2.classcategory_id, |
---|
| 326 | T2.level, |
---|
[18852] | 327 | T3.name AS classcategory_name, |
---|
[18815] | 328 | T4.name AS class_name, |
---|
| 329 | T4.class_id |
---|
| 330 | __EOS__; |
---|
| 331 | $table = <<< __EOS__ |
---|
| 332 | dtb_products_class T1 |
---|
| 333 | LEFT JOIN dtb_class_combination T2 |
---|
| 334 | ON T1.class_combination_id = T2.class_combination_id |
---|
| 335 | LEFT JOIN dtb_classcategory T3 |
---|
| 336 | ON T2.classcategory_id = T3.classcategory_id |
---|
| 337 | LEFT JOIN dtb_class T4 |
---|
| 338 | ON T3.class_id = T4.class_id |
---|
| 339 | __EOS__; |
---|
[18829] | 340 | $arrRet = $objQuery->select($col, $table, "", $params); |
---|
[18815] | 341 | $levels = array(); |
---|
| 342 | $parents = array(); |
---|
[18819] | 343 | foreach ($arrRet as $rows) { |
---|
[18815] | 344 | $levels[] = $rows['level']; |
---|
| 345 | $parents[] = $rows['parent_class_combination_id']; |
---|
| 346 | } |
---|
| 347 | $level = max($levels); |
---|
| 348 | $parentsClass = array(); |
---|
| 349 | // 階層分の親を取得 |
---|
| 350 | for ($i = 0; $i < $level -1; $i++) { |
---|
| 351 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 352 | $objQuery->setWhere('T1.class_combination_id IN (' . implode(', ', array_pad(array(), count($parents), '?')) . ')'); |
---|
| 353 | |
---|
| 354 | $col = <<< __EOS__ |
---|
| 355 | T1.class_combination_id, |
---|
| 356 | T1.classcategory_id, |
---|
| 357 | T1.parent_class_combination_id, |
---|
| 358 | T1.level, |
---|
[18852] | 359 | T2.name AS classcategory_name, |
---|
[18815] | 360 | T3.name AS class_name, |
---|
| 361 | T3.class_id |
---|
| 362 | __EOS__; |
---|
| 363 | $table = <<< __EOS__ |
---|
| 364 | dtb_class_combination T1 |
---|
| 365 | LEFT JOIN dtb_classcategory T2 |
---|
| 366 | ON T1.classcategory_id = T2.classcategory_id |
---|
| 367 | LEFT JOIN dtb_class T3 |
---|
| 368 | ON T2.class_id = T3.class_id |
---|
| 369 | __EOS__; |
---|
| 370 | |
---|
| 371 | $arrParents = $objQuery->select($col, $table, "", $parents); |
---|
| 372 | |
---|
| 373 | unset($parents); |
---|
| 374 | foreach ($arrParents as $rows) { |
---|
| 375 | $parents[] = $rows['parent_class_combination_id']; |
---|
| 376 | |
---|
| 377 | foreach ($arrRet as $child) { |
---|
| 378 | if ($child['parent_class_combination_id'] |
---|
| 379 | == $rows['class_combination_id']) { |
---|
| 380 | $rows['product_id'] = $child['product_id']; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | $tmpParents[] = $rows; |
---|
| 384 | } |
---|
| 385 | $parentsClass = array_merge($parentsClass, $tmpParents); |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | // 末端から枝を作成 |
---|
| 389 | $tmpClass = array_merge($arrRet, $parentsClass); |
---|
| 390 | |
---|
| 391 | foreach ($tmpClass as $val) { |
---|
| 392 | $val['class_id' . $val['level']] = $val['class_id']; |
---|
| 393 | $val['class_name' . $val['level']] = $val['class_name']; |
---|
[18852] | 394 | $val['classcategory_name' . $val['level']] = $val['classcategory_name']; |
---|
[18815] | 395 | $val['classcategory_id' . $val['level']] = $val['classcategory_id']; |
---|
| 396 | $arrProductsClass[] = $val; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | return $arrProductsClass; |
---|
[18277] | 400 | } |
---|
[18815] | 401 | |
---|
| 402 | /** |
---|
[18829] | 403 | * 商品規格IDから商品規格を取得する. |
---|
| 404 | */ |
---|
| 405 | function getProductsClass($productClassId) { |
---|
| 406 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 407 | $objQuery->setWhere('product_class_id = ?'); |
---|
| 408 | $objQuery->setOrder("T2.level DESC"); |
---|
| 409 | $results = $this->getProductsClassByQuery($objQuery, $productClassId); |
---|
| 410 | $productsClass = $this->getProductsClassFull($results); |
---|
| 411 | return $productsClass[0]; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | * 複数の商品IDに紐づいた, 商品規格を取得する. |
---|
| 416 | * |
---|
| 417 | * @param array $productIds 商品IDの配列 |
---|
| 418 | * @return array 商品規格の配列 |
---|
| 419 | */ |
---|
| 420 | function getProductsClassByProductIds($productIds = array()) { |
---|
| 421 | if (empty($productIds)) { |
---|
| 422 | return array(); |
---|
| 423 | } |
---|
| 424 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 425 | $objQuery->setWhere('product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')'); |
---|
| 426 | $objQuery->setOrder("T2.level DESC"); |
---|
| 427 | return $this->getProductsClassByQuery($objQuery, $productIds); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | /** |
---|
[18815] | 431 | * 商品IDに紐づいた, 商品規格を階層ごとに取得する. |
---|
| 432 | * |
---|
[18829] | 433 | * @param array $productId 商品ID |
---|
[18815] | 434 | * @return array 階層ごとの商品規格の配列 |
---|
| 435 | */ |
---|
| 436 | function getProductsClassLevelByProductId($productId) { |
---|
| 437 | $results = $this->getProductsClassByProductIds(array($productId)); |
---|
[18829] | 438 | return $this->getProductsClassLevel($results); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | /** |
---|
| 442 | * 商品IDに紐づいた, 商品規格をすべての組み合わせごとに取得する. |
---|
| 443 | * |
---|
| 444 | * @param array $productId 商品ID |
---|
| 445 | * @return array すべての組み合わせの商品規格の配列 |
---|
| 446 | */ |
---|
| 447 | function getProductsClassFullByProductId($productId) { |
---|
| 448 | $results = $this->getProductsClassByProductIds(array($productId)); |
---|
| 449 | return $this->getProductsClassFull($results); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | /** |
---|
| 453 | * 商品規格の配列から, 商品規格を階層ごとに取得する. |
---|
| 454 | * |
---|
| 455 | * @access private |
---|
| 456 | * @param array $productsClassResults 商品規格の結果の配列 |
---|
| 457 | * @return array 階層ごとの商品規格の配列 |
---|
| 458 | */ |
---|
| 459 | function getProductsClassLevel($productsClassResults) { |
---|
| 460 | foreach ($productsClassResults as $row) { |
---|
[18815] | 461 | $productsClassLevel["level" . $row['level']][] = $row; |
---|
| 462 | } |
---|
| 463 | return $productsClassLevel; |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | /** |
---|
[18829] | 467 | * 商品規格の配列から, 商品規格のすべての組み合わせを取得する. |
---|
[18815] | 468 | * |
---|
[18829] | 469 | * @access private |
---|
| 470 | * @param array $productsClassResults 商品規格の結果の配列 |
---|
| 471 | * @ array 階層ごとの商品規格の配列 |
---|
[18815] | 472 | */ |
---|
[18829] | 473 | function getProductsClassFull($productsClassResults) { |
---|
| 474 | $results = $this->getProductsClassLevel($productsClassResults); |
---|
[18815] | 475 | $productsClass = array(); |
---|
[18829] | 476 | if (SC_Utils_Ex::isBlank($results["level1"]) |
---|
| 477 | && SC_Utils_Ex::isBlank($results["level2"])) { |
---|
[18820] | 478 | return $results["level"]; |
---|
| 479 | } |
---|
| 480 | |
---|
[18815] | 481 | foreach ($results["level1"] as $level1) { |
---|
| 482 | foreach ($results["level2"] as $level2) { |
---|
| 483 | if ($level2['parent_class_combination_id'] == $level1['class_combination_id']) { |
---|
| 484 | $level1 = array_merge($level1, $level2); |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | $productsClass[] = $level1; |
---|
| 488 | } |
---|
| 489 | return $productsClass; |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | /** |
---|
[18862] | 493 | * 商品IDをキーにした, 商品ステータスIDの配列を取得する. |
---|
| 494 | * |
---|
| 495 | * @param array 商品ID の配列 |
---|
| 496 | * @return array 商品IDをキーにした商品ステータスIDの配列 |
---|
| 497 | */ |
---|
| 498 | function getProductStatus($productIds) { |
---|
[20003] | 499 | if (empty($productIds)) { |
---|
| 500 | return array(); |
---|
| 501 | } |
---|
[18862] | 502 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
[20003] | 503 | $cols = 'product_id, product_status_id'; |
---|
| 504 | $from = 'dtb_product_status'; |
---|
| 505 | $where = 'del_flg = 0 AND product_id IN (' . implode(', ', array_pad(array(), count($productIds), '?')) . ')'; |
---|
| 506 | $productStatus = $objQuery->select($cols, $from, $where, $productIds); |
---|
[18862] | 507 | $results = array(); |
---|
| 508 | foreach ($productStatus as $status) { |
---|
| 509 | $results[$status['product_id']][] = $status['product_status_id']; |
---|
| 510 | } |
---|
| 511 | return $results; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | /** |
---|
[18863] | 515 | * 商品ステータスを設定する. |
---|
| 516 | * |
---|
| 517 | * TODO 現在は DELETE/INSERT だが, UPDATE を検討する. |
---|
| 518 | * |
---|
| 519 | * @param integer $productId 商品ID |
---|
| 520 | * @param array $productStatusIds ON にする商品ステータスIDの配列 |
---|
| 521 | */ |
---|
| 522 | function setProductStatus($productId, $productStatusIds) { |
---|
| 523 | |
---|
| 524 | $val['product_id'] = $productId; |
---|
| 525 | $val['creator_id'] = $_SESSION['member_id']; |
---|
| 526 | $val['create_date'] = 'Now()'; |
---|
| 527 | $val['update_date'] = 'Now()'; |
---|
| 528 | $val['del_flg'] = '0'; |
---|
| 529 | |
---|
| 530 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 531 | $objQuery->delete('dtb_product_status', 'product_id = ?', array($productId)); |
---|
| 532 | foreach ($productStatusIds as $productStatusId) { |
---|
[20386] | 533 | if($productStatusId == '') continue; |
---|
[18863] | 534 | $val['product_status_id'] = $productStatusId; |
---|
| 535 | $objQuery->insert('dtb_product_status', $val); |
---|
| 536 | } |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | /** |
---|
[18852] | 540 | * 商品詳細の結果から, 購入制限数を取得する. |
---|
| 541 | * |
---|
| 542 | * getDetailAndProductsClass() の結果から, 購入制限数を取得する. |
---|
| 543 | * |
---|
| 544 | * @param array $p 商品詳細の検索結果の配列 |
---|
| 545 | * @return integer 商品詳細の結果から求めた購入制限数. |
---|
| 546 | * @see getDetailAndProductsClass() |
---|
| 547 | */ |
---|
| 548 | function getBuyLimit($p) { |
---|
| 549 | $limit = null; |
---|
| 550 | if ($p['stock_unlimited'] != '1' && is_numeric($p['sale_limit'])) { |
---|
| 551 | $limit = min($p['sale_limit'], $p['stock']); |
---|
| 552 | } elseif (is_numeric($p['sale_limit'])) { |
---|
| 553 | $limit = $p['sale_limit']; |
---|
| 554 | } elseif ($p['stock_unlimited'] != '1') { |
---|
| 555 | $limit = $p['stock']; |
---|
| 556 | } |
---|
| 557 | return $limit; |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | /** |
---|
[18860] | 561 | * 在庫を減少させる. |
---|
| 562 | * |
---|
| 563 | * 指定の在庫数まで, 在庫を減少させる. |
---|
| 564 | * 減少させた結果, 在庫数が 0 未満になった場合, 引数 $quantity が 0 の場合は, |
---|
| 565 | * 在庫の減少を中止し, false を返す. |
---|
| 566 | * 在庫の減少に成功した場合は true を返す. |
---|
| 567 | * |
---|
| 568 | * @param integer $productClassId 商品規格ID |
---|
| 569 | * @param integer $quantity 減少させる在庫数 |
---|
| 570 | * @return boolean 在庫の減少に成功した場合 true; 失敗した場合 false |
---|
| 571 | */ |
---|
| 572 | function reduceStock($productClassId, $quantity) { |
---|
| 573 | |
---|
| 574 | $productsClass = $this->getDetailAndProductsClass($productClassId); |
---|
| 575 | if (($productsClass['stock_unlimited'] != '1' |
---|
| 576 | && $productsClass['stock'] < $quantity) |
---|
| 577 | || $quantity == 0) { |
---|
| 578 | return false; |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 582 | $objQuery->update('dtb_products_class', array(), |
---|
| 583 | "product_class_id = ?", array($productClassId), |
---|
| 584 | array('stock' => 'stock - ?'), array($quantity)); |
---|
| 585 | // TODO エラーハンドリング |
---|
| 586 | return true; |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | /** |
---|
[18815] | 590 | * 商品詳細の SQL を取得する. |
---|
| 591 | * |
---|
| 592 | * @param string $where 商品詳細の WHERE 句 |
---|
| 593 | * @return string 商品詳細の SQL |
---|
| 594 | */ |
---|
| 595 | function alldtlSQL($where = "") { |
---|
| 596 | $whereCause = ""; |
---|
| 597 | if (!SC_Utils_Ex::isBlank($where)) { |
---|
| 598 | $whereCause = " WHERE " . $where; |
---|
| 599 | } |
---|
[18821] | 600 | /* |
---|
| 601 | * point_rate は商品規格(dtb_products_class)ごとに保持しているが, |
---|
| 602 | * 商品(dtb_products)ごとの設定なので MAX のみを取得する. |
---|
| 603 | */ |
---|
[18815] | 604 | $sql = <<< __EOS__ |
---|
| 605 | ( |
---|
| 606 | SELECT dtb_products.product_id, |
---|
| 607 | dtb_products.name, |
---|
| 608 | dtb_products.maker_id, |
---|
| 609 | dtb_products.status, |
---|
| 610 | dtb_products.comment1, |
---|
| 611 | dtb_products.comment2, |
---|
| 612 | dtb_products.comment3, |
---|
| 613 | dtb_products.comment4, |
---|
| 614 | dtb_products.comment5, |
---|
| 615 | dtb_products.comment6, |
---|
| 616 | dtb_products.note, |
---|
| 617 | dtb_products.main_list_comment, |
---|
| 618 | dtb_products.main_list_image, |
---|
| 619 | dtb_products.main_comment, |
---|
| 620 | dtb_products.main_image, |
---|
| 621 | dtb_products.main_large_image, |
---|
| 622 | dtb_products.sub_title1, |
---|
| 623 | dtb_products.sub_comment1, |
---|
| 624 | dtb_products.sub_image1, |
---|
| 625 | dtb_products.sub_large_image1, |
---|
| 626 | dtb_products.sub_title2, |
---|
| 627 | dtb_products.sub_comment2, |
---|
| 628 | dtb_products.sub_image2, |
---|
| 629 | dtb_products.sub_large_image2, |
---|
| 630 | dtb_products.sub_title3, |
---|
| 631 | dtb_products.sub_comment3, |
---|
| 632 | dtb_products.sub_image3, |
---|
| 633 | dtb_products.sub_large_image3, |
---|
| 634 | dtb_products.sub_title4, |
---|
| 635 | dtb_products.sub_comment4, |
---|
| 636 | dtb_products.sub_image4, |
---|
| 637 | dtb_products.sub_large_image4, |
---|
| 638 | dtb_products.sub_title5, |
---|
| 639 | dtb_products.sub_comment5, |
---|
| 640 | dtb_products.sub_image5, |
---|
| 641 | dtb_products.sub_large_image5, |
---|
| 642 | dtb_products.sub_title6, |
---|
| 643 | dtb_products.sub_comment6, |
---|
| 644 | dtb_products.sub_image6, |
---|
| 645 | dtb_products.sub_large_image6, |
---|
| 646 | dtb_products.del_flg, |
---|
| 647 | dtb_products.creator_id, |
---|
| 648 | dtb_products.create_date, |
---|
| 649 | dtb_products.update_date, |
---|
| 650 | dtb_products.deliv_date_id, |
---|
| 651 | T4.product_code_min, |
---|
| 652 | T4.product_code_max, |
---|
| 653 | T4.price01_min, |
---|
| 654 | T4.price01_max, |
---|
| 655 | T4.price02_min, |
---|
| 656 | T4.price02_max, |
---|
| 657 | T4.stock_min, |
---|
| 658 | T4.stock_max, |
---|
| 659 | T4.stock_unlimited_min, |
---|
| 660 | T4.stock_unlimited_max, |
---|
[18821] | 661 | T4.point_rate, |
---|
[18815] | 662 | T4.class_count |
---|
| 663 | FROM dtb_products |
---|
| 664 | JOIN ( |
---|
| 665 | SELECT product_id, |
---|
| 666 | MIN(product_code) AS product_code_min, |
---|
| 667 | MAX(product_code) AS product_code_max, |
---|
| 668 | MIN(price01) AS price01_min, |
---|
| 669 | MAX(price01) AS price01_max, |
---|
| 670 | MIN(price02) AS price02_min, |
---|
| 671 | MAX(price02) AS price02_max, |
---|
| 672 | MIN(stock) AS stock_min, |
---|
| 673 | MAX(stock) AS stock_max, |
---|
| 674 | MIN(stock_unlimited) AS stock_unlimited_min, |
---|
| 675 | MAX(stock_unlimited) AS stock_unlimited_max, |
---|
[18821] | 676 | MAX(point_rate) AS point_rate, |
---|
[18815] | 677 | COUNT(*) as class_count |
---|
| 678 | FROM dtb_products_class |
---|
| 679 | $whereCause |
---|
| 680 | GROUP BY product_id |
---|
| 681 | ) AS T4 |
---|
| 682 | ON dtb_products.product_id = T4.product_id |
---|
| 683 | ) AS alldtl |
---|
| 684 | __EOS__; |
---|
| 685 | return $sql; |
---|
| 686 | } |
---|
[18826] | 687 | |
---|
| 688 | /** |
---|
[19742] | 689 | * 商品規格詳細の SQL を取得する. |
---|
| 690 | * |
---|
| 691 | * MEMO: 2.4系 vw_product_classに相当(?)するイメージ |
---|
| 692 | * |
---|
| 693 | * @param string $where 商品詳細の WHERE 句 |
---|
| 694 | * @return string 商品規格詳細の SQL |
---|
| 695 | */ |
---|
| 696 | function prdclsSQL($where = "") { |
---|
| 697 | $whereCause = ""; |
---|
| 698 | if (!SC_Utils_Ex::isBlank($where)) { |
---|
| 699 | $whereCause = " WHERE " . $where; |
---|
| 700 | } |
---|
| 701 | $sql = <<< __EOS__ |
---|
| 702 | ( |
---|
| 703 | SELECT dtb_products.*, |
---|
| 704 | dtb_products_class.product_class_id, |
---|
| 705 | dtb_products_class.class_combination_id, |
---|
| 706 | dtb_products_class.product_type_id, |
---|
| 707 | dtb_products_class.product_code, |
---|
| 708 | dtb_products_class.stock, |
---|
| 709 | dtb_products_class.stock_unlimited, |
---|
| 710 | dtb_products_class.sale_limit, |
---|
| 711 | dtb_products_class.price01, |
---|
| 712 | dtb_products_class.price02, |
---|
| 713 | dtb_products_class.deliv_fee, |
---|
| 714 | dtb_products_class.point_rate, |
---|
| 715 | dtb_products_class.down_filename, |
---|
| 716 | dtb_products_class.down_realfilename, |
---|
| 717 | dtb_class_combination.parent_class_combination_id, |
---|
| 718 | dtb_class_combination.classcategory_id, |
---|
| 719 | dtb_class_combination.level as classlevel, |
---|
| 720 | Tpcm.classcategory_id as parent_classcategory_id, |
---|
| 721 | Tpcm.level as parent_classlevel, |
---|
| 722 | Tcc1.class_id as class_id, |
---|
| 723 | Tcc1.name as classcategory_name, |
---|
| 724 | Tcc2.class_id as parent_class_id, |
---|
| 725 | Tcc2.name as parent_classcategory_name |
---|
| 726 | FROM dtb_products |
---|
| 727 | LEFT JOIN dtb_products_class |
---|
| 728 | ON dtb_products.product_id = dtb_products_class.product_id |
---|
| 729 | LEFT JOIN dtb_class_combination |
---|
| 730 | ON dtb_products_class.class_combination_id = dtb_class_combination.class_combination_id |
---|
| 731 | LEFT JOIN dtb_class_combination as Tpcm |
---|
| 732 | ON dtb_class_combination.parent_class_combination_id = Tpcm.class_combination_id |
---|
| 733 | LEFT JOIN dtb_classcategory as Tcc1 |
---|
| 734 | ON dtb_class_combination.classcategory_id = Tcc1.classcategory_id |
---|
| 735 | LEFT JOIN dtb_classcategory as Tcc2 |
---|
| 736 | ON Tpcm.classcategory_id = Tcc2.classcategory_id |
---|
[19746] | 737 | $whereCause |
---|
[19742] | 738 | ) as prdcls |
---|
| 739 | __EOS__; |
---|
| 740 | return $sql; |
---|
| 741 | } |
---|
[20148] | 742 | |
---|
[19742] | 743 | /** |
---|
[18826] | 744 | * 商品規格ID1、2に紐づいた,product_class_idを取得する. |
---|
| 745 | * |
---|
| 746 | * @param int $productId 商品ID |
---|
| 747 | * @param int $classcategory_id1 商品規格ID1 |
---|
| 748 | * @param int $classcategory_id2 商品規格ID2 |
---|
| 749 | * @return string product_class_id |
---|
| 750 | */ |
---|
| 751 | function getClasscategoryIdsByProductClassId($productId, $classcategory_id1, $classcategory_id2) { |
---|
| 752 | $objQuery = new SC_Query(); |
---|
| 753 | $col = "T1.product_id AS product_id,T1.product_class_id AS product_class_id,T1.classcategory_id1 AS classcategory_id1,T1.classcategory_id2 AS classcategory_id2"; |
---|
| 754 | $table = <<< __EOS__ |
---|
| 755 | (SELECT |
---|
| 756 | pc.product_code AS product_code, |
---|
| 757 | pc.product_id AS product_id, |
---|
| 758 | pc.product_class_id AS product_class_id, |
---|
| 759 | pc.class_combination_id AS class_combination_id, |
---|
| 760 | COALESCE(cc2.classcategory_id,0) AS classcategory_id1, |
---|
| 761 | COALESCE(cc1.classcategory_id,0) AS classcategory_id2 |
---|
| 762 | FROM |
---|
| 763 | dtb_products_class pc LEFT JOIN dtb_class_combination cc1 ON pc.class_combination_id = cc1.class_combination_id |
---|
| 764 | LEFT JOIN dtb_class_combination cc2 ON cc1.parent_class_combination_id = cc2.class_combination_id) T1 |
---|
| 765 | __EOS__; |
---|
| 766 | $where = "T1.product_id = ? AND T1.classcategory_id1 = ? AND T1.classcategory_id2 = ?"; |
---|
| 767 | $arrRet = $objQuery->select($col, $table, $where, |
---|
| 768 | array($productId, $classcategory_id1, $classcategory_id2)); |
---|
| 769 | return $arrRet[0]['product_class_id']; |
---|
| 770 | } |
---|
| 771 | |
---|
[18277] | 772 | } |
---|
| 773 | ?> |
---|