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