This is a useful little tweak to the extremely useful Easy Tabs Free Magento Extension. I love Easy Tabs and use it as much as possible.
In this particular site rather than using an auto relate extension I have manually related many products – it took ages so when it was necessary to increase page speed I needed a neat way to both limit and randomise the shown products so that they aren’t in the same order each page load.
In the code below I have stripped out a lot of what I think is unnecessary functionality, such as the buy now checkbox and wishlist etc – if you particularly want that functionality combine your code with the below.
All you need to do is to swap below code for your code in: app/design/frontend/
To change the number of products shown simply change the number in this line: $rel_items_rand_num = 6;
getItems()->getSize();
$rel_items_rand_num = 6;
$rel_items_rand_cnt = 0;
$rel_items_rand;
if ($rel_items_num > 0) {
foreach($this->getItems() as $_item) {
$rel_items_rand[] = $_item;
}
shuffle($rel_items_rand);
if ($rel_items_rand_num < $rel_items_num) {
$rel_items_rand = array_chunk($rel_items_rand, $rel_items_rand_num);
$rel_items_rand = $rel_items_rand[0];
}
}
?>
getItems()->getSize()-1)); ?>
- isComposite() || !$_item->isSaleable()): ?> class="super-products">
htmlEscape($_item->getName()),"...", 40);?>
getPriceHtml($_item, true) ?>
I Hope this helps someone out there, any questions please ask.
Great solution! It works for me, but i notice that that $rel_items_rand_cnt isn’t use and $index_iterator should be declared on top with 0.
But, great work. You helped me a lot 😉
Hi Prof, please can add your complete code here?
The above code now fixes a couple of bugs.