Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Link a category directly to product page? - 2.3.1


Mrmike

Recommended Posts

Can anyone tell me how to link a Category link directly to the Product Page in 2.3.1 ? (ie: bypass the category product listing )

 

for instance I have 4 categories. Of the 4 categories 2 contain multiple items, and so the product listing is needed.

 

But the other 2 have only one item, so the product listing is redundant and just means the visitor has to click twice to get to the same item.

 

I find if I just add as a product without a category in admin, it doesnt list it in the Category box.

Link to comment
Share on other sites

I have done this, but as part of a rewrite of the categories (in index.php) to address a number of issues so my code no longer looks much like the original so I don't feel posting that here would help greatly.

 

Probably your best bet is to look at the product_listing.php module, add a test there with tep_db_num_rows (if thats not there already) then redirect if that = 1

 

 

PS This is not the place for queries, only solutions as tips

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Link to comment
Share on other sites

Yes, pretty simple, but resource intensive. Use at your own risk;

 

/includes/modules/bm_categories.php

 

Find:

   function tep_show_category($counter) {
     global $tree, $categories_string, $cPath_array;

 

Add After:

  $products_in_category = tep_count_products_in_category($counter);
  $direct_to_product = false;
  if ($products_in_category == 1) {
	$direct_to_product = true;
  }

 

Find:

 

	if ($tree[$counter]['parent'] == 0) {
	  $cPath_new = 'cPath=' . $counter;
	} else {
	  $cPath_new = 'cPath=' . $tree[$counter]['path'];
	}

 

Change to:

 

  if ($direct_to_product == false) {
	if ($tree[$counter]['parent'] == 0) {
	  $cPath_new = 'cPath=' . $counter;
	} else {
	  $cPath_new = 'cPath=' . $tree[$counter]['path'];
	}
  }
  else {
	$productPath = 'products_id=' . clubosc_get_product_in_category($counter);
  }

 

Find:

 

  $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

 

Change to:

  if ($direct_to_product == false) {
	$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
  }
  else {
	$categories_string .= tep_href_link(FILENAME_PRODUCT_INFO, $productPath) . '">';
  }

 

Find:

 

  if (SHOW_COUNTS == 'true') {
	$products_in_category = tep_count_products_in_category($counter);
	if ($products_in_category > 0) {
	  $categories_string .= ' (' . $products_in_category . ')';
	}
  }

 

Change to:

  if (SHOW_COUNTS == 'true') {

	if ($products_in_category > 0) {
	  $categories_string .= ' (' . $products_in_category . ')';
	}
  }

 

 

/includes/functions/general.php

 

Add:

 function clubosc_get_product_in_category($category) {
$product_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category . "'");
$product = tep_db_fetch_array($product_query);

return $product['products_id'];
 }

Link to comment
Share on other sites

it seems the same question was als asked in the general support section, to which i proposed another solution which seems much simpler:

http://www.oscommerce.com/forums/topic/376323-product-in-categories-box-231/

Ken

commercial support - unProtected channel, not to be confused with the forum with same name - open to everyone who need some professional help: either PM/email me, or go to my website (URL can be found in my profile).

over 20 years of computer programming experience.

Link to comment
Share on other sites

Thanks for some suggestions.

 

Ken's solution might be the answer, thus why I couldnt find a solid answer via search as his method approaches it differently.

 

I did find Spooks topic ( I think it was, the bird avatar is what's reminding me I read something of yours recently :P )

 

Anyhow Ill give this a go later and report back as to what worked for me!

 

PS: thats twice I posted this topic in the wrong forum, my bad :ph34r:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...