I have been working on my own theme from the default RWD on 1.9.2.1.
I would like to limit the related products to show only 8 products instead of all of the say 139 I have currently for a single product.
Also, I would like to randomise so pick at random 8 from all of the related products.
I am aware that I could simply add a break in the loop so when it has iterated 8 times it'll stop, but this I believe can be waste of resources.
I have gathered that the code below is responsible for creating the collection of related products. So, how would I amend this in the correct way to limit to 8 products and choose at random?
$product = Mage::registry('product');
/* @var $product Mage_Catalog_Model_Product */
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->setPositionOrder()
->addStoreFilter()
;
if (Mage::helper('catalog')->isModuleEnabled('Mage_Checkout')) {
Mage::getResourceSingleton('checkout/cart')->addExcludeProductFilter($this->_itemCollection,
Mage::getSingleton('checkout/session')->getQuoteId()
);
$this->_addProductAttributesAndPrices($this->_itemCollection);
}
// Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_itemCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
$this->_itemCollection->load();
foreach ($this->_itemCollection as $product) {
$product->setDoNotUseCategoryId(true);
}
return $this;