Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Exclude certain categories from new products module?

Exclude certain categories from new products module?

Views: 7,989

Results 1 to 20 of 20
30 Nov 2008, 6:01 AM
#1
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Exclude certain categories from new products module?

Searched all over, can't figure out how to exclude a certain category from showing up in the new product module... the one that displays random products on the homepage or other listing pages.

I supposed I can go in and modify the "Date Added" for each product in the database, and set the "New Product Listing - Limited to ..." 30 days. BUT this would be a pain, and I would have to do it each time I list a new product in that particular category. There should be an easier way.

Can someone let me know the key to accomplishing this?

For example: say your main product is A but you also sell some B. Most of your visitors will be coming to the site looking for A so you don't want all your B showing up randomly in all the product modules. Get it?

30 Nov 2008, 7:08 AM
#3
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

misty:

Similar thread at
http://www.zen-cart.com/forum/showthread.php?t=84752

That's a nice start, but I do not want to have to do global replace, since it's not a one time thing. I need to disable the entire category from displaying on the new product module.

Otherwise, you would need to customize the code to ignore products where master_categories_id = 1313 or what have you ...

Can someone please explain this more? How would one go about modifying the code to exclude a certain category?

/index.php?main_page=index&cPath=3_6

30 Nov 2008, 9:08 AM
#4
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: Exclude certain categories from new products module?

in includes/modules/pages/products_new/header_php.php

change:

$products_new_query_raw = "SELECT p.products_id, p.products_type, pd.products_name, p.products_image, p.products_price,
p.products_tax_class_id, p.products_date_added, m.manufacturers_name, p.products_model,
p.products_quantity, p.products_weight, p.product_is_call,
p.product_is_always_free_shipping, p.products_qty_box_status,
p.master_categories_id
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_MANUFACTURERS . " m
ON (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd
WHERE p.products_status = 1
AND p.products_id = pd.products_id
AND pd.language_id = :languageID " . $display_limit . $order_by;

to:

$products_new_query_raw = "SELECT p.products_id, p.products_type, pd.products_name, p.products_image, p.products_price,
p.products_tax_class_id, p.products_date_added, m.manufacturers_name, p.products_model,
p.products_quantity, p.products_weight, p.product_is_call,
p.product_is_always_free_shipping, p.products_qty_box_status,
p.master_categories_id
FROM " . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_MANUFACTURERS . " m
ON (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd
WHERE p.products_status = 1
AND p.products_id = pd.products_id
AND p.master_categories_id != CAT-TO-EXCLUDE
AND pd.language_id = :languageID " . $display_limit . $order_by;

Make sure to change "CAT-TO-EXCLUDE" to the number of the category you don't want to show up.

30 Nov 2008, 5:34 PM
#5
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

kiddo:

in includes/modules/pages/products_new/header_php.php

change:
p.master_categories_id != CAT-TO-EXCLUDE

Make sure to change "CAT-TO-EXCLUDE" to the number of the category you don't want to show up.

This is great info and it actually works =)

BUT it's only working for the "New Products" page. I need the particular category to be eliminated from the New Products module that displays random new products on the home page and other various pages.

30 Nov 2008, 8:14 PM
#6
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: Exclude certain categories from new products module?

The same can be done elsewhere. For instance if you are using the whats new sidebox and want to not have a category included there look in:

includes/modules/sideboxes/whats_new.php and find: (about line 19)

where p.products_id = pd.products_id
and p.products_status = 1 " . $display_limit;

and change to:

where p.products_id = pd.products_id
and p.master_categories_id != CAT-TO-SKIP
and p.products_status = 1 " . $display_limit;

If there are some other place where this category isn't to show, post a link to a page so I can see what you are saying about and I'll point you to where to patch.

Again, be sure to change CAT-TO-SKIP to the proper category id number.

Hint: you can exclude more than one category like:

where p.products_id = pd.products_id
and p.master_categories_id != CAT-TO-SKIP
and p.master_categories_id != ANOTHER-CAT-TO-SKIP
and p.products_status = 1 " . $display_limit;

or only show new items from one single category like:

where p.products_id = pd.products_id
and p.master_categories_id = CAT-TO-SELECT-FROM
and p.products_status = 1 " . $display_limit;

Hope that helps some.

1 Dec 2008, 6:05 AM
#7
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

GOT IT!

It works. The file I needed to modify was:
includes/modules/template/new_products.php

This effectively removed a particular category from showing up on the main page where the "New Products For (Month)" displays. No need to go into the database to change dates, no need to add fake dates when uploading new products.

Thanks for your help =)

1 Dec 2008, 6:30 AM
#8
kiddo avatar

kiddo

Totally Zenned

Join Date:
Jul 2006
Location:
SF Bay Area
Posts:
837
Plugin Contributions:
1

Re: Exclude certain categories from new products module?

Congrats on working it out. That is so much more satisfying!

Happy Zen Hacking!

24 Feb 2009, 4:05 PM
#9
ella33 avatar

ella33

New Zenner

Join Date:
Oct 2008
Posts:
21
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

I am also trying to prevent a category from showing up on the main page as a new product. This is the code I tried doing on the new_products.php page, but it is not stopping the category from displaying. What am I doing wrong?

