I did not use the mysql random sort as it proved way too slow when you have a large number or products. The randomization occurs in php code.
/catalog/controller/product/category.php
lines 62-66 before:
Code: Select all
if ($category_info['image']) {
$image = $category_info['image'];
} else {
$image = '';
}
Code: Select all
if ($category_info['image']) {
$image = $category_info['image'];
} else {
$image = '';
// Use random image from products in the category
$rndImgQry = "SELECT p.image AS image FROM product AS p JOIN product_to_category AS c ON p.product_id = c.product_id "
. "WHERE c.category_id = " . $category_info['category_id'] . " AND p.image NOT LIKE 'no_image.jpg'";
$rndImgRslt = mysql_query($rndImgQry) or die (mysql_error());
if (mysql_num_rows($rndImgRslt) > 0)
{
$imgRows = array();
while($imgRow = mysql_fetch_array($rndImgRslt))
{
$imgRows[] = $imgRow['image'];
}
$image = $imgRows[array_rand($imgRows)];
}
}
lines 109-113 before:
Code: Select all
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
Code: Select all
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
// Use random image from products in the category
$rndImgQry = "SELECT p.image AS image FROM product AS p JOIN product_to_category AS c ON p.product_id = c.product_id "
. "WHERE c.category_id = " . $result['category_id'] . " AND p.image NOT LIKE 'no_image.jpg'";
$rndImgRslt = mysql_query($rndImgQry) or die (mysql_error());
if (mysql_num_rows($rndImgRslt) > 0)
{
$imgRows = array();
while($imgRow = mysql_fetch_array($rndImgRslt))
{
$imgRows[] = $imgRow['image'];
}
$image = $imgRows[array_rand($imgRows)];
}
}