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