source: branches/version-2_12-multilang/data/class/api/operations/ItemSearch.php @ 22032

Revision 22032, 11.4 KB checked in by pineray, 12 years ago (diff)

#1890 コード中のメッセージを集約

class/api 以下のファイル内の文字列を差し替え.

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 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 * APIの基本クラス
26 *
27 * @package Api
28 * @author LOCKON CO.,LTD.
29 * @version $Id$
30 */
31require_once CLASS_EX_REALDIR . 'api_extends/SC_Api_Abstract_Ex.php';
32
33class API_ItemSearch extends SC_Api_Abstract_Ex {
34
35    protected $operation_name = 'ItemSearch';
36    protected $operation_description = '';
37    protected $default_auth_types = self::API_AUTH_TYPE_OPEN;
38    protected $default_enable = '1';
39    protected $default_is_log = '0';
40    protected $default_sub_data = '';
41
42    public function __construct() {
43        parent::__construct();
44        $this->operation_description = SC_I18n_Ex::t('API_ITEMSEARCH_DESC');
45    }
46
47    public function doAction($arrParam) {
48        $arrRequest = $this->doInitParam($arrParam);
49        if (!$this->isParamError()) {
50
51            $masterData                 = new SC_DB_MasterData_Ex();
52            $arrSTATUS            = $masterData->getMasterData('mtb_status');
53            $arrSTATUS_IMAGE      = $masterData->getMasterData('mtb_status_image');
54
55            $objProduct = new SC_Product_Ex();
56            $arrSearchData = array(
57                'category_id' => $arrRequest['BrowseNode'],
58                'maker_name' => $arrRequest['Manufacturer'],
59                'name' => $arrRequest['Keywords'],
60                'orderby' => $arrRequest['Sort'],
61            );
62
63            $arrSearchCondition = $this->getSearchCondition($arrSearchData);
64            $disp_number = 10;
65
66            $objQuery =& SC_Query_Ex::getSingletonInstance();
67            $objQuery->setWhere($arrSearchCondition['where_for_count']);
68            $objProduct = new SC_Product_Ex();
69            $linemax = $objProduct->findProductCount($objQuery, $arrSearchCondition['arrval']);
70            $objNavi = new SC_PageNavi_Ex($arrRequest['ItemPage'], $tpl_linemax, $disp_number);
71            $arrProducts = $this->getProductsList($arrSearchCondition, $disp_number, $objNavi->start_row, $linemax, $objProduct);
72
73            if (!SC_Utils_Ex::isBlank($arrProducts)) {
74                $arrProducts = $this->setStatusDataTo($arrProducts, $arrSTATUS, $arrSTATUS_IMAGE);
75                $arrProducts = $objProduct->setPriceTaxTo($arrProducts);
76                foreach ($arrProducts as $key=>$val) {
77                    $arrProducts[$key]['main_list_image'] = SC_Utils_Ex::sfNoImageMainList($val['main_list_image']);
78                }
79
80                $arrData = array();
81                foreach ($arrProducts as $key => $val) {
82                    $arrData[] = array(
83                        'product_id' => $val['product_id'],
84                        'DetailPageURL' => HTTP_URL . 'products/detail.php?product_id=' . $val['product_id'],
85                        'ItemAttributes' => $val
86                        );
87                }
88                $this->setResponse('Item', $arrData);
89
90                return true;
91            } else {
92                $this->addError('ItemSearch.Error', SC_I18n_Ex::t('API_ITEMSEARCH_ERROR'));
93            }
94        }
95
96        return false;
97    }
98
99    protected function lfInitParam(&$objFormParam) {
100        $objFormParam->addParam(SC_I18n_Ex::t('PARAM_LABEL_BROWSENODE'), 'BrowseNode', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
101        $objFormParam->addParam(SC_I18n_Ex::t('PARAM_LABEL_KEYWORDS'), 'Keywords', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
102        $objFormParam->addParam(SC_I18n_Ex::t('PARAM_LABEL_MANUFACTURER'), 'Manufacturer', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
103        $objFormParam->addParam(SC_I18n_Ex::t('PARAM_LABEL_ITEMPAGE'), 'ItemPage', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
104        $objFormParam->addParam(SC_I18n_Ex::t('PARAM_LABEL_SORT'), 'Sort', STEXT_LEN, 'a', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
105    }
106
107    public function getResponseGroupName() {
108        return 'Items';
109    }
110
111
112    /**
113     * 商品一覧の取得
114     *
115     * @return array
116     * TODO: LC_Page_Products_List::lfGetProductsList() と共通化
117     */
118    protected function getProductsList($searchCondition, $disp_number, $startno, $linemax, &$objProduct) {
119
120        $arrOrderVal = array();
121
122        $objQuery =& SC_Query_Ex::getSingletonInstance();
123        // 表示順序
124        switch ($searchCondition['orderby']) {
125            // 販売価格が安い順
126            case 'price':
127                $objProduct->setProductsOrder('price02', 'dtb_products_class', 'ASC');
128                break;
129            // 販売価格が高い順
130            case '-price':
131                $objProduct->setProductsOrder('price02', 'dtb_products_class', 'DESC');
132                break;
133
134            // 新着順
135            case 'releasedate':
136            case 'date':
137                $objProduct->setProductsOrder('create_date', 'dtb_products', 'DESC');
138                break;
139
140            // 新着順
141            case 'releasedate':
142            case 'date':
143                $objProduct->setProductsOrder('create_date', 'dtb_products', 'ASC');
144                break;
145
146            default:
147                if (strlen($searchCondition['where_category']) >= 1) {
148                    $dtb_product_categories = '(SELECT * FROM dtb_product_categories WHERE '.$searchCondition['where_category'].')';
149                    $arrOrderVal           = $searchCondition['arrvalCategory'];
150                } else {
151                    $dtb_product_categories = 'dtb_product_categories';
152                }
153                $order = <<< __EOS__
154                    (
155                        SELECT
156                            T3.rank * 2147483648 + T2.rank
157                        FROM
158                            $dtb_product_categories T2
159                            JOIN dtb_category T3
160                              ON T2.category_id = T3.category_id
161                        WHERE T2.product_id = alldtl.product_id
162                        ORDER BY T3.rank DESC, T2.rank DESC
163                        LIMIT 1
164                    ) DESC
165                    ,product_id DESC
166__EOS__;
167                    $objQuery->setOrder($order);
168                break;
169        }
170        // 取得範囲の指定(開始行番号、行数のセット)
171        $objQuery->setLimitOffset($disp_number, $startno);
172        $objQuery->setWhere($searchCondition['where']);
173
174        // 表示すべきIDとそのIDの並び順を一気に取得
175        $arrProductId = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition['arrval'], $arrOrderVal));
176
177        $objQuery =& SC_Query_Ex::getSingletonInstance();
178        $arrProducts = $objProduct->getListByProductIds($objQuery, $arrProductId);
179        // 規格を設定
180        $objProduct->setProductsClassByProductIds($arrProductId);
181        $arrProducts['productStatus'] = $objProduct->getProductStatus($arrProductId);
182        return $arrProducts;
183
184    }
185
186    /**
187     * 検索条件のwhere文とかを取得
188     *
189     * @return array
190     * TODO: LC_Page_Products_List:;lfGetSearchCondition() と共通化
191     */
192    protected function getSearchCondition($arrSearchData) {
193        $searchCondition = array(
194            'where'             => '',
195            'arrval'            => array(),
196            'where_category'    => '',
197            'arrvalCategory'    => array(),
198            'orderby'           => ''
199        );
200
201        // カテゴリからのWHERE文字列取得
202        if (!SC_Utils_Ex::isBlank($arrSearchData['category_id'])) {
203            list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);
204        }
205        // ▼対象商品IDの抽出
206        // 商品検索条件の作成(未削除、表示)
207        $searchCondition['where'] = 'alldtl.del_flg = 0 AND alldtl.status = 1 ';
208
209        if (strlen($searchCondition['where_category']) >= 1) {
210            $searchCondition['where'] .= ' AND EXISTS (SELECT * FROM dtb_product_categories WHERE ' . $searchCondition['where_category'] . ' AND product_id = alldtl.product_id)';
211            $searchCondition['arrval'] = array_merge($searchCondition['arrval'], $searchCondition['arrvalCategory']);
212        }
213
214        // 商品名をwhere文に
215        $name = $arrSearchData['name'];
216        $name = str_replace(',', '', $name);
217        // 全角スペースを半角スペースに変換
218        $name = str_replace(' ', ' ', $name);
219        // スペースでキーワードを分割
220        $names = preg_split('/ +/', $name);
221        // 分割したキーワードを一つずつwhere文に追加
222        foreach ($names as $val) {
223            if (strlen($val) > 0) {
224                $searchCondition['where']    .= ' AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) ';
225                $searchCondition['arrval'][]  = "%$val%";
226                $searchCondition['arrval'][]  = "%$val%";
227            }
228        }
229
230        // メーカーらのWHERE文字列取得
231        if ($arrSearchData['maker_id']) {
232            $searchCondition['where']   .= ' AND alldtl.maker_id = ? ';
233            $searchCondition['arrval'][] = $arrSearchData['maker_id'];
234        }
235
236        $searchCondition['where_for_count'] = $searchCondition['where'];
237
238        // 在庫無し商品の非表示
239        if (NOSTOCK_HIDDEN) {
240            $searchCondition['where'] .= ' AND (stock >= 1 OR stock_unlimited = 1)';
241            $searchCondition['where_for_count'] .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = alldtl.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))';
242        }
243
244        // ソート順
245        if (!SC_Utils_Ex::isBlank($arrSearchData['orderby'])) {
246            $searchCondition['orderby'] = $arrSearchData['orderby'];
247        }
248
249        return $searchCondition;
250    }
251
252
253    /**
254     * 商品情報配列に商品ステータス情報を追加する
255     *
256     * @param Array $arrProducts 商品一覧情報
257     * @param Array $arrStatus 商品ステータス配列
258     * @param Array $arrStatusImage スタータス画像配列
259     * @return Array $arrProducts 商品一覧情報
260     */
261    protected function setStatusDataTo($arrProducts, $arrStatus, $arrStatusImage) {
262
263        foreach ($arrProducts['productStatus'] as $product_id => $arrValues) {
264            for ($i = 0; $i < count($arrValues); $i++) {
265                $product_status_id = $arrValues[$i];
266                if (!empty($product_status_id)) {
267                    $arrProductStatus = array(
268                        'status_cd' => $product_status_id,
269                        'status_name' => $arrStatus[$product_status_id],
270                        'status_image' =>$arrStatusImage[$product_status_id],
271                    );
272                    $arrProducts['productStatus'][$product_id][$i] = $arrProductStatus;
273                }
274            }
275        }
276        return $arrProducts;
277    }
278
279}
Note: See TracBrowser for help on using the repository browser.