if ( (($manufacturers_id > 0 && $_GET['filter_id'] == 0) || $_GET['music_genre_id'] > 0 || $_GET['record_company_id'] > 0) || (!isset($new_products_category_id) || $new_products_category_id == '0') ) {
$new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
p.products_date_added, p.products_price, p.products_type, p.master_categories_id
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
where p.products_id = pd.products_id
and p.master_categories_id != 684
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p.products_status = 1 " . $display_limit;
} else {
// get all products and cPaths in this subcat tree
$productsInCategory = zen_get_categories_products_list( (($manufacturers_id > 0 && $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : $cPath), false, true, 0, $display_limit);

if (is_array($productsInCategory) && sizeof($productsInCategory) > 0) {
// build products-list string to insert into SQL query
foreach($productsInCategory as $key => $value) {
$list_of_products .= $key . ', ';
}
$list_of_products = substr($list_of_products, 0, -2); // remove trailing comma

$new_products_query = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name,
                              p.products_date_added, p.products_price, p.products_type, p.master_categories_id
                       from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                       where p.products_id = pd.products_id
                       and p.master_categories_id != 684
                       and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                       and p.products_id in (" . $list_of_products . ")";
1 Apr 2010, 11:46 PM
#10
mrcastle avatar

mrcastle

Zen Follower

Join Date:
Feb 2010
Posts:
205
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

Hey everyone ... this is exactly what I would like to do.... I have a lot of sheet music and don't want it showing up in the new products window. It is category item# 10 and I've made the modification to the header_php.php file but it is not working. Is there something else I need to enable/disable in my admin to make this work ?

Thanks for your help.

8 Jul 2010, 3:24 PM
#11
fonzie avatar

fonzie

New Zenner

Join Date:
Feb 2008
Location:
Antwerpen
Posts:
51
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

I'm using version 1.3.9d, and this didn't work for me at all, in fact it even disabled showing all the new products,

29 Jul 2010, 3:26 PM
#12
monkeytown avatar

monkeytown

New Zenner

Join Date:
Nov 2007
Posts:
78
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

There is an add on called Hide Categories. That might work for you. We use it to disable categories that we provide direct links to for certain customers.

31 May 2011, 12:52 PM
#13
alabasta79 avatar

alabasta79

New Zenner

Join Date:
Jun 2010
Posts:
21
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

Thanks a lot.. although i'm using 1.3.9h and the coding changed a little bit.. but this thread really help me to exclude some category from new product... this is what i am searching for a long time..

thank you very much...:clap:

15 Nov 2015, 5:08 AM
#14
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Exclude certain categories from new products module?

monkeytown:

There is an add on called Hide Categories. That might work for you. We use it to disable categories that we provide direct links to for certain customers.

I know this is an old thread, I just thought this was funny. I was trying to hide a category from something and thought to myself "why re-invent the wheels... let's see what others have come up with" and I saw your link to HideCategories. I thought, "hey, that's clever"... lol... then I realized I wrote HideCategories. sigh

15 Nov 2015, 9:21 AM
#15
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Exclude certain categories from new products module?

s_mack:

I know this is an old thread, I just thought this was funny. I was trying to hide a category from something and thought to myself "why re-invent the wheels... let's see what others have come up with" and I saw your link to HideCategories. I thought, "hey, that's clever"... lol... then I realized I wrote HideCategories. sigh

Circle of life. :)

30 Nov 2015, 3:57 PM
#16
jmsnyder23 avatar

jmsnyder23

Zen Follower

Join Date:
Jan 2010
Location:
Richmond, Virginia, United States
Posts:
122
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

I can't get this to work on the new_products.php file in 1.54. I've added the line:

AND p.master_categories_id != 86

twice where necessary and the products in that category still show up on my main page in the new products listing. HELP!

Thanks :)

30 Nov 2015, 10:52 PM
#17
jmsnyder23 avatar

jmsnyder23

Zen Follower

Join Date:
Jan 2010
Location:
Richmond, Virginia, United States
Posts:
122
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

Could it maybe be because the category is hidden? This wasn't an issue in 1.39.

Any thoughts at all? I can't find an answer in the forum after hours of searching and nothing I try works.

1 Dec 2015, 4:58 AM
#18
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Exclude certain categories from new products module?

jmsnyder23:

I can't get this to work on the new_products.php file in 1.54. I've added the line:

AND p.master_categories_id != 86

twice where necessary and the products in that category still show up on my main page in the new products listing. HELP!

Thanks :)

You say above that using master_categories_id. This won't hide products that are linked to that category... If you want none of the product that appear in the category to be displayed then the query of product though needs to include a reference to the products_to_categories table and then to omit the products that are assigned to that category... (At the moment not doing the leg work to support this path if I'm barking up the wrong tree.)

The next thing is which new product(s) area are you wanting to affect because I thought I recently had to modify at least two files to address all new_products. There is also/possibly code in an applicable header_php.php file or simlar inthe includes/modules/pages directory...

1 Dec 2015, 5:05 AM
#19
jmsnyder23 avatar

jmsnyder23

Zen Follower

Join Date:
Jan 2010
Location:
Richmond, Virginia, United States
Posts:
122
Plugin Contributions:
0

Re: Exclude certain categories from new products module?

Thanks! I figured it out. Apparently the template I'm using had a different new_products.php file that was overriding the default one. I didn't realize that. When I found it, I added the line there twice and it excluded the right category like I wanted!

1 Dec 2015, 10:46 AM
#20
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Exclude certain categories from new products module?

jmsnyder23:

Thanks! I figured it out. Apparently the template I'm using had a different new_products.php file that was overriding the default one. I didn't realize that. When I found it, I added the line there twice and it excluded the right category like I wanted!

Welcome to the template override system. That is/has been the way to manage changes to the store's operation for the most part. It also makes upgrading a bit easier to leave the base files unchanged and only edit the override files.

Glad you were able to resolve the issue and letting others know that it was resolved.