Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Hide category in menu - how to?


Criz

Recommended Posts

Hello,

 

I have a few categories with products of which one category I do currently not want to show. I have seen that I can 'disable' individual products. Can I also do this with a category? I would like to have the category available for in the near future.

 

Disabling all the products in the category does not make the category hidden.

 

Thanks for your help!

 

Chris

Link to comment
Share on other sites

it used to be part of osCommerce but was taken out because it used too much resources (took to long, slowed down the site). It is still in CVS and there is a contribution that tells you how to put it back in.

 

Mattice

"Politics is the art of preventing people from taking part in affairs which properly concern them"

Link to comment
Share on other sites

Hey Mattice,

 

Could you help me out a little further?

 

I have just adjusted the contribution main_categories.php to display only enabled categories.

 

In the "what's New Box" I also only want to display products from the enabled categories. I have tried several options but did not succeed (I am not really a php wizard :wink: ). Hereunder, I enclosed the code for the what's new box. I adjusted the following line in main_categories.php to make that file work

 

$status = tep_db_num_rows(tep_db_query('describe categories status'));

 

$query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image

from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION .

" cd

where c.categories_status = '1'

 

I hope you are able to show me in the right direction.

 

Chris

 

<?php

/*

$Id: new_products.php,v 1.32 2002/04/26 20:28:07 dgw_ Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2002 osCommerce

 

Released under the GNU General Public License

*/

?>

<!-- new_products //-->

<?php

$info_box_contents = array();

$info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$info_box_contents = array();

$row = 0;

$col = 0;

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'center',

'params' => 'class="smallText" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . '</a><br>' . $currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])));

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

new contentBox($info_box_contents);

?>

<!-- new_products_eof //-->

Link to comment
Share on other sites

untested... but I think you mean this? (START / STOP has to be removed :D)

//snippet

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where [START ADDITIONAL] c.categories_status=1 and [STOP ADDITIONAL] p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS); 

}

 

Groeten,

Mattice

"Politics is the art of preventing people from taking part in affairs which properly concern them"

Link to comment
Share on other sites

Hi Mattice,

 

Thanks for the code. I added it and it looks like it should work, but it doesn't :cry: . I cannot figure out why. Maybe there are some conditions in the code that override this statement?

 

I will try some other ways of putting the code in.

 

Mazzel,

 

Chris

Link to comment
Share on other sites

Hai Chris,

 

Check this out, it's the CVS server at Sourceforge showing the categories.php box back in the days when it had the status bit:

 

http://cvs.sourceforge.net/cgi-bin/viewcvs....viewcvs-markup

 

Try to diff that to yours.

 

HTH

Mattice

"Politics is the art of preventing people from taking part in affairs which properly concern them"

Link to comment
Share on other sites

The problem with the whats new & bestsellers boxes are ones I had not considered. When I first made the enable/disable categories I was only doing it to easily disable categories for which i had no products yet, but would eventually be populated. Because there were no products, the Whats New & Bestsellers never showed anything for them. My assumption is that adding a small bit to the WHERE part of the sql statements, in /catalog/includes/boxes/best_sellers.php & /catalog/includes/boxes/whats_new.php files should do the trick.

 

In the Best_Sellers.php, there are two possible sql statements that are made, one if it is in a specific category and one if it is at the main store page, or any other non category page. The category one is easy to change, but I am not sure if it really needs to be, if you cant get into the disabled category in the first place :) it shouldnt matter, but I would make the change any way. Below are the changed parts. In the first sql statement I added the "c.categories_status='1' and " to the where claus, easy enough. The second sql statement (which is the non-category specific one) I messed with for a while on my site, but after several attempts without success, decided to just try using the same sql statement as the category one. Seems to be working correctly. (starts about line 15 in bestsellers.php)

 

Original:

  if ($cPath) {

   $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 } else {

   $best_sellers_query = tep_db_query("select p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 }

New:

 if ($cPath) {

   $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and c.categories_status='1' and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 } else {

   $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);

 }

 

Now in the whats_new.php this is what I would change to accomplish the same thing (this is about line 17 in whats_new.php)

 

Old:

if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' order by products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

 

New:

if ($random_product = tep_random_select("select distinct p.products_id, p.products_image, p.products_tax_class_id, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status=1 and p.products_id = p2c.products_id and c.categories_id = p2c.categories_id and c.categories_status=1 order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW)) {

 

Hope this helps.

>Insert witty comment here<

Link to comment
Share on other sites

Hi Mikel,

 

Great that you responded so quickly and thoroughly. If have tried the new codes and the strange thing is that it does not seem to make a difference. All the products are still shown in the whats new box and the bestsellers box. Could it have something to do with the OR statement in the code?

 

Does it work properly with your site? Maybe I am doing something wrong then.

 

Thanks,

 

Chris

Link to comment
Share on other sites

The Or section of the code, (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') is only checking to see what category is currently selected, or if no category is selected it is set to 0. I have been testing the changes, and have not found any problem with them displaying items of disabled categories in the Whats New box or the Best Sellers Box.

 

I did find a flaw where a new product will show on the main page in the "New Products for [CURRENTMONTH]", and on the New Products page (found by clicking on the arrow in the Whats New box). I am working on fixes for these as well. Looks like I may be updating my contribution as well ;)

 

I'll post here if/when I have a better answer.

>Insert witty comment here<

Link to comment
Share on other sites

Ok, so this is what seems to work for me so far,

 

../catalog/includes/modules/new_product.php

 

OLD:

  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

   $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

 } else {

   $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

 }

 

NEW:

  if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

   $new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where c.categories_status='1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

 } else {

   $new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where c.categories_status='1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added DESC limit " . MAX_DISPLAY_NEW_PRODUCTS);

 }

 

 

../catalog/products_new.php

 

OLD:

  $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added DESC, pd.products_name";

 

NEW:

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where c.categories_status=1 and p.products_id = p2c.products_id and c.categories_id = p2c.categories_id and products_status = '1' order by p.products_date_added DESC, pd.products_name";

 

I still am usure why the changes did not seem to work for the best_sellers and whats_new for you though, still looking at them to see what else might need changing.

>Insert witty comment here<

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...