Our category page child category links are generated using the code below. However, some categories only contain one product. If the category contains only one product is there a way to link directly to that product page rather than the category product listing page?
For example; the 'widgets' category contains only 1 product 'widget'. So rather than the code below generating a link to 'mywebsite.com/main-category/widgets.html' the link would go directly to 'mywebsite.com/widget-product.html
<?php
//If there are sub categories
$categories = $this->getCurrentChildCategories();
$categoriescount = $this->getCurrentChildCategories()->count();
if ($categoriescount > 0):
?>
<div class="container_12">
<?php
//Loop through categories
foreach ($categories as $category):
?>
<div class="grid_3 alpha special-spacing" style="margin-bottom:10px;">
<div>
<a href="<?php echo $this->getCategoryUrl($category)?>" class="cat-link"><?php echo $category->getName()?></a>
</div>
<a href="<?php echo $this->getCategoryUrl($category)?>" class="cat-image">
<?php
// If there is a thumbnail set for the category - Display it
if($imgUrl = Mage::getModel('catalog/category')->load($category->getId())->getImage()):?>
<img src="<?php echo $this->getBaseUrl()."media/catalog/category/".$imgUrl ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<?php endif; ?>
</a>
</div>
<?php endforeach; ?>
<div class="clear"></div>
</div>
<?php else:?>
<p>No Sub Categories</p>
<?php endif; ?>