View Single Post
  #1  
Old 07-17-2006, 07:40 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default Redirect to Product Page when only One product in category

For simple sites that don't use sub-categories, etc, this may come in handy! Further, this was my first success at defining a Smarty var in the actual .TPL template file, then referencing back in php. I'm sure there is an easier way to do this, but this was my first successful attempt.

A request was made to have all of our category links on the left link directly to the individual product page when there is only one product in the category.

Adding the following code to the top of skin1/customer/main/subcategories.tpl does the trick!

Thanks to darrenkierman for pointing out that adding the following code to the top of skin1/customer/main/search_result.tpl will also take you straight to the product page if your search returns only 1 result!

Code:
{if $products|@count eq 1} {assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"} {php} header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] ); {/php} {/if}
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote