Post by pta » Wed Mar 25, 2015 3:40 pm

Hi,

i am using opencart 2.0.1.1, my query is , how to display product picture randomly in each visit of page in featured and latest module.now it is displaying same picture in every visit.
And for latest module, i am not able to select product for display, it just display product picture which i set a limit of 3
pls, help

pta
New member

Posts

Joined
Sun Feb 08, 2015 11:54 am

Post by grgr » Wed Mar 25, 2015 5:14 pm

For the latest you can try something like this:

Edit ../catalog/controller/module/latest.php

Find this bit:

Code: Select all

		$filter_data = array(
			'sort'  => 'p.date_added',
			'order' => 'DESC',
			'start' => 0,
			'limit' => $setting['limit']
		);

		$results = $this->model_catalog_product->getProducts($filter_data);

		if ($results) {

and change it so that it looks like this instead:

Code: Select all

		$filter_data = array(
			'sort'  => 'p.date_added',
			'order' => 'DESC',
			'start' => 0,
			'limit' => 10 * $setting['limit']
		);

		$results = $this->model_catalog_product->getProducts($filter_data);

		if ($results) {
			shuffle($results); 
			$results = array_slice($results, 0, $setting['limit']);

For featured you could try this:

edit: ../catalog/controller/module/featured.php

find:

Code: Select all

		$products = array_slice($setting['product'], 0, (int)$setting['limit']);
and add a shuffle like so:

Code: Select all

		shuffle($setting['product']);
		$products = array_slice($setting['product'], 0, (int)$setting['limit']);

-
Image Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by pta » Thu Mar 26, 2015 1:47 am

Hi grgr,

i tried your suggestion, its not working after testing. any suggestions

i used here as per your suggestion in latest page---
$data['products'] = array();

$filter_data = array(
'sort' => 'p.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => 10 * $setting['limit']
);

$results = $this->model_catalog_product->getProducts($filter_data);

if ($results) {
shuffle($results);
$results = array_slice($results, 0, $setting['limit']);


and i used ur suggestion here..for featured

$data['products'] = array();

if (!$setting['limit']) {
$setting['limit'] = 4;
}
shuffle($setting['product']);
$products = array_slice($setting['product'], 0, (int)$setting['limit']);

foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);

pta
New member

Posts

Joined
Sun Feb 08, 2015 11:54 am

Post by pta » Wed Apr 01, 2015 7:05 pm

hi grgr,

can u please help it out, the suggested code is not working for randomizing images.

pta
New member

Posts

Joined
Sun Feb 08, 2015 11:54 am

Post by award123 » Sat Nov 21, 2015 4:28 am

Hello,

I am upgraded to 2.1.0.1 and am trying to do the same. I modified the /catalog/controller/module/featured.php and added the shuffle($setting['product']); accordingly and nothing seems to work. Help?

Newbie

Posts

Joined
Wed Sep 16, 2015 10:13 pm
Who is online

Users browsing this forum: No registered users and 120 guests