Jump to content

[Résolu] Produits fares aléatoire


Recommended Posts

Bonjour,

 

Quelqu'un aurait il une idée comment faire les produits phares aléatoires sur la version de prestashop 1.6.

 

Sur la 1.5 ce code marche mais pas sur la 1.6

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10),NULL,NULL,false,true,true,($nb ? $nb : 50));

Voici le code à modifier :

public function _cacheProducts()
	{
		if (!isset(HomeFeatured::$cache_products))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
		}

		if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
			return false;
	}

Merci par avance ..

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

Bonjour,

 

 

La solution !

if (!isset(HomeFeatured::$cache_products))
		{
			
			
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 50),NULL,NULL,false,true,true,($nb ? $nb : 8), 'position');
			
			/*$cache_products = range(8, 50);
            shuffle($cache_products);*/
	
			
		
		}

Ne pas oublier de vider le cache.

 

Dommage pour les fautes au titre ....

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

Bonjour,

 

 

La solution !

if (!isset(HomeFeatured::$cache_products))
		{
			
			
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 50),NULL,NULL,false,true,true,($nb ? $nb : 8), 'position');
			
			/*$cache_products = range(8, 50);
            shuffle($cache_products);*/
	
			
		
		}

Ne pas oublier de vider le cache.

 

Dommage pour les fautes au titre ....

Pour moi, ça marche pas... Je vide le cache, ca marche 1 fois et si j'actualise la page, ca marche plus. J'ai toujours les mêmes produits.

Link to comment
Share on other sites

C'est normal que ça marche q'une fois il faut vider le cache à chaque fois pour voir le changement.

Désactivé le cache dans le back office et cela va marcher à chaque fois. 

 

Merci !!!

C'est vrai qu'étant en local pour les modifs, j'avais oublié de le désactiver :blush:

Link to comment
Share on other sites

Bonjour,

 

Si j'ai bien comprit il faut remplacer la ligne :

			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');

par celle-ci :

			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 50),NULL,NULL,false,true,true,($nb ? $nb : 8), 'position');

Cela fonctionne mais pour être certain y'a rien d'autre à modifier/supprimer ?

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...