Jump to content

How does Home Featured's modules random function works?


Recommended Posts

Hi,

I've made some changes in Home Featured module and it worked well. But then I got info that after my changes, it doesn't random displayed products even though it has the option set that it should random them. I didn't touch anything related to that, so I was highly surprised. I've then checked the code and found this in the homefeatured.php:

if (!isset(HomeFeatured::$cache_products))
{
	$category = new Category((int)Configuration::get('HOME_FEATURED_CAT'), (int)Context::getContext()->language->id);
	$nb = (int)Configuration::get('HOME_FEATURED_NBR');
	if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
		HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));
	else
		HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
}

So, I believe it randoms the products once, caches them and then displays them ... well, forever. Is this correct?

Also, I don't understand this call of the getProducts function:

if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
	HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));

Here's the definition of the function in Products.php:

public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
        $only_active = false, Context $context = null)

So, getProducts takes only 8 arguments, but in the function call that I've showed, it gives 9 arguments to it. Why?

I also don't see it randoming the products anywhere. It always starts from the 1 position and takes x products. Where is the randoming factor?

Edited by kubaseo (see edit history)
Link to comment
Share on other sites

 

So, I believe it randoms the products once, caches them and then displays them ... well, forever. Is this correct?

it displays the same products as long as cache will exist, once you will clear it - the products will be randomized again.

 

 

Also, I don't understand this call of the getProducts function:

its not from product.php but from category.php class

  • Like 1
Link to comment
Share on other sites

it displays the same products as long as cache will exist, once you will clear it - the products will be randomized again.

So it's exactly as I suspected. I have to say though, option in the configuration of HomeFeatured module can be a bit misleading - my client was sure they get randomized by some period of time / every time you visit the page.

I only figured out that it's not the case after looking into the code, before that I thought too that it works this way.

I'll ask him if he'd like it to random on every page refresh then, seems like a very easy change.

its not from product.php but from category.php class

Well now it makes perfect sense.

Thanks a lot vekia.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...