X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Exclude categories from recommends... (https://forum.x-cart.com/showthread.php?t=43026)

Jerrad 10-16-2008 04:18 AM

Exclude categories from recommends...
 
We're planning to add some categories to our store which contain adult/erotic products. Before these categories can be viewed customers will see a message that these categories contain erotic images and text.

Because of obvious reasons we don't want any of the products of these categories to show up in the recommends, which we use on the storefront of our store.

I've found this (old) post about excluding one category from the recommends:
http://forum.x-cart.com/showthread.php?t=21990&highlight=exclude+category+ recommends

Does anybody know what the code would be for excluding several categories from the recommends?

Any help is very appreciated. Many thanks in advance!

Jerrad :D

JWait 10-16-2008 01:18 PM

Re: Exclude categories from recommends...
 
How many categories are you trying to exclude? The reference you gave could possible be modified to include several (up to 3 or 4 maybe) just by adding more "AND"s. Also, the modification excludes main categories and subcategories, so if you had a category named "Adult" you could exclude all of the subcategories of "Adult".

Jerrad 10-16-2008 01:34 PM

Re: Exclude categories from recommends...
 
Thanks for your reply, JWait!

There are around 8 main categories, which each will have from 3 up to 10 subcategories.

Do I understand you correctly that excluding a main category like for example "Adult", will also automatically exclude all subcategories of that category?
Or must each subcategory excluded separately?

Thanks again!

JWait 10-16-2008 04:36 PM

Re: Exclude categories from recommends...
 
I'm just going by the original question in the other thread at http://forum.x-cart.com/showthread.php?t=21990 -
"Anyone know of a way to exclude the products of 1 specified main category (and its subcategories) from ever displaying in randomly generated Recommended Products results?"

I have not tried it, so I don't know if it works, but it does make sense that if a main category is excluded that any subcategories of the main category would be excluded also. Another thing to consider is that the thread was from 2006, and the version listed are 4.0.x branches. There may have been changes since then.

Jerrad 10-17-2008 06:14 AM

Re: Exclude categories from recommends...
 
I've added the code (red text in the bold line) to my recommends.php and it seems to work.
Unfortunately it 'only' excludes the category that is added and not the subcategories from that certain category.

Could it do any harm adding all the categories (25+) separately to the recommends and/or slow down the storefront, where the recommends are displayed?

All suggestions are very welcomed!
Thanks!


Code:


<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2005 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2005          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: recommends.php,v 1.1.2.4 2005/01/12 07:41:43 svowl Exp $
#
# Recommends list
#

if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }

#
# Get products data for current category and store it into $products array
#
$avail_condition = "";
if ($config["General"]["unlimited_products"] == "N" && $config["General"]["disable_outofstock_products"] == "Y") {
    $avail_condition = " AND $sql_tbl[products].avail>0 ";
}

$lng_condition = " AND $sql_tbl[products_lng].code='$store_language'";
$lng_fields = "IF ($sql_tbl[products_lng].product IS NOT NULL,$sql_tbl[products_lng].product, $sql_tbl[products].product) AS product, IF ($sql_tbl[products_lng].descr IS NOT NULL,$sql_tbl[products_lng].descr, $sql_tbl[products].descr) AS descr, IF ($sql_tbl[products_lng].full_descr IS NOT NULL,$sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) AS fulldescr";

if ($config["Modules"]["select_recommends_list_randomly"] == "Y") {
    $query_ids = array();
    $rnd = rand();
    $products_id = func_query("SELECT $sql_tbl[products].productid FROM $sql_tbl[products] USE INDEX (fi,fia), $sql_tbl[products_categories] USE INDEX (cpm), $sql_tbl[categories] USE INDEX (iam) WHERE $sql_tbl[products].forsale='Y' AND $sql_tbl[products].productid = $sql_tbl[products_categories].productid AND $sql_tbl[products_categories].main = 'Y' AND $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[categories].categoryid != 548 AND $sql_tbl[categories].membership IN ('".@$user_account['membership']."','') ".$avail_condition." ORDER BY RAND(NOW()+$rnd) LIMIT ".$config["Modules"]["number_of_recommends"]);
    if(!empty($products_id)) {
        foreach($products_id as $p) {
            $query_ids[] = $p['productid'];
        }
    }
    unset($products_id);
}

if ($config["Modules"]["select_recommends_list_randomly"] == "Y" && count($query_ids)>0) {
    $query = "SELECT $sql_tbl[products].*, $lng_fields FROM $sql_tbl[products] LEFT JOIN $sql_tbl[products_lng] ON $sql_tbl[products].productid=$sql_tbl[products_lng].productid $lng_condition WHERE $sql_tbl[products].productid IN ('".join("','",$query_ids)."')";

# Add extra code for Prices to Show

$recommends_prices = func_query("select * from $sql_tbl[pricing] where quantity='1' and productid in (".join(",",$query_ids).")");
    $smarty->assign("recommends_prices",$recommends_prices);
$query = "SELECT $sql_tbl[products].*, $lng_fields FROM $sql_tbl[products] LEFT JOIN $sql_tbl[products_lng] ON $sql_tbl[products].productid=$sql_tbl[products_lng].productid $lng_condition WHERE $sql_tbl[products].forsale='Y' ".$avail_condition." AND $sql_tbl[products].productid IN (".join(",",$query_ids).")";

#End Add extra code for Prices to Show

}
else
    $query = "SELECT DISTINCT sp2.productid, $sql_tbl[products].*, $lng_fields FROM $sql_tbl[stats_customers_products] as sp1, $sql_tbl[stats_customers_products] AS sp2, $sql_tbl[products], $sql_tbl[products_categories], $sql_tbl[categories] LEFT JOIN $sql_tbl[products_lng] ON $sql_tbl[products].productid=$sql_tbl[products_lng].productid $lng_condition WHERE sp1.productid='$productid' AND sp1.login=sp2.login AND sp2.productid!='$productid' AND $sql_tbl[products].productid=sp2.productid AND $sql_tbl[products].forsale='Y' AND $sql_tbl[products].productid = $sql_tbl[products_categories].productid AND $sql_tbl[products_categories].main = 'Y' AND $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[categories].membership IN ('".@$user_account['membership']."','') ".$avail_condition." ORDER BY $sql_tbl[products].product LIMIT ".$config["Modules"]["number_of_recommends"];

$recommends = func_query($query);

$smarty->assign("recommends",$recommends);
?>




All times are GMT -8. The time now is 01:33 AM.

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