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