Ignore:
Timestamp:
2013/02/26 09:09:44 (11 years ago)
Author:
pineray
Message:

#2162 pageクラスからdtb_best_productsテーブルを直接指定している箇所をなくす

Location:
branches/version-2_12-dev/data
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/Smarty/templates/admin/contents/recommend.tpl

    r22572 r22582  
    2121 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
    2222 */ 
    23 *}--> 
     23 
     24 *}--> 
    2425 
    2526<script type="text/javascript"> 
     
    7576    if ( flag ){ 
    7677        document.form1["mode"].value = mode; 
    77         document.form1["rank"].value = data; 
     78        document.form1["best_id"].value = data; 
    7879        document.form1.submit(); 
    7980    } 
     
    117118                                            <input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" /> 
    118119                                            <input type="hidden" name="mode" value="regist" /> 
     120                                            <input type="hidden" name="best_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].best_id|h}-->" /> 
    119121                                            <input type="hidden" name="product_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].product_id|h}-->" /> 
    120122                                            <input type="hidden" name="category_id" value="<!--{$category_id|h}-->" /> 
     
    133135                                <input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" /> 
    134136                                <input type="hidden" name="mode" value="regist" /> 
     137                                <input type="hidden" name="best_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].best_id|h}-->" /> 
    135138                                <input type="hidden" name="product_id" value="<!--{$arrItems[$smarty.section.cnt.iteration].product_id|h}-->" /> 
    136139                                <input type="hidden" name="category_id" value="<!--{$category_id|h}-->" /> 
     
    158161                    <!--{* 移動 *}--> 
    159162                    <!--{if $smarty.section.cnt.iteration != 1 && $arrItems[$smarty.section.cnt.iteration].product_id}--> 
    160                         <a href="?" onclick="lfnSortItem('up',<!--{$arrItems[$smarty.section.cnt.iteration].rank}-->); return false;">上へ</a><br />&nbsp; 
     163                        <a href="?" onclick="lfnSortItem('up',<!--{$arrItems[$smarty.section.cnt.iteration].best_id}-->); return false;">上へ</a><br />&nbsp; 
    161164                    <!--{/if}--> 
    162165                    <!--{if $smarty.section.cnt.iteration != $tpl_disp_max && $arrItems[$smarty.section.cnt.iteration].product_id}--> 
    163                         <a href="?" onclick="lfnSortItem('down',<!--{$arrItems[$smarty.section.cnt.iteration].rank}-->); return false;">下へ</a> 
     166                        <a href="?" onclick="lfnSortItem('down',<!--{$arrItems[$smarty.section.cnt.iteration].best_id}-->); return false;">下へ</a> 
    164167                    <!--{/if}--> 
    165168                </td> 
  • branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php

    r22567 r22582  
    7777        $objFormParam->setParam($_POST); 
    7878        $objFormParam->convParam(); 
    79         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    80         $objDb = new SC_Helper_DB_Ex(); 
     79        $arrPost = $objFormParam->getHashArray(); 
     80 
     81        $objRecommend = new SC_Helper_Recommend_Ex(); 
    8182 
    8283        switch ($this->getMode()) { 
    83             case 'down': //商品の並び替えをする。おすすめはデータベースの登録が昇順なので、Modeを逆にする。 
    84                 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 
    85                 $best_id = $arrRet[0]['best_id']; 
    86                 $objDb->sfRankUp('dtb_best_products','best_id',$best_id); 
    87                 $arrPost = $objFormParam->getHashArray(); 
    88                 $arrItems = $this->getRecommendProducts(); 
    89                 break; 
    90  
    91             case 'up': //商品の並び替えをする。おすすめのみデータベースの登録が昇順なので、Modeを逆にする。 
    92                 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 
    93                 $best_id = $arrRet[0]['best_id']; 
    94                 $objDb->sfRankDown('dtb_best_products','best_id',$best_id); 
    95                 $arrPost = $objFormParam->getHashArray(); 
    96                 $arrItems = $this->getRecommendProducts(); 
     84            case 'down': //商品の並び替えをする。 
     85                $objRecommend->rankDown($arrPost['best_id']); 
     86                $arrItems = $this->getRecommendProducts($objRecommend); 
     87                break; 
     88 
     89            case 'up': //商品の並び替えをする。 
     90                $objRecommend->rankUp($arrPost['best_id']); 
     91                $arrItems = $this->getRecommendProducts($objRecommend); 
    9792                break; 
    9893 
    9994            case 'regist': // 商品を登録する。 
    10095                $this->arrErr = $this->lfCheckError($objFormParam); 
    101                 $arrPost = $objFormParam->getHashArray(); 
    10296                // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 
    10397                if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    10498                    $member_id = $_SESSION['member_id']; 
    105                     $this->insertRecommendProduct($arrPost,$member_id); 
    106                     $arrItems = $this->getRecommendProducts(); 
     99                    $this->insertRecommendProduct($arrPost,$member_id,$objRecommend); 
     100                    $arrItems = $this->getRecommendProducts($objRecommend); 
    107101                } else { 
    108102                    $arrItems = $this->setProducts($arrPost, $arrItems); 
     
    113107            case 'delete': // 商品を削除する。 
    114108                $this->arrErr = $this->lfCheckError($objFormParam); 
    115                 $arrPost = $objFormParam->getHashArray(); 
    116109                if (SC_Utils_Ex::isBlank($this->arrErr)) { 
    117                     $this->deleteProduct($arrPost); 
    118                     $arrItems = $this->getRecommendProducts(); 
     110                    $this->deleteProduct($arrPost, $objRecommend); 
     111                    $arrItems = $this->getRecommendProducts($objRecommend); 
    119112                } 
    120113                $this->tpl_onload = "window.alert('削除しました');"; 
     
    124117                $arrPost = $objFormParam->getHashArray(); 
    125118                if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { 
    126                     $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts()); 
     119                    $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts($objRecommend)); 
    127120                    $this->checkRank = $arrPost['rank']; 
    128121                } 
    129122                break; 
    130123            default: 
    131                 $arrItems = $this->getRecommendProducts(); 
     124                $arrItems = $this->getRecommendProducts($objRecommend); 
    132125                break; 
    133126        } 
     
    158151    function lfInitParam(&$objFormParam) 
    159152    { 
     153        $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 
    160154        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 
    161155        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 
     
    178172    /** 
    179173     * 既に登録されている内容を取得する 
     174     * @param Object $objRecommend 
    180175     * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 
    181176     */ 
    182     function getRecommendProducts() 
    183     { 
     177    function getRecommendProducts(SC_Helper_Recommend_Ex &$objRecommend) 
     178    { 
     179        $arrList = $objRecommend->getList(); 
     180        // product_id の一覧を作成 
     181        $product_ids = array(); 
     182        foreach ($arrList as $value) { 
     183            $product_ids[] = $value['product_id']; 
     184        } 
     185 
     186        $objProduct = new SC_Product_Ex; 
    184187        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    185         $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*,dtb_products.status'; 
    186         $table = 'dtb_best_products INNER JOIN dtb_products ON dtb_best_products.product_id = dtb_products.product_id'; 
    187         $where = 'dtb_best_products.del_flg = 0'; 
    188         $order = 'rank'; 
    189         $objQuery->setOrder($order); 
    190         $arrProducts = $objQuery->select($col, $table, $where); 
     188        $arrProducts = $objProduct->getListByProductIds($objQuery, $product_ids); 
    191189 
    192190        $arrReturnProducts = array(); 
    193         foreach ($arrProducts as $data) { 
     191        foreach ($arrList as $data) { 
     192            $data['main_list_image'] = $arrProducts[$data['product_id']]['main_list_image']; 
     193            $data['name'] = $arrProducts[$data['product_id']]['name']; 
    194194            $arrReturnProducts[$data['rank']] = $data; 
    195195        } 
     
    201201     * @param Array $arrPost POSTの値を格納した配列 
    202202     * @param Integer $member_id 登録した管理者を示すID 
    203      */ 
    204     function insertRecommendProduct($arrPost,$member_id) 
    205     { 
    206         $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     203     * @param Object $objRecommend 
     204     */ 
     205    function insertRecommendProduct($arrPost,$member_id, SC_Helper_Recommend_Ex &$objRecommend) 
     206    { 
    207207        // 古いおすすめ商品のデータを削除する。 
    208         $this->deleteProduct($arrPost); 
     208        $this->deleteProduct($arrPost, $objRecommend); 
    209209 
    210210        $sqlval = array(); 
     
    214214        $sqlval['comment'] = $arrPost['comment']; 
    215215        $sqlval['creator_id'] = $member_id; 
    216         $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 
    217         $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 
    218         $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id'); 
    219         $objQuery->insert('dtb_best_products', $sqlval); 
     216        $objRecommend->save($sqlval); 
    220217    } 
    221218 
     
    223220     * データを削除する 
    224221     * @param Array $arrPost POSTの値を格納した配列 
    225      */ 
    226     function deleteProduct($arrPost) 
    227     { 
    228         $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    229         $table = 'dtb_best_products'; 
    230         $where = 'category_id = ? AND rank = ?'; 
    231         $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']); 
    232         $objQuery->delete($table, $where, $arrWhereVal); 
     222     * @param Object $objRecommend 
     223     * @return void 
     224     */ 
     225    function deleteProduct($arrPost, SC_Helper_Recommend_Ex &$objRecommend) 
     226    { 
     227        if ($arrPost['best_id']) { 
     228            $target = $arrPost['best_id']; 
     229        } else { 
     230            $recommend = $objRecommend->getByRank($arrPost['rank']); 
     231            $target = $recommend['best_id']; 
     232        } 
     233        $objRecommend->delete($target); 
    233234    } 
    234235 
     
    236237     * 商品情報を取得する 
    237238     * @param Integer $product_id 商品ID 
    238      * @return Array $arrProduct 商品のデータを格納した配列 
     239     * @return Array $return 商品のデータを格納した配列 
    239240     */ 
    240241    function getProduct($product_id) 
    241242    { 
    242         $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    243         $col = 'product_id,main_list_image,name'; 
    244         $table = 'dtb_products'; 
    245         $where = 'product_id = ? AND del_flg = 0'; 
    246         $arrWhereVal = array($product_id); 
    247         $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal); 
    248         return $arrProduct[0]; 
     243        $objProduct = new SC_Product_Ex(); 
     244        $arrProduct = $objProduct->getDetail($product_id); 
     245        $return = array( 
     246            'product_id' => $arrProduct['product_id'], 
     247            'main_list_image' => $arrProduct['main_list_image'], 
     248            'name' => $arrProduct['name'] 
     249        ); 
     250        return $return; 
    249251    } 
    250252 
  • branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php

    r22577 r22582  
    266266    { 
    267267        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     268        $arrRet = $objQuery->getCol('product_id', "dtb_products", $where, $arrParam); 
     269        $product_ids = array(); 
     270        foreach ($arrRet as $value) { 
     271            $product_ids[] = $value['product_id']; 
     272        } 
    268273        $sqlval['del_flg']     = 1; 
    269274        $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 
     
    271276        $objQuery->update('dtb_products_class', $sqlval, "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); 
    272277        $objQuery->delete('dtb_customer_favorite_products', "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); 
    273         $objQuery->delete('dtb_best_products', "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam); 
     278 
     279        $objRecomment = new SC_Helper_Recommend_Ex(); 
     280        $objRecomment->deleteByProductIDs($product_ids); 
     281 
    274282        $objQuery->update('dtb_products', $sqlval, $where, $arrParam); 
    275283        $objQuery->commit(); 
  • branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend.php

    r22567 r22582  
    9494    function lfGetRanking() 
    9595    { 
    96         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    97         $objProduct = new SC_Product_Ex(); 
     96        $objRecommend = new SC_Helper_Recommend_Ex(); 
    9897 
    9998        // おすすめ商品取得 
    100         $col = 'T1.best_id, T1.category_id, T1.rank, T1.product_id, T1.title, T1.comment, T1.create_date, T1.update_date'; 
    101         $table = 'dtb_best_products as T1 INNER JOIN dtb_products as T2 ON T1.product_id = T2.product_id'; 
    102         $where = 'T1.del_flg = 0 and T2.status = 1'; 
    103         if (NOSTOCK_HIDDEN) { 
    104             $where .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = T1.product_id AND dtb_products_class.del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))'; 
    105         } 
    106         $objQuery->setOrder('T1.rank'); 
    107         $objQuery->setLimit(RECOMMEND_NUM); 
    108         $arrBestProducts = $objQuery->select($col, $table, $where); 
     99        $arrRecommends = $objRecommend->getList(RECOMMEND_NUM); 
    109100 
    110         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    111         if (count($arrBestProducts) > 0) { 
     101        $response = array(); 
     102        if (count($arrRecommends) > 0) { 
    112103            // 商品一覧を取得 
     104            $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     105            $objProduct = new SC_Product_Ex(); 
    113106            // where条件生成&セット 
    114107            $arrProductId = array(); 
    115             $where = 'product_id IN ('; 
    116             foreach ($arrBestProducts as $key => $val) { 
     108            foreach ($arrRecommends as $key => $val) { 
    117109                $arrProductId[] = $val['product_id']; 
    118110            } 
    119             // 取得 
    120             $arrProductList = $objProduct->getListByProductIds($objQuery, $arrProductId); 
     111            $arrProducts = $objProduct->getListByProductIds($objQuery, $arrProductId); 
     112 
     113            // 税込金額を設定する 
     114            SC_Product_Ex::setIncTaxToProducts($arrProducts); 
     115 
    121116            // おすすめ商品情報にマージ 
    122             foreach ($arrBestProducts as $key => $value) { 
    123                 $arrRow =& $arrBestProducts[$key]; 
    124                 if (isset($arrProductList[$arrRow['product_id']])) { 
    125                     $arrRow = array_merge($arrRow, $arrProductList[$arrRow['product_id']]); 
     117            foreach ($arrRecommends as $key => $value) { 
     118                if (isset($arrProducts[$value['product_id']])) { 
     119                    $product = $arrProducts[$value['product_id']]; 
     120                    if (!NOSTOCK_HIDDEN || ($product['status'] == 1 && ($product['stock_max'] >= 1 || $product['stock_unlimited_max'] == 1))) { 
     121                        $response[] = array_merge($value, $arrProducts[$value['product_id']]); 
     122                    } 
    126123                } else { 
    127124                    // 削除済み商品は除外 
    128                     unset($arrBestProducts[$key]); 
     125                    unset($arrRecommends[$key]); 
    129126                } 
    130127            } 
    131128        } 
    132         return $arrBestProducts; 
     129        return $response; 
    133130    } 
    134131} 
Note: See TracChangeset for help on using the changeset viewer.