Changeset 20222


Ignore:
Timestamp:
2011/02/20 02:39:51 (13 years ago)
Author:
tao
Message:

refs #982 リファクタリング 商品一覧

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/pages/products/LC_Page_Products_List.php

    r20199 r20222  
    9696    function action() { 
    9797        $objQuery =& SC_Query::getSingletonInstance(); 
    98         $objDb = new SC_Helper_DB_Ex();//$this->helperDBにしたい 
    9998        $objProduct = new SC_Product(); 
    10099 
    101         $this->arrForm = $_GET; 
     100        $this->arrForm = $_REQUEST; 
    102101        //modeの取得 
    103102        $this->mode = $this->getMode(); 
     
    105104        //表示条件の取得 
    106105        $this->arrSearchData = array( 
    107             'category_id' => $this->lfGetCategoryId($this->arrForm['category_id']), 
    108             'maker_id'=>$this->arrForm['maker_id'], 
     106            'category_id' => $this->lfGetCategoryId(intval($this->arrForm['category_id'])), 
     107            'maker_id'=>intval($this->arrForm['maker_id']), 
    109108            'name'=>$this->arrForm['name'] 
    110109        ); 
     
    114113        $this->tpl_pageno = $this->arrForm['pageno']; 
    115114        $this->disp_number = $this->lfGetDisplayNum($this->arrForm['disp_number']); 
    116         $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
    117         $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam); 
    118115 
    119116        // 画面に表示するサブタイトルの設定 
     
    122119        // 画面に表示する検索条件を設定 
    123120        $this->arrSearch = $this->lfGetSearchConditionDisp($this->arrSearchData); 
    124         //この辺まではinit()に書いちゃダメなのかな? 
    125121 
    126122        // 商品一覧データの取得 
    127         $searchCondition = $this->lfGetSearchCondition($arrSearchData); 
    128         $this->tpl_linemax = $this->lfGetProductAllNum($searchCondition); 
    129         $this->arrProducts = $this->lfGetProductsList($searchCondition,$this->disp_number,$this->objNavi->start_row,$this->tpl_linemax,&$objProduct); 
    130          
     123        $arrSearchCondition = $this->lfGetSearchCondition($this->arrSearchData); 
     124        $this->tpl_linemax = $this->lfGetProductAllNum($arrSearchCondition); 
     125        $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
     126        $this->objNavi = new SC_PageNavi($this->tpl_pageno, $this->tpl_linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam,SC_Display::detectDevice() !== DEVICE_TYPE_MOBILE); 
     127        $this->arrProducts = $this->lfGetProductsList($arrSearchCondition,$this->disp_number,$this->objNavi->start_row,$this->tpl_linemax,&$objProduct); 
    131128        //商品一覧の表示処理 
    132129        $strnavi = $this->objNavi->strnavi; 
     
    156153        unset($this->arrProducts["productStatus"]); 
    157154 
    158         $productsClassCategories = $objProduct->classCategories; 
    159  
    160155        $objJson = new Services_JSON(); 
    161         $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($productsClassCategories) . '; '; 
    162          
     156        $this->tpl_javascript .= 'var productsClassCategories = ' . $objJson->encode($objProduct->classCategories) . ';\n'; 
    163157 
    164158        //onloadスクリプトを設定 
    165159        foreach ($this->arrProducts as $arrProduct) { 
    166160            $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n"; 
    167         }     
     161        } 
    168162 
    169163        //カート処理 
    170         if (intval($this->arrForm['product_id']) > 0) { 
     164        $target_product_id = intval($this->arrForm['product_id']); 
     165        if ( $target_product_id > 0) { 
    171166            // 商品IDの正当性チェック 
    172167            if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id']) || !SC_Helper_DB_Ex::sfIsRecord("dtb_products", "product_id", $this->arrForm['product_id'], "del_flg = 0 AND status = 1")) { 
    173168                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
    174169            } 
    175             $product_id = $this->arrForm['product_id']; 
     170 
    176171            // 入力内容のチェック 
    177             $arrErr = $this->lfCheckError($product_id); 
     172            $arrErr = $this->lfCheckError($target_product_id,&$this->arrForm,$this->tpl_classcat_find1,$this->tpl_classcat_find2); 
    178173            if (count($arrErr) == 0) { 
    179                 $classcategory_id1 = $this->arrForm['classcategory_id1']; 
    180                 $classcategory_id2 = $this->arrForm['classcategory_id2']; 
    181                 // 規格1が設定されていない場合 
    182                 if (!$this->tpl_classcat_find1[$product_id]) { 
    183                     $classcategory_id1 = '0'; 
    184                 } 
    185                 // 規格2が設定されていない場合 
    186                 if (!$this->tpl_classcat_find2[$product_id]) { 
    187                     $classcategory_id2 = '0'; 
    188                 } 
    189                 // 規格IDを取得 
    190                 $objProduct = new SC_Product(); 
    191                 $product_class_id = $this->arrForm['product_class_id']; 
    192                 $product_type = $this->arrForm['product_type']; 
    193                 $objCartSess = new SC_CartSession(); 
    194                 $objCartSess->addProduct($product_class_id, $this->arrForm['quantity'], $product_type); 
    195  
    196                 // カート「戻るボタン」用に保持 
    197                 if (SC_Utils_Ex::sfIsInternalDomain($_SERVER['HTTP_REFERER'])) { 
    198                     $_SESSION['cart_referer_url'] = $_SERVER['HTTP_REFERER']; 
    199                 } 
    200  
    201                 SC_Response_Ex::sendRedirect(CART_URLPATH); 
     174                $this->lfAddCart($this->arrForm,$this->tpl_classcat_find1,$this->tpl_classcat_find2,$target_product_id); 
    202175                exit; 
    203176            } 
    204             foreach (array_keys($this->arrProducts) as $key) { 
    205                 $arrProduct =& $this->arrProducts[$key]; 
    206                 if ($arrProduct['product_id'] == $product_id) { 
    207                     $arrProduct['product_class_id'] = $this->arrForm['product_class_id']; 
    208                     $arrProduct['classcategory_id1'] = $this->arrForm['classcategory_id1']; 
    209                     $arrProduct['classcategory_id2'] = $this->arrForm['classcategory_id2']; 
    210                     $arrProduct['quantity'] = $this->arrForm['quantity']; 
    211                     $arrProduct['arrErr'] = $arrErr; 
    212                     $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']}, '{$this->arrForm['classcategory_id2']}');\n"; 
    213                 } 
    214             } 
     177            $js_fnOnLoad .= $this->lfSetSelectedData(&$this->arrProducts,$this->arrForm,$arrErr,$target_product_id); 
    215178        } 
    216179 
    217180        // ページャ用データ設定(モバイル) 
    218181        if (Net_UserAgent_Mobile::isMobile() === true) { 
    219             $this->lfSetPagerMobile(); 
    220         } 
    221  
    222         $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; 
     182            $this->tpl_previous_page = $this->objNavi->arrPagenavi['before']; 
     183            $this->tpl_next_page =  $this->objNavi->arrPagenavi['next']; 
     184        } 
     185 
     186        $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'."\n"; 
    223187        $this->tpl_onload .= 'fnOnLoad(); '; 
    224188 
     
    318282                    ,product_id 
    319283__EOS__; 
    320                     $objQuery->setOrder($order); 
     284                    //$objQuery->setOrder($order); 
    321285                break; 
    322286        } 
     
    328292        $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition["arrval"], $arrval_order)); 
    329293 
    330         // 取得した表示すべきIDだけを指定して情報を取得。 < 謎の処理 
     294        // 取得した表示すべきIDだけを指定して情報を取得。 
    331295        $where = ""; 
    332296        if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 
     
    357321 
    358322    /* 入力内容のチェック */ 
    359     function lfCheckError($id) { 
     323    function lfCheckError($product_id,&$arrForm,$tpl_classcat_find1,$tpl_classcat_find2) { 
    360324 
    361325        // 入力データを渡す。 
    362         $objErr = new SC_CheckError($this->arrForm); 
     326        $objErr = new SC_CheckError($arrForm); 
    363327 
    364328        // 複数項目チェック 
    365         if ($this->tpl_classcat_find1[$id]) { 
     329        if ($tpl_classcat_find1[$product_id]) { 
    366330            $objErr->doFunc(array("規格1", 'classcategory_id1', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 
    367331        } 
    368         if ($this->tpl_classcat_find2[$id]) { 
     332        if ($tpl_classcat_find2[$product_id]) { 
    369333            $objErr->doFunc(array("規格2", 'classcategory_id2', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 
    370334        } 
     
    388352        } 
    389353        return $display_number; 
    390     } 
    391  
    392     /** 
    393      * ページャ用データ設定(モバイル) 
    394      * 
    395      * @return void 
    396      */ 
    397     function lfSetPagerMobile() { 
    398         // ページ送り機能用のURLを作成する。 
    399         $objURL = new Net_URL($_SERVER['PHP_SELF']); 
    400         foreach ($_REQUEST as $key => $value) { 
    401             if ($key == session_name() || $key == 'pageno') { 
    402                 continue; 
    403             } 
    404             $objURL->addQueryString($key, mb_convert_encoding($value, 'SJIS', CHAR_CODE)); 
    405         } 
    406  
    407         if ($this->objNavi->now_page > 1) { 
    408             $objURL->addQueryString('pageno', $this->objNavi->now_page - 1); 
    409             $this->tpl_previous_page = $objURL->path . '?' . $objURL->getQueryString(); 
    410         } 
    411         if ($this->objNavi->now_page < $this->objNavi->max_page) { 
    412             $objURL->addQueryString('pageno', $this->objNavi->now_page + 1); 
    413             $this->tpl_next_page = $objURL->path . '?' . $objURL->getQueryString(); 
    414         } 
    415354    } 
    416355 
     
    524463        return $searchCondition; 
    525464    } 
     465 
     466    /** 
     467     * カートに入れる商品情報にエラーがあったら戻す 
     468     * 
     469     * @return str 
     470     */    
     471    function lfSetSelectedData(&$arrProducts,$arrForm,$arrErr,$product_id){ 
     472        $js_fnOnLoad = ""; 
     473        foreach (array_keys($arrProducts) as $key) { 
     474            if ($arrProducts[$key]['product_id'] == $product_id) { 
     475                $arrProducts[$key]['product_class_id'] = $arrForm['product_class_id']; 
     476                $arrProducts[$key]['classcategory_id1'] = $arrForm['classcategory_id1']; 
     477                $arrProducts[$key]['classcategory_id2'] = $arrForm['classcategory_id2']; 
     478                $arrProducts[$key]['quantity'] = $arrForm['quantity']; 
     479                $arrProducts[$key]['arrErr'] = $arrErr; 
     480                $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProducts[$key]['product_id']}, '{$arrForm['classcategory_id2']}');\n"; 
     481            } 
     482        } 
     483        return $js_fnOnLoad; 
     484    } 
     485     
     486    /** 
     487     * カートに商品を追加 
     488     * 
     489     * @return void 
     490     */    
     491    function lfAddCart($arrForm,$tpl_classcat_find1,$tpl_classcat_find2,$target_product_id){ 
     492        $classcategory_id1 = $arrForm['classcategory_id1']; 
     493        $classcategory_id2 = $arrForm['classcategory_id2']; 
     494        // 規格1が設定されていない場合 
     495        if (!$tpl_classcat_find1[$target_product_id]) { 
     496            $classcategory_id1 = '0'; 
     497        } 
     498        // 規格2が設定されていない場合 
     499        if (!$tpl_classcat_find2[$target_product_id]) { 
     500            $classcategory_id2 = '0'; 
     501        } 
     502 
     503        // 規格IDを取得 
     504        $product_class_id = $arrForm['product_class_id']; 
     505        $product_type = $arrForm['product_type']; 
     506        $objCartSess = new SC_CartSession(); 
     507        $objCartSess->addProduct($product_class_id, $arrForm['quantity'], $product_type); 
     508 
     509        // カート「戻るボタン」用に保持 
     510        if (SC_Utils_Ex::sfIsInternalDomain($_SERVER['HTTP_REFERER'])) { 
     511            $_SESSION['cart_referer_url'] = $_SERVER['HTTP_REFERER']; 
     512        } 
     513 
     514        SC_Response_Ex::sendRedirect(CART_URLPATH); 
     515    } 
    526516} 
    527517?> 
Note: See TracChangeset for help on using the changeset viewer.