[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 | * |
---|
[23124] | 197 | * @param integer $productId 商品ID |
---|
| 198 | * @return array 商品詳細情報の配列 |
---|
[18815] | 199 | */ |
---|
[23124] | 200 | public function getDetail($productId) |
---|
[22567] | 201 | { |
---|
[20507] | 202 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21708] | 203 | $arrProduct = $objQuery->getRow('*', $this->alldtlSQL('product_id = ?'), |
---|
[21514] | 204 | 'product_id = ?', |
---|
[18815] | 205 | array($productId, $productId)); |
---|
[23124] | 206 | $arrProduct = (array) $arrProduct; |
---|
[21708] | 207 | |
---|
| 208 | // 税込金額を設定する |
---|
| 209 | SC_Product_Ex::setIncTaxToProduct($arrProduct); |
---|
| 210 | |
---|
| 211 | return $arrProduct; |
---|
[18815] | 212 | } |
---|
| 213 | |
---|
| 214 | /** |
---|
[18829] | 215 | * 商品詳細情報と商品規格を取得する. |
---|
| 216 | * |
---|
[23124] | 217 | * @param integer $productClassId 商品規格ID |
---|
| 218 | * @return array 商品詳細情報と商品規格の配列 |
---|
[18829] | 219 | */ |
---|
[23124] | 220 | public function getDetailAndProductsClass($productClassId) |
---|
[22567] | 221 | { |
---|
[18829] | 222 | $result = $this->getProductsClass($productClassId); |
---|
| 223 | $result = array_merge($result, $this->getDetail($result['product_id'])); |
---|
[22507] | 224 | |
---|
[18829] | 225 | return $result; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | /** |
---|
[18815] | 229 | * 商品IDに紐づく商品規格を自分自身に設定する. |
---|
| 230 | * |
---|
| 231 | * 引数の商品IDの配列に紐づく商品規格を取得し, 自分自身のフィールドに |
---|
| 232 | * 設定する. |
---|
| 233 | * |
---|
[23124] | 234 | * @param array $arrProductId 商品ID の配列 |
---|
| 235 | * @param boolean $has_deleted 削除された商品規格も含む場合 true; 初期値 false |
---|
[18815] | 236 | * @return void |
---|
| 237 | */ |
---|
[23124] | 238 | public function setProductsClassByProductIds($arrProductId, $has_deleted = false) |
---|
[22567] | 239 | { |
---|
[18815] | 240 | foreach ($arrProductId as $productId) { |
---|
[21506] | 241 | $arrProductClasses = $this->getProductsClassFullByProductId($productId, $has_deleted); |
---|
[18815] | 242 | |
---|
[18277] | 243 | $classCats1 = array(); |
---|
[21245] | 244 | $classCats1['__unselected'] = '選択してください'; |
---|
[18815] | 245 | |
---|
[18277] | 246 | // 規格1クラス名 |
---|
| 247 | $this->className1[$productId] = |
---|
[21506] | 248 | isset($arrProductClasses[0]['class_name1']) |
---|
| 249 | ? $arrProductClasses[0]['class_name1'] |
---|
[18277] | 250 | : ''; |
---|
| 251 | |
---|
| 252 | // 規格2クラス名 |
---|
| 253 | $this->className2[$productId] = |
---|
[21506] | 254 | isset($arrProductClasses[0]['class_name2']) |
---|
| 255 | ? $arrProductClasses[0]['class_name2'] |
---|
[18277] | 256 | : ''; |
---|
[18815] | 257 | |
---|
[18277] | 258 | // 規格1が設定されている |
---|
[21506] | 259 | $this->classCat1_find[$productId] = $arrProductClasses[0]['classcategory_id1'] > 0; // 要変更ただし、他にも改修が必要となる |
---|
[18277] | 260 | // 規格2が設定されている |
---|
[21506] | 261 | $this->classCat2_find[$productId] = $arrProductClasses[0]['classcategory_id2'] > 0; // 要変更ただし、他にも改修が必要となる |
---|
[18277] | 262 | |
---|
| 263 | $this->stock_find[$productId] = false; |
---|
| 264 | $classCategories = array(); |
---|
[21245] | 265 | $classCategories['__unselected']['__unselected']['name'] = '選択してください'; |
---|
[21506] | 266 | $classCategories['__unselected']['__unselected']['product_class_id'] = $arrProductClasses[0]['product_class_id']; |
---|
[18882] | 267 | // 商品種別 |
---|
[21506] | 268 | $classCategories['__unselected']['__unselected']['product_type'] = $arrProductClasses[0]['product_type_id']; |
---|
| 269 | $this->product_class_id[$productId] = $arrProductClasses[0]['product_class_id']; |
---|
[18882] | 270 | // 商品種別 |
---|
[21506] | 271 | $this->product_type[$productId] = $arrProductClasses[0]['product_type_id']; |
---|
| 272 | foreach ($arrProductClasses as $arrProductsClass) { |
---|
| 273 | $arrClassCats2 = array(); |
---|
| 274 | $classcategory_id1 = $arrProductsClass['classcategory_id1']; |
---|
| 275 | $classcategory_id2 = $arrProductsClass['classcategory_id2']; |
---|
[18277] | 276 | // 在庫 |
---|
[21506] | 277 | $stock_find_class = ($arrProductsClass['stock_unlimited'] || $arrProductsClass['stock'] > 0); |
---|
[18815] | 278 | |
---|
[21506] | 279 | $arrClassCats2['classcategory_id2'] = $classcategory_id2; |
---|
| 280 | $arrClassCats2['name'] = $arrProductsClass['classcategory_name2'] . ($stock_find_class ? '' : ' (品切れ中)'); |
---|
[18815] | 281 | |
---|
[21506] | 282 | $arrClassCats2['stock_find'] = $stock_find_class; |
---|
[18815] | 283 | |
---|
[18277] | 284 | if ($stock_find_class) { |
---|
| 285 | $this->stock_find[$productId] = true; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | if (!in_array($classcat_id1, $classCats1)) { |
---|
[21506] | 289 | $classCats1[$classcategory_id1] = $arrProductsClass['classcategory_name1'] |
---|
| 290 | . ($classcategory_id2 == 0 && !$stock_find_class ? ' (品切れ中)' : ''); |
---|
[18277] | 291 | } |
---|
[18815] | 292 | |
---|
[18277] | 293 | // 価格 |
---|
[23024] | 294 | // TODO: ここでprice01,price02を税込みにしてよいのか? _inctax を付けるべき?要検証 |
---|
[21506] | 295 | $arrClassCats2['price01'] |
---|
| 296 | = strlen($arrProductsClass['price01']) |
---|
[22736] | 297 | ? number_format(SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProductsClass['price01'], $productId, $arrProductsClass['product_class_id'])) |
---|
[18277] | 298 | : ''; |
---|
[18815] | 299 | |
---|
[21506] | 300 | $arrClassCats2['price02'] |
---|
| 301 | = strlen($arrProductsClass['price02']) |
---|
[22736] | 302 | ? number_format(SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProductsClass['price02'], $productId, $arrProductsClass['product_class_id'])) |
---|
[18277] | 303 | : ''; |
---|
[18815] | 304 | |
---|
[18277] | 305 | // ポイント |
---|
[21506] | 306 | $arrClassCats2['point'] |
---|
| 307 | = number_format(SC_Utils_Ex::sfPrePoint($arrProductsClass['price02'], $arrProductsClass['point_rate'])); |
---|
[18815] | 308 | |
---|
[18278] | 309 | // 商品コード |
---|
[21506] | 310 | $arrClassCats2['product_code'] = $arrProductsClass['product_code']; |
---|
[18829] | 311 | // 商品規格ID |
---|
[21506] | 312 | $arrClassCats2['product_class_id'] = $arrProductsClass['product_class_id']; |
---|
[18882] | 313 | // 商品種別 |
---|
[21506] | 314 | $arrClassCats2['product_type'] = $arrProductsClass['product_type_id']; |
---|
[20048] | 315 | |
---|
| 316 | // #929(GC8 規格のプルダウン順序表示不具合)対応のため、2次キーは「#」を前置 |
---|
[21502] | 317 | if (!$this->classCat1_find[$productId]) { |
---|
[21506] | 318 | $classcategory_id1 = '__unselected2'; |
---|
[21263] | 319 | } |
---|
[21506] | 320 | $classCategories[$classcategory_id1]['#'] = array( |
---|
[20048] | 321 | 'classcategory_id2' => '', |
---|
| 322 | 'name' => '選択してください', |
---|
| 323 | ); |
---|
[21506] | 324 | $classCategories[$classcategory_id1]['#' . $classcategory_id2] = $arrClassCats2; |
---|
[18277] | 325 | } |
---|
[18815] | 326 | |
---|
[18277] | 327 | $this->classCategories[$productId] = $classCategories; |
---|
[18815] | 328 | |
---|
[18277] | 329 | // 規格1 |
---|
| 330 | $this->classCats1[$productId] = $classCats1; |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
[18815] | 334 | /** |
---|
[18829] | 335 | * SC_Query インスタンスに設定された検索条件を使用して商品規格を取得する. |
---|
[18815] | 336 | * |
---|
[23124] | 337 | * @param SC_Query $objQuery SC_Queryインスタンス |
---|
| 338 | * @param array $params 検索パラメーターの配列 |
---|
| 339 | * @return array 商品規格の配列 |
---|
[18815] | 340 | */ |
---|
[23124] | 341 | public function getProductsClassByQuery(&$objQuery, $params) |
---|
[22567] | 342 | { |
---|
[18815] | 343 | // 末端の規格を取得 |
---|
| 344 | $col = <<< __EOS__ |
---|
| 345 | T1.product_id, |
---|
| 346 | T1.stock, |
---|
| 347 | T1.stock_unlimited, |
---|
[20790] | 348 | T1.sale_limit, |
---|
[18815] | 349 | T1.price01, |
---|
| 350 | T1.price02, |
---|
| 351 | T1.point_rate, |
---|
| 352 | T1.product_code, |
---|
| 353 | T1.product_class_id, |
---|
| 354 | T1.del_flg, |
---|
[18882] | 355 | T1.product_type_id, |
---|
[18819] | 356 | T1.down_filename, |
---|
| 357 | T1.down_realfilename, |
---|
[21502] | 358 | T3.name AS classcategory_name1, |
---|
| 359 | T3.rank AS rank1, |
---|
| 360 | T4.name AS class_name1, |
---|
| 361 | T4.class_id AS class_id1, |
---|
| 362 | T1.classcategory_id1, |
---|
| 363 | T1.classcategory_id2, |
---|
| 364 | dtb_classcategory2.name AS classcategory_name2, |
---|
| 365 | dtb_classcategory2.rank AS rank2, |
---|
| 366 | dtb_class2.name AS class_name2, |
---|
| 367 | dtb_class2.class_id AS class_id2 |
---|
[18815] | 368 | __EOS__; |
---|
| 369 | $table = <<< __EOS__ |
---|
[21527] | 370 | dtb_products_class T1 |
---|
[18815] | 371 | LEFT JOIN dtb_classcategory T3 |
---|
[21527] | 372 | ON T1.classcategory_id1 = T3.classcategory_id |
---|
[18815] | 373 | LEFT JOIN dtb_class T4 |
---|
[21527] | 374 | ON T3.class_id = T4.class_id |
---|
[21502] | 375 | LEFT JOIN dtb_classcategory dtb_classcategory2 |
---|
[21527] | 376 | ON T1.classcategory_id2 = dtb_classcategory2.classcategory_id |
---|
[21502] | 377 | LEFT JOIN dtb_class dtb_class2 |
---|
[21527] | 378 | ON dtb_classcategory2.class_id = dtb_class2.class_id |
---|
[18815] | 379 | __EOS__; |
---|
[20595] | 380 | |
---|
[21931] | 381 | $objQuery->setOrder('T3.rank DESC, dtb_classcategory2.rank DESC'); // XXX |
---|
[21514] | 382 | $arrRet = $objQuery->select($col, $table, '', $params); |
---|
[18815] | 383 | |
---|
[21502] | 384 | return $arrRet; |
---|
[18277] | 385 | } |
---|
[18815] | 386 | |
---|
| 387 | /** |
---|
[18829] | 388 | * 商品規格IDから商品規格を取得する. |
---|
[20595] | 389 | * |
---|
| 390 | * 削除された商品規格は取得しない. |
---|
| 391 | * |
---|
[23124] | 392 | * @param integer $productClassId 商品規格ID |
---|
| 393 | * @return array 商品規格の配列 |
---|
[18829] | 394 | */ |
---|
[23124] | 395 | public function getProductsClass($productClassId) |
---|
[22567] | 396 | { |
---|
[20507] | 397 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20595] | 398 | $objQuery->setWhere('product_class_id = ? AND T1.del_flg = 0'); |
---|
[21502] | 399 | $arrRes = $this->getProductsClassByQuery($objQuery, $productClassId); |
---|
[22507] | 400 | |
---|
[23230] | 401 | $arrProduct = (array) $arrRes[0]; |
---|
| 402 | |
---|
| 403 | // 税込計算 |
---|
| 404 | if(!SC_Utils_Ex::isBlank($arrProduct['price01'])) { |
---|
| 405 | $arrProduct['price01_inctax'] = SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price01'], $arrProduct['product_id'], $productClassId); |
---|
| 406 | } |
---|
| 407 | if(!SC_Utils_Ex::isBlank($arrProduct['price02'])) { |
---|
| 408 | $arrProduct['price02_inctax'] = SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price02'], $arrProduct['product_id'], $productClassId); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | return $arrProduct; |
---|
[18829] | 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | * 複数の商品IDに紐づいた, 商品規格を取得する. |
---|
| 416 | * |
---|
[23124] | 417 | * @param array $productIds 商品IDの配列 |
---|
| 418 | * @param boolean $has_deleted 削除された商品規格も含む場合 true; 初期値 false |
---|
| 419 | * @return array 商品規格の配列 |
---|
[18829] | 420 | */ |
---|
[23124] | 421 | public function getProductsClassByProductIds($productIds = array(), $has_deleted = false) |
---|
[22567] | 422 | { |
---|
[18829] | 423 | if (empty($productIds)) { |
---|
| 424 | return array(); |
---|
| 425 | } |
---|
[20507] | 426 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21564] | 427 | $where = 'product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')'; |
---|
[20595] | 428 | if (!$has_deleted) { |
---|
| 429 | $where .= ' AND T1.del_flg = 0'; |
---|
| 430 | } |
---|
| 431 | $objQuery->setWhere($where); |
---|
[22507] | 432 | |
---|
[18829] | 433 | return $this->getProductsClassByQuery($objQuery, $productIds); |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | /** |
---|
[22960] | 437 | * 商品IDに紐づいた, 商品規格を全ての組み合わせごとに取得する. |
---|
[18829] | 438 | * |
---|
[23124] | 439 | * @param array $productId 商品ID |
---|
| 440 | * @param boolean $has_deleted 削除された商品規格も含む場合 true; 初期値 false |
---|
| 441 | * @return array 全ての組み合わせの商品規格の配列 |
---|
[18829] | 442 | */ |
---|
[23124] | 443 | public function getProductsClassFullByProductId($productId, $has_deleted = false) |
---|
[22567] | 444 | { |
---|
[21502] | 445 | $arrRet = $this->getProductsClassByProductIds(array($productId), $has_deleted); |
---|
[22507] | 446 | |
---|
[21502] | 447 | return $arrRet; |
---|
[18829] | 448 | } |
---|
| 449 | |
---|
| 450 | /** |
---|
[18862] | 451 | * 商品IDをキーにした, 商品ステータスIDの配列を取得する. |
---|
| 452 | * |
---|
| 453 | * @param array 商品ID の配列 |
---|
| 454 | * @return array 商品IDをキーにした商品ステータスIDの配列 |
---|
| 455 | */ |
---|
[23124] | 456 | public function getProductStatus($productIds) |
---|
[22567] | 457 | { |
---|
[20003] | 458 | if (empty($productIds)) { |
---|
| 459 | return array(); |
---|
| 460 | } |
---|
[20507] | 461 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20003] | 462 | $cols = 'product_id, product_status_id'; |
---|
| 463 | $from = 'dtb_product_status'; |
---|
[21564] | 464 | $where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')'; |
---|
[20003] | 465 | $productStatus = $objQuery->select($cols, $from, $where, $productIds); |
---|
[18862] | 466 | $results = array(); |
---|
| 467 | foreach ($productStatus as $status) { |
---|
| 468 | $results[$status['product_id']][] = $status['product_status_id']; |
---|
| 469 | } |
---|
[22507] | 470 | |
---|
[18862] | 471 | return $results; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /** |
---|
[18863] | 475 | * 商品ステータスを設定する. |
---|
| 476 | * |
---|
| 477 | * TODO 現在は DELETE/INSERT だが, UPDATE を検討する. |
---|
| 478 | * |
---|
[23124] | 479 | * @param integer $productId 商品ID |
---|
| 480 | * @param array $productStatusIds ON にする商品ステータスIDの配列 |
---|
[18863] | 481 | */ |
---|
[23124] | 482 | public function setProductStatus($productId, $productStatusIds) |
---|
[22567] | 483 | { |
---|
[18863] | 484 | $val['product_id'] = $productId; |
---|
| 485 | $val['creator_id'] = $_SESSION['member_id']; |
---|
[21185] | 486 | $val['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 487 | $val['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
[18863] | 488 | $val['del_flg'] = '0'; |
---|
| 489 | |
---|
[20507] | 490 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[18863] | 491 | $objQuery->delete('dtb_product_status', 'product_id = ?', array($productId)); |
---|
| 492 | foreach ($productStatusIds as $productStatusId) { |
---|
[21684] | 493 | if ($productStatusId == '') continue; |
---|
[18863] | 494 | $val['product_status_id'] = $productStatusId; |
---|
| 495 | $objQuery->insert('dtb_product_status', $val); |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
[21352] | 500 | * 商品詳細の結果から, 販売制限数を取得する. |
---|
[18852] | 501 | * |
---|
[21352] | 502 | * getDetailAndProductsClass() の結果から, 販売制限数を取得する. |
---|
[18852] | 503 | * |
---|
[23124] | 504 | * @param array $p 商品詳細の検索結果の配列 |
---|
[21352] | 505 | * @return integer 商品詳細の結果から求めた販売制限数. |
---|
[18852] | 506 | * @see getDetailAndProductsClass() |
---|
| 507 | */ |
---|
[23124] | 508 | public function getBuyLimit($p) |
---|
[22567] | 509 | { |
---|
[18852] | 510 | $limit = null; |
---|
| 511 | if ($p['stock_unlimited'] != '1' && is_numeric($p['sale_limit'])) { |
---|
| 512 | $limit = min($p['sale_limit'], $p['stock']); |
---|
| 513 | } elseif (is_numeric($p['sale_limit'])) { |
---|
| 514 | $limit = $p['sale_limit']; |
---|
| 515 | } elseif ($p['stock_unlimited'] != '1') { |
---|
| 516 | $limit = $p['stock']; |
---|
| 517 | } |
---|
[22507] | 518 | |
---|
[18852] | 519 | return $limit; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | /** |
---|
[18860] | 523 | * 在庫を減少させる. |
---|
| 524 | * |
---|
| 525 | * 指定の在庫数まで, 在庫を減少させる. |
---|
| 526 | * 減少させた結果, 在庫数が 0 未満になった場合, 引数 $quantity が 0 の場合は, |
---|
| 527 | * 在庫の減少を中止し, false を返す. |
---|
| 528 | * 在庫の減少に成功した場合は true を返す. |
---|
| 529 | * |
---|
[23124] | 530 | * @param integer $productClassId 商品規格ID |
---|
| 531 | * @param integer $quantity 減少させる在庫数 |
---|
[18860] | 532 | * @return boolean 在庫の減少に成功した場合 true; 失敗した場合 false |
---|
| 533 | */ |
---|
[23124] | 534 | public function reduceStock($productClassId, $quantity) |
---|
[22567] | 535 | { |
---|
[21005] | 536 | if ($quantity == 0) { |
---|
[18860] | 537 | return false; |
---|
| 538 | } |
---|
| 539 | |
---|
[20507] | 540 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[18860] | 541 | $objQuery->update('dtb_products_class', array(), |
---|
[21514] | 542 | 'product_class_id = ?', array($productClassId), |
---|
[18860] | 543 | array('stock' => 'stock - ?'), array($quantity)); |
---|
| 544 | // TODO エラーハンドリング |
---|
[21005] | 545 | |
---|
| 546 | $productsClass = $this->getDetailAndProductsClass($productClassId); |
---|
| 547 | if ($productsClass['stock_unlimited'] != '1' && $productsClass['stock'] < 0) { |
---|
| 548 | return false; |
---|
| 549 | } |
---|
| 550 | |
---|
[18860] | 551 | return true; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | /** |
---|
[21131] | 555 | * 商品情報の配列に, 税込金額を設定して返す. |
---|
| 556 | * |
---|
| 557 | * この関数は, 主にスマートフォンで使用します. |
---|
| 558 | * |
---|
[23124] | 559 | * @param array $arrProducts 商品情報の配列 |
---|
[22486] | 560 | * @return array 旧バージョン互換用のデータ |
---|
[21131] | 561 | */ |
---|
[23124] | 562 | public static function setPriceTaxTo(&$arrProducts) |
---|
[22567] | 563 | { |
---|
[22486] | 564 | foreach ($arrProducts as &$arrProduct) { |
---|
| 565 | $arrProduct['price01_min_format'] = number_format($arrProduct['price01_min']); |
---|
| 566 | $arrProduct['price01_max_format'] = number_format($arrProduct['price01_max']); |
---|
| 567 | $arrProduct['price02_min_format'] = number_format($arrProduct['price02_min']); |
---|
| 568 | $arrProduct['price02_max_format'] = number_format($arrProduct['price02_max']); |
---|
[21131] | 569 | |
---|
[22486] | 570 | SC_Product_Ex::setIncTaxToProduct($arrProduct); |
---|
[21131] | 571 | |
---|
[22486] | 572 | $arrProduct['price01_min_inctax_format'] = number_format($arrProduct['price01_min_inctax']); |
---|
| 573 | $arrProduct['price01_max_inctax_format'] = number_format($arrProduct['price01_max_inctax']); |
---|
| 574 | $arrProduct['price02_min_inctax_format'] = number_format($arrProduct['price02_min_inctax']); |
---|
| 575 | $arrProduct['price02_max_inctax_format'] = number_format($arrProduct['price02_max_inctax']); |
---|
| 576 | |
---|
| 577 | // @deprecated 2.12.4 |
---|
| 578 | // 旧バージョン互換用 |
---|
| 579 | // 本来は、税額の代入で使用すべきキー名。 |
---|
| 580 | $arrProduct['price01_min_tax_format'] =& $arrProduct['price01_min_inctax_format']; |
---|
| 581 | $arrProduct['price01_max_tax_format'] =& $arrProduct['price01_max_inctax_format']; |
---|
| 582 | $arrProduct['price02_min_tax_format'] =& $arrProduct['price02_min_inctax_format']; |
---|
| 583 | $arrProduct['price02_max_tax_format'] =& $arrProduct['price02_max_inctax_format']; |
---|
[21131] | 584 | } |
---|
[22486] | 585 | // @deprecated 2.12.4 |
---|
| 586 | // 旧バージョン互換用 |
---|
| 587 | // 現在は参照渡しで戻せる |
---|
[21131] | 588 | return $arrProducts; |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | /** |
---|
[21708] | 592 | * 商品情報の配列に税込金額を設定する |
---|
| 593 | * |
---|
[23124] | 594 | * @param array $arrProducts 商品情報の配列 |
---|
[21708] | 595 | * @return void |
---|
| 596 | */ |
---|
[23124] | 597 | public static function setIncTaxToProducts(&$arrProducts) |
---|
[22567] | 598 | { |
---|
[21708] | 599 | foreach ($arrProducts as &$arrProduct) { |
---|
| 600 | SC_Product_Ex::setIncTaxToProduct($arrProduct); |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | /** |
---|
| 605 | * 商品情報の配列に税込金額を設定する |
---|
| 606 | * |
---|
[23124] | 607 | * @param array $arrProducts 商品情報の配列 |
---|
[21708] | 608 | * @return void |
---|
| 609 | */ |
---|
[23124] | 610 | public static function setIncTaxToProduct(&$arrProduct) |
---|
[22567] | 611 | { |
---|
[22736] | 612 | $arrProduct['price01_min_inctax'] = isset($arrProduct['price01_min']) ? SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price01_min'], $arrProduct['product_id']) : null; |
---|
| 613 | $arrProduct['price01_max_inctax'] = isset($arrProduct['price01_max']) ? SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price01_max'], $arrProduct['product_id']) : null; |
---|
| 614 | $arrProduct['price02_min_inctax'] = isset($arrProduct['price02_min']) ? SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price02_min'], $arrProduct['product_id']) : null; |
---|
| 615 | $arrProduct['price02_max_inctax'] = isset($arrProduct['price02_max']) ? SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProduct['price02_max'], $arrProduct['product_id']) : null; |
---|
[21708] | 616 | } |
---|
| 617 | |
---|
| 618 | /** |
---|
[18815] | 619 | * 商品詳細の SQL を取得する. |
---|
| 620 | * |
---|
[23124] | 621 | * @param string $where_products_class 商品規格情報の WHERE 句 |
---|
[18815] | 622 | * @return string 商品詳細の SQL |
---|
| 623 | */ |
---|
[23124] | 624 | public function alldtlSQL($where_products_class = '') |
---|
[22567] | 625 | { |
---|
[21320] | 626 | if (!SC_Utils_Ex::isBlank($where_products_class)) { |
---|
[21328] | 627 | $where_products_class = 'AND (' . $where_products_class . ')'; |
---|
[18815] | 628 | } |
---|
[18821] | 629 | /* |
---|
[20877] | 630 | * point_rate, deliv_fee は商品規格(dtb_products_class)ごとに保持しているが, |
---|
[18821] | 631 | * 商品(dtb_products)ごとの設定なので MAX のみを取得する. |
---|
| 632 | */ |
---|
[18815] | 633 | $sql = <<< __EOS__ |
---|
| 634 | ( |
---|
[21834] | 635 | SELECT |
---|
| 636 | dtb_products.product_id |
---|
[20916] | 637 | ,dtb_products.name |
---|
| 638 | ,dtb_products.maker_id |
---|
| 639 | ,dtb_products.status |
---|
| 640 | ,dtb_products.comment1 |
---|
| 641 | ,dtb_products.comment2 |
---|
| 642 | ,dtb_products.comment3 |
---|
| 643 | ,dtb_products.comment4 |
---|
| 644 | ,dtb_products.comment5 |
---|
| 645 | ,dtb_products.comment6 |
---|
| 646 | ,dtb_products.note |
---|
| 647 | ,dtb_products.main_list_comment |
---|
| 648 | ,dtb_products.main_list_image |
---|
| 649 | ,dtb_products.main_comment |
---|
| 650 | ,dtb_products.main_image |
---|
| 651 | ,dtb_products.main_large_image |
---|
| 652 | ,dtb_products.sub_title1 |
---|
| 653 | ,dtb_products.sub_comment1 |
---|
| 654 | ,dtb_products.sub_image1 |
---|
| 655 | ,dtb_products.sub_large_image1 |
---|
| 656 | ,dtb_products.sub_title2 |
---|
| 657 | ,dtb_products.sub_comment2 |
---|
| 658 | ,dtb_products.sub_image2 |
---|
| 659 | ,dtb_products.sub_large_image2 |
---|
| 660 | ,dtb_products.sub_title3 |
---|
| 661 | ,dtb_products.sub_comment3 |
---|
| 662 | ,dtb_products.sub_image3 |
---|
| 663 | ,dtb_products.sub_large_image3 |
---|
| 664 | ,dtb_products.sub_title4 |
---|
| 665 | ,dtb_products.sub_comment4 |
---|
| 666 | ,dtb_products.sub_image4 |
---|
| 667 | ,dtb_products.sub_large_image4 |
---|
| 668 | ,dtb_products.sub_title5 |
---|
| 669 | ,dtb_products.sub_comment5 |
---|
| 670 | ,dtb_products.sub_image5 |
---|
| 671 | ,dtb_products.sub_large_image5 |
---|
| 672 | ,dtb_products.sub_title6 |
---|
| 673 | ,dtb_products.sub_comment6 |
---|
| 674 | ,dtb_products.sub_image6 |
---|
| 675 | ,dtb_products.sub_large_image6 |
---|
| 676 | ,dtb_products.del_flg |
---|
| 677 | ,dtb_products.creator_id |
---|
| 678 | ,dtb_products.create_date |
---|
| 679 | ,dtb_products.update_date |
---|
| 680 | ,dtb_products.deliv_date_id |
---|
| 681 | ,T4.product_code_min |
---|
| 682 | ,T4.product_code_max |
---|
| 683 | ,T4.price01_min |
---|
| 684 | ,T4.price01_max |
---|
| 685 | ,T4.price02_min |
---|
| 686 | ,T4.price02_max |
---|
| 687 | ,T4.stock_min |
---|
| 688 | ,T4.stock_max |
---|
| 689 | ,T4.stock_unlimited_min |
---|
| 690 | ,T4.stock_unlimited_max |
---|
| 691 | ,T4.point_rate |
---|
| 692 | ,T4.deliv_fee |
---|
| 693 | ,T4.class_count |
---|
| 694 | ,dtb_maker.name AS maker_name |
---|
| 695 | FROM dtb_products |
---|
| 696 | JOIN ( |
---|
[21527] | 697 | SELECT product_id, |
---|
| 698 | MIN(product_code) AS product_code_min, |
---|
| 699 | MAX(product_code) AS product_code_max, |
---|
| 700 | MIN(price01) AS price01_min, |
---|
| 701 | MAX(price01) AS price01_max, |
---|
| 702 | MIN(price02) AS price02_min, |
---|
| 703 | MAX(price02) AS price02_max, |
---|
| 704 | MIN(stock) AS stock_min, |
---|
| 705 | MAX(stock) AS stock_max, |
---|
| 706 | MIN(stock_unlimited) AS stock_unlimited_min, |
---|
| 707 | MAX(stock_unlimited) AS stock_unlimited_max, |
---|
| 708 | MAX(point_rate) AS point_rate, |
---|
| 709 | MAX(deliv_fee) AS deliv_fee, |
---|
| 710 | COUNT(*) as class_count |
---|
[20916] | 711 | FROM dtb_products_class |
---|
[21328] | 712 | WHERE del_flg = 0 $where_products_class |
---|
[20916] | 713 | GROUP BY product_id |
---|
| 714 | ) AS T4 |
---|
| 715 | ON dtb_products.product_id = T4.product_id |
---|
| 716 | LEFT JOIN dtb_maker |
---|
| 717 | ON dtb_products.maker_id = dtb_maker.maker_id |
---|
| 718 | ) AS alldtl |
---|
[18815] | 719 | __EOS__; |
---|
[22507] | 720 | |
---|
[18815] | 721 | return $sql; |
---|
| 722 | } |
---|
[18826] | 723 | |
---|
| 724 | /** |
---|
[19742] | 725 | * 商品規格詳細の SQL を取得する. |
---|
| 726 | * |
---|
| 727 | * MEMO: 2.4系 vw_product_classに相当(?)するイメージ |
---|
| 728 | * |
---|
[23124] | 729 | * @param string $where 商品詳細の WHERE 句 |
---|
[19742] | 730 | * @return string 商品規格詳細の SQL |
---|
| 731 | */ |
---|
[23124] | 732 | public function prdclsSQL($where = '') |
---|
[22567] | 733 | { |
---|
[21514] | 734 | $where_clause = ''; |
---|
[19742] | 735 | if (!SC_Utils_Ex::isBlank($where)) { |
---|
[21514] | 736 | $where_clause = ' WHERE ' . $where; |
---|
[19742] | 737 | } |
---|
| 738 | $sql = <<< __EOS__ |
---|
| 739 | ( |
---|
[21527] | 740 | SELECT dtb_products.*, |
---|
| 741 | dtb_products_class.product_class_id, |
---|
| 742 | dtb_products_class.product_type_id, |
---|
| 743 | dtb_products_class.product_code, |
---|
| 744 | dtb_products_class.stock, |
---|
| 745 | dtb_products_class.stock_unlimited, |
---|
| 746 | dtb_products_class.sale_limit, |
---|
| 747 | dtb_products_class.price01, |
---|
| 748 | dtb_products_class.price02, |
---|
| 749 | dtb_products_class.deliv_fee, |
---|
| 750 | dtb_products_class.point_rate, |
---|
| 751 | dtb_products_class.down_filename, |
---|
| 752 | dtb_products_class.down_realfilename, |
---|
[21640] | 753 | dtb_products_class.classcategory_id1 AS classcategory_id, /* 削除 */ |
---|
[21527] | 754 | dtb_products_class.classcategory_id1, |
---|
[21640] | 755 | dtb_products_class.classcategory_id2 AS parent_classcategory_id, /* 削除 */ |
---|
[21527] | 756 | dtb_products_class.classcategory_id2, |
---|
| 757 | Tcc1.class_id as class_id, |
---|
| 758 | Tcc1.name as classcategory_name, |
---|
| 759 | Tcc2.class_id as parent_class_id, |
---|
| 760 | Tcc2.name as parent_classcategory_name |
---|
| 761 | FROM dtb_products |
---|
| 762 | LEFT JOIN dtb_products_class |
---|
| 763 | ON dtb_products.product_id = dtb_products_class.product_id |
---|
| 764 | LEFT JOIN dtb_classcategory as Tcc1 |
---|
| 765 | ON dtb_products_class.classcategory_id1 = Tcc1.classcategory_id |
---|
| 766 | LEFT JOIN dtb_classcategory as Tcc2 |
---|
| 767 | ON dtb_products_class.classcategory_id2 = Tcc2.classcategory_id |
---|
| 768 | $where_clause |
---|
[19742] | 769 | ) as prdcls |
---|
| 770 | __EOS__; |
---|
[22507] | 771 | |
---|
[19742] | 772 | return $sql; |
---|
| 773 | } |
---|
[22833] | 774 | |
---|
[23124] | 775 | public function getProductDispConditions($tablename = null) |
---|
| 776 | { |
---|
[22833] | 777 | $tablename = ($tablename) ? $tablename . '.' : null; |
---|
[22856] | 778 | |
---|
[22833] | 779 | return $tablename . 'del_flg = 0 AND ' . $tablename . 'status = 1 '; |
---|
| 780 | } |
---|
[18277] | 781 | } |
---|