Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Hide products from a category in search results only

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 01-10-2017, 06:02 AM
 
xcartdev2 xcartdev2 is offline
 

Advanced Member
  
Join Date: Nov 2011
Posts: 43
 

Default Hide products from a category in search results only

I've got a category which is available and visible and has active products in it but I don't want those products to show in general searches. The categoryid is 273.

In includes/search.php I tried adding the line:
PHP Code:
if ($cat == ''
            
$inner_joins['categories']['on'] .= " AND $sql_tbl[categories].categoryid != 273"

Just below

PHP Code:
if ($current_area == 'C'
            
$inner_joins['categories']['on'] .= " AND $sql_tbl[categories].avail = 'Y'"


It does add this to the query so it reads "...INNER JOIN xcart_categories ON xcart_products_categories.categoryid = xcart_categories.categoryid AND xcart_categories.avail = 'Y' AND xcart_categories.catgeoryid != 273 ... " but seems to have no effect.

Any ideas how this can be done?
__________________
Verion 4.7.12
Reply With Quote
  #2  
Old 01-10-2017, 08:47 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: Hide products from a category in search results only

You have to add the condition in

where[] = .....

No need to "join" the table as it is already joined.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 01-11-2017, 02:16 AM
 
xcartdev2 xcartdev2 is offline
 

Advanced Member
  
Join Date: Nov 2011
Posts: 43
 

Default Re: Hide products from a category in search results only

Thanks cflsystems but I realised this would only work if the main category of the product to be hidden was 273.

A better way I found (for anyone else who finds this thread) is to flush out the products after the database query has been completed. Like this:

PHP Code:
// collect productids of products from categoryid 273 to flush from search results
                
if ($cat == "") { // only if this is a search result, not a category page
                
$get_products=mysql_query("SELECT productid FROM xcart_products_categories WHERE categoryid='273'");    
                
                while (
$row_products mysql_fetch_array($get_products)) {
                    
$products_arr[]=$row_products['productid'];
                    }
                    
                foreach (
$products as $k => $v) {
                    if (
in_array($products[$k]['productid'], $products_arr)) {
                        unset(
$products[$k]);
                        
$total_items=$total_items-1;
                        }
                    }    
                } 
__________________
Verion 4.7.12
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:46 AM.

   

 
X-Cart forums © 2001-2020