public function get_random_same_cate_products() {
$_product = $this->getProduct();
$categoryIds = $_product->getCategoryIds();
if(count($categoryIds) ){
foreach ($categoryIds as $cid) {
$_category = Mage::getModel('catalog/category')->load($cid);
if ($_category->getLevel() == 3) {
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => $cid),
)
)
->addAttributeToFilter('type_id','configurable')
->addAttributeToFilter('sku',array('neq'=>$_product->getSku()));
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 4);
return $_productCollection;
}
}
}
}