source: branches/version-2_13-dev/data/class/SC_Product.php @ 23459

Revision 23459, 28.1 KB checked in by pineray, 10 years ago (diff)

#2515 無駄な処理を改善する for 2.13.3

カテゴリーID取得部分の処理を整理.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
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
24/**
25 * 商品を扱うサービスクラス.
26 *
27 * @author LOCKON CO.,LTD.
28 * @author Kentaro Ohkouchi
29 * @version $Id$
30 */
31class SC_Product
32{
33    /** 規格名一覧 */
34    public $arrClassName;
35    /** 規格分類名一覧 */
36    public $arrClassCatName;
37    /** このプロパティが保持する price01 及び price02 は、税金付与した金額である。 */
38    public $classCategories = array();
39    public $stock_find;
40    /** 規格1クラス名 */
41    public $className1 = '';
42    /** 規格2クラス名 */
43    public $className2 = '';
44    /** 規格1が設定されている */
45    public $classCat1_find;
46    /** 規格2が設定されている */
47    public $classCat2_find;
48    public $classCats1;
49    /** 検索用並び替え条件配列 */
50    public $arrOrderData;
51
52    /**
53     * 商品検索結果の並び順を指定する。
54     *
55     * ただし指定できるテーブルはproduct_idを持っているテーブルであることが必要.
56     *
57     * @param  string $col   並び替えの基準とするフィールド
58     * @param  string $table 並び替えの基準とするフィールドがあるテーブル
59     * @param  string $order 並び替えの順序 ASC / DESC
60     * @return void
61     */
62    public function setProductsOrder($col, $table = 'dtb_products', $order = 'ASC')
63    {
64        $this->arrOrderData = array('col' => $col, 'table' => $table, 'order' => $order);
65    }
66
67    /**
68     * SC_Queryインスタンスに設定された検索条件を元に並び替え済みの検索結果商品IDの配列を取得する。
69     *
70     * 検索条件は, SC_Query::setWhere() 関数で設定しておく必要があります.
71     *
72     * @param  SC_Query $objQuery SC_Query インスタンス
73     * @param  array    $arrVal   検索パラメーターの配列
74     * @return array    商品IDの配列
75     */
76    public function findProductIdsOrder(&$objQuery, $arrVal = array())
77    {
78        $table = 'dtb_products AS alldtl';
79
80        if (is_array($this->arrOrderData) and $objQuery->order == '') {
81            $o_col = $this->arrOrderData['col'];
82            $o_table = $this->arrOrderData['table'];
83            $o_order = $this->arrOrderData['order'];
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");
89        }
90        $arrReturn = $objQuery->getCol('alldtl.product_id', $table, '', $arrVal);
91
92        return $arrReturn;
93    }
94
95    /**
96     * SC_Queryインスタンスに設定された検索条件をもとに対象商品数を取得する.
97     *
98     * 検索条件は, SC_Query::setWhere() 関数で設定しておく必要があります.
99     *
100     * @param  SC_Query $objQuery SC_Query インスタンス
101     * @param  array    $arrVal   検索パラメーターの配列
102     * @return array    対象商品ID数
103     */
104    public function findProductCount(&$objQuery, $arrVal = array())
105    {
106        $table = 'dtb_products AS alldtl';
107
108        return $objQuery->count($table, '', $arrVal);
109    }
110
111    /**
112     * SC_Queryインスタンスに設定された検索条件をもとに商品一覧の配列を取得する.
113     *
114     * 主に SC_Product::findProductIds() で取得した商品IDを検索条件にし,
115     * SC_Query::setOrder() や SC_Query::setLimitOffset() を設定して, 商品一覧
116     * の配列を取得する.
117     *
118     * @param  SC_Query $objQuery SC_Query インスタンス
119     * @return array    商品一覧の配列
120     */
121    public function lists(&$objQuery)
122    {
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__;
147        $res = $objQuery->select($col, $this->alldtlSQL());
148
149        return $res;
150    }
151
152    /**
153     * 商品IDを指定し、商品一覧を取得する
154     *
155     * SC_Query::setOrder() や SC_Query::setLimitOffset() を設定して, 商品一覧
156     * の配列を取得する.
157     * FIXME: 呼び出し元で設定した、SC_Query::setWhere() も有効に扱いたい。
158     *
159     * @param  SC_Query $objQuery     SC_Query インスタンス
160     * @param  array    $arrProductId 商品ID
161     * @return array    商品一覧の配列 (キー: 商品ID)
162     */
163    public function getListByProductIds(&$objQuery, $arrProductId = array())
164    {
165        if (empty($arrProductId)) {
166            return array();
167        }
168
169        $where = 'alldtl.product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($arrProductId)) . ')';
170        $where .= ' AND alldtl.del_flg = 0';
171
172        $objQuery->setWhere($where, $arrProductId);
173        $arrProducts = $this->lists($objQuery);
174
175        // 配列のキーを商品IDに
176        $arrProducts = SC_Utils_Ex::makeArrayIDToKey('product_id', $arrProducts);
177
178        // SC_Query::setOrder() の指定がない場合、$arrProductId で指定された商品IDの順に配列要素を並び替え
179        if (strlen($objQuery->order) === 0) {
180            $arrTmp = array();
181            foreach ($arrProductId as $product_id) {
182                $arrTmp[$product_id] = $arrProducts[$product_id];
183            }
184            $arrProducts =& $arrTmp;
185            unset($arrTmp);
186        }
187
188        // 税込金額を設定する
189        SC_Product_Ex::setIncTaxToProducts($arrProducts);
190
191        return $arrProducts;
192    }
193
194    /**
195     * 商品詳細を取得する.
196     *
197     * @param  integer $product_id 商品ID
198     * @return array   商品詳細情報の配列
199     */
200    public function getDetail($product_id)
201    {
202        $objQuery =& SC_Query_Ex::getSingletonInstance();
203
204        $from = $this->alldtlSQL();
205        $where = 'product_id = ?';
206        $arrWhereVal = array($product_id);
207        $arrProduct = (array)$objQuery->getRow('*', $from, $where, $arrWhereVal);
208
209        // 税込金額を設定する
210        SC_Product_Ex::setIncTaxToProduct($arrProduct);
211
212        return $arrProduct;
213    }
214
215    /**
216     * 商品詳細情報と商品規格を取得する.
217     *
218     * @param  integer $productClassId 商品規格ID
219     * @return array   商品詳細情報と商品規格の配列
220     */
221    public function getDetailAndProductsClass($productClassId)
222    {
223        $result = $this->getProductsClass($productClassId);
224        $result = array_merge($result, $this->getDetail($result['product_id']));
225
226        return $result;
227    }
228
229    /**
230     * 商品IDに紐づく商品規格を自分自身に設定する.
231     *
232     * 引数の商品IDの配列に紐づく商品規格を取得し, 自分自身のフィールドに
233     * 設定する.
234     *
235     * @param  array   $arrProductId 商品ID の配列
236     * @param  boolean $has_deleted  削除された商品規格も含む場合 true; 初期値 false
237     * @return void
238     */
239    public function setProductsClassByProductIds($arrProductId, $has_deleted = false)
240    {
241        foreach ($arrProductId as $productId) {
242            $arrProductClasses = $this->getProductsClassFullByProductId($productId, $has_deleted);
243
244            $classCats1 = array();
245            $classCats1['__unselected'] = '選択してください';
246
247            // 規格1クラス名
248            $this->className1[$productId] =
249                isset($arrProductClasses[0]['class_name1'])
250                ? $arrProductClasses[0]['class_name1']
251                : '';
252
253            // 規格2クラス名
254            $this->className2[$productId] =
255                isset($arrProductClasses[0]['class_name2'])
256                ? $arrProductClasses[0]['class_name2']
257                : '';
258
259            // 規格1が設定されている
260            $this->classCat1_find[$productId] = $arrProductClasses[0]['classcategory_id1'] > 0; // 要変更ただし、他にも改修が必要となる
261            // 規格2が設定されている
262            $this->classCat2_find[$productId] = $arrProductClasses[0]['classcategory_id2'] > 0; // 要変更ただし、他にも改修が必要となる
263
264            $this->stock_find[$productId] = false;
265            $classCategories = array();
266            $classCategories['__unselected']['__unselected']['name'] = '選択してください';
267            $classCategories['__unselected']['__unselected']['product_class_id'] = $arrProductClasses[0]['product_class_id'];
268            // 商品種別
269            $classCategories['__unselected']['__unselected']['product_type'] = $arrProductClasses[0]['product_type_id'];
270            $this->product_class_id[$productId] = $arrProductClasses[0]['product_class_id'];
271            // 商品種別
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'];
277                // 在庫
278                $stock_find_class = ($arrProductsClass['stock_unlimited'] || $arrProductsClass['stock'] > 0);
279
280                $arrClassCats2['classcategory_id2'] = $classcategory_id2;
281                $arrClassCats2['name'] = $arrProductsClass['classcategory_name2'] . ($stock_find_class ? '' : ' (品切れ中)');
282
283                $arrClassCats2['stock_find'] = $stock_find_class;
284
285                if ($stock_find_class) {
286                    $this->stock_find[$productId] = true;
287                }
288
289                if (!in_array($classcat_id1, $classCats1)) {
290                    $classCats1[$classcategory_id1] = $arrProductsClass['classcategory_name1']
291                        . ($classcategory_id2 == 0 && !$stock_find_class ? ' (品切れ中)' : '');
292                }
293
294                // 価格
295                // TODO: ここでprice01,price02を税込みにしてよいのか? _inctax を付けるべき?要検証
296                $arrClassCats2['price01']
297                    = strlen($arrProductsClass['price01'])
298                    ? number_format(SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProductsClass['price01'], $productId, $arrProductsClass['product_class_id']))
299                    : '';
300
301                $arrClassCats2['price02']
302                    = strlen($arrProductsClass['price02'])
303                    ? number_format(SC_Helper_TaxRule_Ex::sfCalcIncTax($arrProductsClass['price02'], $productId, $arrProductsClass['product_class_id']))
304                    : '';
305
306                // ポイント
307                $arrClassCats2['point']
308                    = number_format(SC_Utils_Ex::sfPrePoint($arrProductsClass['price02'], $arrProductsClass['point_rate']));
309
310                // 商品コード
311                $arrClassCats2['product_code'] = $arrProductsClass['product_code'];
312                // 商品規格ID
313                $arrClassCats2['product_class_id'] = $arrProductsClass['product_class_id'];
314                // 商品種別
315                $arrClassCats2['product_type'] = $arrProductsClass['product_type_id'];
316
317                // #929(GC8 規格のプルダウン順序表示不具合)対応のため、2次キーは「#」を前置
318                if (!$this->classCat1_find[$productId]) {
319                    $classcategory_id1 = '__unselected2';
320                }
321                $classCategories[$classcategory_id1]['#'] = array(
322                    'classcategory_id2' => '',
323                    'name' => '選択してください',
324                );
325                $classCategories[$classcategory_id1]['#' . $classcategory_id2] = $arrClassCats2;
326            }
327
328            $this->classCategories[$productId] = $classCategories;
329
330            // 規格1
331            $this->classCats1[$productId] = $classCats1;
332        }
333    }
334
335    /**
336     * SC_Query インスタンスに設定された検索条件を使用して商品規格を取得する.
337     *
338     * @param  SC_Query $objQuery SC_Queryインスタンス
339     * @param  array    $params   検索パラメーターの配列
340     * @return array    商品規格の配列
341     */
342    public function getProductsClassByQuery(&$objQuery, $params)
343    {
344        // 末端の規格を取得
345        $col = <<< __EOS__
346            T1.product_id,
347            T1.stock,
348            T1.stock_unlimited,
349            T1.sale_limit,
350            T1.price01,
351            T1.price02,
352            T1.point_rate,
353            T1.product_code,
354            T1.product_class_id,
355            T1.del_flg,
356            T1.product_type_id,
357            T1.down_filename,
358            T1.down_realfilename,
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
369__EOS__;
370        $table = <<< __EOS__
371            dtb_products_class T1
372            LEFT JOIN dtb_classcategory T3
373                ON T1.classcategory_id1 = T3.classcategory_id
374            LEFT JOIN dtb_class T4
375                ON T3.class_id = T4.class_id
376            LEFT JOIN dtb_classcategory dtb_classcategory2
377                ON T1.classcategory_id2 = dtb_classcategory2.classcategory_id
378            LEFT JOIN dtb_class dtb_class2
379                ON dtb_classcategory2.class_id = dtb_class2.class_id
380__EOS__;
381
382        $objQuery->setOrder('T3.rank DESC, dtb_classcategory2.rank DESC'); // XXX
383        $arrRet = $objQuery->select($col, $table, '', $params);
384
385        return $arrRet;
386    }
387
388    /**
389     * 商品規格IDから商品規格を取得する.
390     *
391     * 削除された商品規格は取得しない.
392     *
393     * @param  integer $productClassId 商品規格ID
394     * @return array   商品規格の配列
395     */
396    public function getProductsClass($productClassId)
397    {
398        $objQuery =& SC_Query_Ex::getSingletonInstance();
399        $objQuery->setWhere('product_class_id = ? AND T1.del_flg = 0');
400        $arrRes = $this->getProductsClassByQuery($objQuery, $productClassId);
401
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;
413    }
414
415    /**
416     * 複数の商品IDに紐づいた, 商品規格を取得する.
417     *
418     * @param  array   $productIds  商品IDの配列
419     * @param  boolean $has_deleted 削除された商品規格も含む場合 true; 初期値 false
420     * @return array   商品規格の配列
421     */
422    public function getProductsClassByProductIds($productIds = array(), $has_deleted = false)
423    {
424        if (empty($productIds)) {
425            return array();
426        }
427        $objQuery =& SC_Query_Ex::getSingletonInstance();
428        $where = 'product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
429        if (!$has_deleted) {
430            $where .= ' AND T1.del_flg = 0';
431        }
432        $objQuery->setWhere($where);
433
434        return $this->getProductsClassByQuery($objQuery, $productIds);
435    }
436
437    /**
438     * 商品IDに紐づいた, 商品規格を全ての組み合わせごとに取得する.
439     *
440     * @param  array   $productId   商品ID
441     * @param  boolean $has_deleted 削除された商品規格も含む場合 true; 初期値 false
442     * @return array   全ての組み合わせの商品規格の配列
443     */
444    public function getProductsClassFullByProductId($productId, $has_deleted = false)
445    {
446        $arrRet = $this->getProductsClassByProductIds(array($productId), $has_deleted);
447
448        return $arrRet;
449    }
450
451    /**
452     * 商品IDをキーにした, 商品ステータスIDの配列を取得する.
453     *
454     * @param array 商品ID の配列
455     * @return array 商品IDをキーにした商品ステータスIDの配列
456     */
457    public function getProductStatus($productIds)
458    {
459        if (empty($productIds)) {
460            return array();
461        }
462        $objQuery =& SC_Query_Ex::getSingletonInstance();
463        $cols = 'product_id, product_status_id';
464        $from = 'dtb_product_status';
465        $where = 'del_flg = 0 AND product_id IN (' . SC_Utils_Ex::repeatStrWithSeparator('?', count($productIds)) . ')';
466        $productStatus = $objQuery->select($cols, $from, $where, $productIds);
467        $results = array();
468        foreach ($productStatus as $status) {
469            $results[$status['product_id']][] = $status['product_status_id'];
470        }
471
472        return $results;
473    }
474
475    /**
476     * 商品ステータスを設定する.
477     *
478     * TODO 現在は DELETE/INSERT だが, UPDATE を検討する.
479     *
480     * @param integer $productId        商品ID
481     * @param array   $productStatusIds ON にする商品ステータスIDの配列
482     */
483    public function setProductStatus($productId, $productStatusIds)
484    {
485        $val['product_id'] = $productId;
486        $val['creator_id'] = $_SESSION['member_id'];
487        $val['create_date'] = 'CURRENT_TIMESTAMP';
488        $val['update_date'] = 'CURRENT_TIMESTAMP';
489        $val['del_flg'] = '0';
490
491        $objQuery =& SC_Query_Ex::getSingletonInstance();
492        $objQuery->delete('dtb_product_status', 'product_id = ?', array($productId));
493        foreach ($productStatusIds as $productStatusId) {
494            if ($productStatusId == '') continue;
495            $val['product_status_id'] = $productStatusId;
496            $objQuery->insert('dtb_product_status', $val);
497        }
498    }
499
500    /**
501     * 商品詳細の結果から, 販売制限数を取得する.
502     *
503     * getDetailAndProductsClass() の結果から, 販売制限数を取得する.
504     *
505     * @param  array   $p 商品詳細の検索結果の配列
506     * @return integer 商品詳細の結果から求めた販売制限数.
507     * @see getDetailAndProductsClass()
508     */
509    public function getBuyLimit($p)
510    {
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        }
519
520        return $limit;
521    }
522
523    /**
524     * 在庫を減少させる.
525     *
526     * 指定の在庫数まで, 在庫を減少させる.
527     * 減少させた結果, 在庫数が 0 未満になった場合, 引数 $quantity が 0 の場合は,
528     * 在庫の減少を中止し, false を返す.
529     * 在庫の減少に成功した場合は true を返す.
530     *
531     * @param  integer $productClassId 商品規格ID
532     * @param  integer $quantity       減少させる在庫数
533     * @return boolean 在庫の減少に成功した場合 true; 失敗した場合 false
534     */
535    public function reduceStock($productClassId, $quantity)
536    {
537        if ($quantity == 0) {
538            return false;
539        }
540
541        $objQuery =& SC_Query_Ex::getSingletonInstance();
542        $objQuery->update('dtb_products_class', array(),
543                          'product_class_id = ?', array($productClassId),
544                          array('stock' => 'stock - ?'), array($quantity));
545        // TODO エラーハンドリング
546
547        $productsClass = $this->getDetailAndProductsClass($productClassId);
548        if ($productsClass['stock_unlimited'] != '1' && $productsClass['stock'] < 0) {
549            return false;
550        }
551
552        return true;
553    }
554
555    /**
556     * 商品情報の配列に, 税込金額を設定して返す.
557     *
558     * この関数は, 主にスマートフォンで使用します.
559     *
560     * @param  array $arrProducts 商品情報の配列
561     * @return array 旧バージョン互換用のデータ
562     */
563    public static function setPriceTaxTo(&$arrProducts)
564    {
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']);
570
571            SC_Product_Ex::setIncTaxToProduct($arrProduct);
572
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'];
585        }
586        // @deprecated 2.12.4
587        // 旧バージョン互換用
588        // 現在は参照渡しで戻せる
589        return $arrProducts;
590    }
591
592    /**
593     * 商品情報の配列に税込金額を設定する
594     *
595     * @param  array $arrProducts 商品情報の配列
596     * @return void
597     */
598    public static function setIncTaxToProducts(&$arrProducts)
599    {
600        foreach ($arrProducts as &$arrProduct) {
601            SC_Product_Ex::setIncTaxToProduct($arrProduct);
602        }
603    }
604
605    /**
606     * 商品情報の配列に税込金額を設定する
607     *
608     * @param  array $arrProducts 商品情報の配列
609     * @return void
610     */
611    public static function setIncTaxToProduct(&$arrProduct)
612    {
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;
617    }
618
619    /**
620     * 商品詳細の SQL を取得する.
621     *
622     * @param  string $where_products_class 商品規格情報の WHERE 句
623     * @return string 商品詳細の SQL
624     */
625    public function alldtlSQL($where_products_class = '')
626    {
627        $objDBFactory = SC_DB_DBFactory_Ex::getInstance();
628
629        return $objDBFactory->alldtlSQL($where_products_class);
630    }
631
632    /**
633     * 商品規格詳細の SQL を取得する.
634     *
635     * MEMO: 2.4系 vw_product_classに相当(?)するイメージ
636     *
637     * @param  string $where 商品詳細の WHERE 句
638     * @return string 商品規格詳細の SQL
639     */
640    public function prdclsSQL($where = '')
641    {
642        $where_clause = '';
643        if (!SC_Utils_Ex::isBlank($where)) {
644            $where_clause = ' WHERE ' . $where;
645        }
646        $sql = <<< __EOS__
647        (
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,
661                dtb_products_class.classcategory_id1 AS classcategory_id, /* 削除 */
662                dtb_products_class.classcategory_id1,
663                dtb_products_class.classcategory_id2 AS parent_classcategory_id, /* 削除 */
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
677        ) as prdcls
678__EOS__;
679
680        return $sql;
681    }
682
683    public function getProductDispConditions($tablename = null)
684    {
685        $tablename = ($tablename) ? $tablename . '.' : null;
686
687        return $tablename . 'del_flg = 0 AND ' . $tablename . 'status = 1 ';
688    }
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) {
698        if ($this->isValidProductId($product_id, $include_hidden)) {
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    }
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) {
720            $where .= ' status = 1';
721        }
722        if (!$include_deleted) {
723            $where .= ' del_flg = 0';
724        }
725        if (
726            SC_Utils_Ex::sfIsInt($product_id)
727            && !SC_Utils_Ex::sfIsZeroFilling($product_id)
728            && SC_Helper_DB_Ex::sfIsRecord('dtb_products','product_id', array($product_id), $where)
729        ) {
730            return true;
731        }
732        return false;
733    }
734}
Note: See TracBrowser for help on using the repository browser.