This small change to /catalog/controller/home.php will display 6 random products instead of lates one. This is first release, will be updated soon, to provide additional features.
Code: Select all
if (!$customer->isLogged()) {
$view->set('text_greeting', $language->get('text_greeting', $url->href('account_login'), $url->href('account_create')));
} else {
$view->set('text_greeting', $language->get('text_logged', $customer->getFirstName()));
}
// Select Random products by JT
$allProducts = array ();
$results = $database->getRows("SELECT product_id FROM product WHERE status='1'");
foreach($results as $result)
$allProducts[] = $result['product_id'];
$numberOfProducts = count($allProducts)-1;
$randomProducts = array();
$numberOfRandomProducts = 0;
$randomMax = min( $numberOfProducts, 6 );
$randomList = "";
while( $numberOfRandomProducts < $randomMax ) {
$ptr = rand(0, $numberOfProducts );
if( $allProducts[$ptr]>0 ) {
$randomList .= $allProducts[$ptr];
if( $numberOfRandomProducts < ($randomMax-1) )
$randomList .= ",";
$randomProducts[] = $allProducts[$ptr];
$allProducts[$ptr] = 0;
$numberOfRandomProducts++;
}
}
// End Random products
$view->set('text_latest', $language->get('text_latest'));
$product_data = array();
$results = $database->getRows("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '" . (int)$language->getId() . "' and p.date_available < now() and p.status = '1' and p.product_id in (".$randomList.")");
I'll be happy to see your comments and ideas to improve it.