<?php //if(count($this->getItemCollection()->getItems())): ?>
<?php
$_product = $this->getProduct();
$categories = $_product->getCategoryIds();
$_currentCatId = $categories[array_rand($categories,1)];
$_currentCategory = Mage::getModel('catalog/category')->load($_currentCatId);
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_currentCategory)->addAttributeToSelect(array('name', 'price'), 'inner')-> addAttributeToFilter('visibility', $visibility);
foreach ($products as $product) {
$result[] = $product->getId();
}
if(count($result) >= 5){
$ourneed = array_rand($result,5);
}else{
$ourneed = array_keys($result);
}
?>
<div class="box-collateral box-up-sell">
<h5 class="upsell-product-h5"><?php echo $this->__('You may also be interested in the following product(s)') ?></h5>
<table class="mini-products-grid" id="upsell-product-table">
<?php // $this->setColumnCount(5); ?>
<?php //$this->resetItemsIterator() ?>
<?php //for($_i=0;$_i<$row;$_i++): ?>
<tr>
<?php
foreach($ourneed as $cc):
$_product = Mage::getModel('catalog/product')->load($result[$cc]);
?>
<td>
<a href="<?php echo Mage::getBaseUrl('web').$_product->getUrlKey().'.html' ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(171) ?>" width="171" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
<div class="moreinformation">
<h3 class="product-name"><a href="<?php echo Mage::getBaseUrl('web').$_product->getUrlKey().'.html' ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
<?php echo $this->getPriceHtml($_product, true, '-upsell') ?>
</div>
</td>
<?php endforeach; ?>
</tr>
<?php //endfor; ?>
</table>
<script type="text/javascript">decorateTable('upsell-product-table')</script>
</div>
<?php //endif ?>