Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Display Link to Category Product Is In


rcmdesign

Recommended Posts

Posted

I want to display a link in the products description to the category that the product is in. I thought I could go about doing it with <a href="index.php?cPath=$cPath">Link</a> but that doesn't seem to work. Anyone know how to get this link to work?

Posted

as $cPath is a variable you need to echo the value it holds.

 

try:

 

<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath) . '">' . 'Link' . '</a>'; ?>

Your online success is Paramount.

Posted

nothing done it phpmyadmin.

 

just added this line:

 

<tr> <td class="main">

<?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath) . '">' . 'More in this Collection' . '</a>'; ?>

</td></tr>

 

to the product_info.php page.

Your online success is Paramount.

Posted

Oh ok. I am referring to the product_description because I only want this done in the descrption for certain products. Thanks.

Posted

oki - well you could include it in product_info.php and just IF clause it depending on product_id.

 

depending on how many products you wanted it for.

Your online success is Paramount.

Posted

I just realized that code doesn't work if the user searches for the item, or if they select a manufaturer and the item shows up in the results. For some reason it does not pass the cPath parameter when you search for it, or use manufacturer's drop down box. So we would have to put that from that specific product's information in the database. It's category...Any ideas...

Posted

Ok here is the fix for that:

 

in products_info.php add somewhere below description:

 

$categories_info_query = tep_db_query("select p2c.categories_id, p2c.products_id, p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id = p2c.products_id");

$categories_info = tep_db_fetch_array($categories_info_query);

echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $categories_info['categories_id']) . '">' . '<b>Click here to view more products from this category.</b>' . '</a>';

Posted

Quick fix to above code -

 

Issue: if customer browses categories in the category box to a particular product, and then clicks the link in the product_info.php page to see other products in that category, it will close up all of the open categories in the includes/boxes/categories.php box. Here is the fix for that:

 

if ($cPath) {

echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath) . '">' . '<b>Click here to view more products in this category.</b>' . '</a>';

} else {

$categories_info_query = tep_db_query("select p2c.categories_id, p2c.products_id, p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_id = p2c.products_id");

$categories_info = tep_db_fetch_array($categories_info_query);

echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $categories_info['categories_id']) . '">' . '<b>Click here to view more products in this category.</b>' . '</a>';

}

Posted

you can also use:

 

<?php if(isset($cPath) && tep_not_null($cPath))
{ ?>
<tr> <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $cPath) . '">' . 'More in this Collection' . '</a>'; ?></td></tr>
<?php
}
else
{
?>
<tr> <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . (int)$HTTP_GET_VARS['manufacturers_id']) . '">' . 'More in this Collection' . '</a>'; ?></td></tr>
<?php } ?>

 

Which uses the manufacturer id if cPath is unset. Works for me on both manufacturer and search.

Your online success is Paramount.

Archived

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

×
×
  • Create New...