X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Hide products from a category in search results only (https://forum.x-cart.com/showthread.php?t=74854)

xcartdev2 01-10-2017 06:02 AM

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?

cflsystems 01-10-2017 08:47 AM

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.

xcartdev2 01-11-2017 02:16 AM

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;
                        }
                    }    
                } 



All times are GMT -8. The time now is 03:29 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.