Ignore:
Timestamp:
2011/02/24 20:36:44 (13 years ago)
Author:
shutta
Message:

refs #1038
コンテンツ管理(おすすめ商品管理):商品検索ポップアップで「商品コード」が表示されなかったのを修正。
LC_Page_Admin_Order_ProductSelect.phpのコードをほぼほぼ流用。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_RecommendSearch.php

    r20380 r20391  
    7474        switch ($this->getMode()) { 
    7575        case 'search': 
    76             $objQuery = new SC_Query(); 
    7776            // POST値の引き継ぎ 
    7877            $this->arrErr = $this->lfCheckError($objFormParam); 
     
    8180            // 検索結果の数に応じてページャの処理も入れる。 
    8281            if (SC_Utils_Ex::isBlank($this->arrErr)) { 
     82                $objProduct = new SC_Product(); 
     83 
    8384                $where = 'del_flg = 0'; 
    8485                $order = "update_date DESC, product_id DESC"; 
    85                 list($where, $arrval) = $this->getSearchParam($objDb,$arrPost,$where); 
    86                 $linemax = $this->getLineCount($where, $arrval); 
     86 
     87                $wheres = $this->createWhere($objFormParam,$objDb); 
     88                $this->tpl_linemax = $this->getLineCount($wheres,$objProduct); 
     89 
    8790                $page_max = SC_Utils_Ex::sfGetSearchPageMax($arrPost['search_page_max']); 
    8891 
    8992                // ページ送りの取得 
    9093                $objNavi = new SC_PageNavi($arrPost['search_pageno'], $linemax, $page_max, "fnNaviSearchOnlyPage", NAVI_PMAX); 
    91                 $this->tpl_linemax = $linemax;               // 何件が該当しました。表示用 
    9294                $this->tpl_strnavi = $objNavi->strnavi;      // 表示文字列 
    9395                $startno = $objNavi->start_row; 
    9496 
    95                 // 取得範囲の指定(開始行番号、行数のセット) 
    96                 $objQuery->setLimitOffset($page_max, $startno); 
    97                 $objQuery->setOrder($order); 
    98                 $this->arrForm = $arrPost; 
    99                 // 検索結果の取得 
    100                 $this->arrProducts = $this->getProducts($objQuery, $arrval, $where); 
     97                $arrProduct_id = $this->getProducts($wheres, $objProduct, $page_max, $startno); 
     98                $productList = $this->getProductList($arrProduct_id,$objProduct); 
     99                //取得している並び順で並び替え 
     100                $this->arrProducts = $this->sortProducts($arrProduct_id,$productList); 
    101101            } 
    102102            break; 
     
    141141 
    142142    /** 
    143      * 検索パラメータを返す。 
    144      * @param Array $arrPost 
    145      * @return Array $arrSQL 検索条件とパラメータを配列にして返す。 
    146      */ 
    147     function getSearchParam(&$objDb,$arrPost,$where){ 
    148             $arrval = array(); 
    149             foreach ($arrPost as $key => $val) { 
    150                 if($val == "") { 
    151                     continue; 
    152                 } 
    153                 switch ($key) { 
     143     * 
     144     * POSTされた値からSQLのWHEREとBINDを配列で返す。 
     145     * @return array ('where' => where string, 'bind' => databind array) 
     146     * @param SC_FormParam $objFormParam 
     147     */ 
     148    function createWhere(&$objFormParam,&$objDb){ 
     149        $arrForm = $objFormParam->getHashArray(); 
     150        $where = "alldtl.del_flg = 0"; 
     151        $bind = array(); 
     152        foreach ($arrForm as $key => $val) { 
     153            if($val == "") { 
     154                continue; 
     155            } 
     156 
     157            switch ($key) { 
    154158                case 'search_name': 
    155159                    $where .= " AND name ILIKE ?"; 
    156                     $arrval[] = "%$val%"; 
     160                    $bind[] = "%".$val."%"; 
    157161                    break; 
    158162                case 'search_category_id': 
    159                     list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val); 
     163                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val); 
    160164                    if($tmp_where != "") { 
    161                         $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 
    162                         $arrval = array_merge((array)$arrval, (array)$tmp_arrval); 
     165                        $where.= " AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 
     166                        $bind = array_merge((array)$bind, (array)$tmp_bind); 
    163167                    } 
    164168                    break; 
    165169                case 'search_product_code': 
    166                     $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)"; 
    167                     $arrval[] = "$val%"; 
    168                     break; 
     170                    $where .=    " AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)"; 
     171                    $bind[] = '%'.$val.'%'; 
     172                    break; 
     173 
    169174                default: 
    170175                    break; 
    171                 } 
    172176            } 
    173             return array($where, $arrval); 
    174     } 
    175  
    176     /** 
    177      * 指定された条件の商品の数を取得する 
    178      * @param String $where 検索条件 
    179      * @param Array $arrval 検索パラメータ 
    180      * @return Integer $linemax 条件にマッチする商品の数 
    181      */ 
    182     function getLineCount($where,$arrval){ 
     177        } 
     178        return array( 
     179            'where'=>$where, 
     180            'bind' => $bind 
     181        ); 
     182    } 
     183 
     184    /** 
     185     * 
     186     * 検索結果対象となる商品の数を返す。 
     187     * @param array $whereAndBind 
     188     * @param SC_Product $objProduct 
     189     */ 
     190    function getLineCount($whereAndBind,&$objProduct){ 
     191        $where = $whereAndBind['where']; 
     192        $bind = $whereAndBind['bind']; 
     193        // 検索結果対象となる商品の数を取得 
    183194        $objQuery =& SC_Query::getSingletonInstance(); 
    184         $linemax = $objQuery->count("dtb_products", $where, $arrval); 
    185         return $linemax; 
    186     } 
    187  
    188     /** 
    189      * 指定された条件の商品データを取得する。 
    190      * @param Object $objQuery ObjQueryオブジェクト 
    191      * @param Array $arrval 検索パラメータ 
    192      * @param String $where 検索条件 
    193      * @return Array 商品情報の配列 
    194      */ 
    195     function getProducts(&$objQuery,$arrval,$where){ 
     195        $objQuery->setWhere($where); 
     196        $linemax = $objProduct->findProductCount($objQuery, $bind); 
     197        return  $linemax;   // 何件が該当しました。表示用 
     198    } 
     199 
     200    /** 
     201     * 検索結果の取得 
     202     * @param array $whereAndBind string whereと array bindの連想配列 
     203     * @param SC_Product $objProduct 
     204     */ 
     205    function getProducts($whereAndBind,&$objProduct, $page_max, $startno){ 
     206        $where = $whereAndBind['where']; 
     207        $bind = $whereAndBind['bind']; 
    196208        $objQuery =& SC_Query::getSingletonInstance(); 
    197         return $objQuery->select("*", SC_Product::alldtlSQL(), $where, $arrval); 
    198     } 
    199  
     209        $objQuery->setWhere($where); 
     210        // 取得範囲の指定(開始行番号、行数のセット) 
     211        $objQuery->setLimitOffset($page_max, $startno); 
     212        // 表示順序 
     213        $objQuery->setOrder($order); 
     214 
     215        // 検索結果の取得 
     216        return $objProduct->findProductIdsOrder($objQuery, $bind); 
     217    } 
     218 
     219    /** 
     220     *  
     221     * 商品取得 
     222     * @param array $arrProduct_id 
     223     * @param SC_Product $objProduct 
     224     */ 
     225    function getProductList($arrProduct_id,&$objProduct){ 
     226        $where = ""; 
     227        if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 
     228            $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 
     229        } else { 
     230            // 一致させない 
     231            $where = '0<>0'; 
     232        } 
     233        $objQuery =& SC_Query::getSingletonInstance(); 
     234        $objQuery->setWhere($where); 
     235        return $objProduct->lists($objQuery, $arrProduct_id); 
     236    } 
     237 
     238    /** 
     239     * 取得している並び順で並び替え 
     240     * @param $arrProduct_id 
     241     * @param $productList 
     242     */ 
     243    function sortProducts($arrProduct_id,$productList){ 
     244        $products  = array(); 
     245        foreach($productList as $item) { 
     246            $products[ $item['product_id'] ] = $item; 
     247        } 
     248        $arrProducts = array(); 
     249        foreach($arrProduct_id as $product_id) { 
     250            $arrProducts[] = $products[$product_id]; 
     251        } 
     252        return $arrProducts; 
     253    } 
    200254} 
    201255?> 
Note: See TracChangeset for help on using the changeset viewer.