Jump to content
Beezkit

Produit sur la page d'accueil

Recommended Posts

Bonjour à tous,

 

J'aimerais afficher des produits sur ma page d'accueil mais sans passer par un module.

 

Est il possible d'obtenir la variable $products dans d'autre .tpl genre sur l'index.tpl ou autre ?

 

Cordialement.

Edited by Beezkit (see edit history)

Share this post


Link to post
Share on other sites

Est il possible d'obtenir la variable $products dans d'autre .tpl genre sur l'index.tpl ou autre ?

 

:blink:

 

Et elle contient quoi selon toi cette variable $products ?

Share this post


Link to post
Share on other sites

Bonjour,

 

Il faut créer un override de indexcontroller.php

 

Ensuite dans ce fichier, voici un exemple pour générer des produits selon un ID de catégorie :

class IndexController extends IndexControllerCore
{
	public function init()
	{
		parent::init();
		
		$id_category=2;

$this->home_category = new Category($id_category, $this->context->language->id);
$this->nbProducts = $this->home_category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
$this->cat_products = $this->home_category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);

$this->context->smarty->assign(array(
'HOOK_HOME' => Hook::exec('displayHome'),
'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent'),
'nb_products' => $this->nbProducts,
'products'=> $this->cat_products
));
	}
}

Bon courage

Edited by Christophe Boix (see edit history)

Share this post


Link to post
Share on other sites

si tu es sur la 1.7, il suffit de cocher "accueil" dans "Catégories associées" dans la page du produit (1er onglet : essentiel) et il apparaitra dans la page d'accueil

Share this post


Link to post
Share on other sites

Merci Christophe Boix, le controller me renvoi bien les produits, mais impossible d'assigner la variable $products sur l'index.tpl, il ne connais pas cette variable.

Share this post


Link to post
Share on other sites

J'ai trouvé, voici la correction du code :

$id_category=2;

      $this->home_category = new Category($id_category, $this->context->language->id);
      $this->nbProducts = $this->home_category->getProducts(null, null, null, $this->orderBy, $this->orderWay, true);
      $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
      $this->cat_products = $this->home_category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);

      $this->context->smarty->assign(array(
          'HOOK_HOME' => Hook::exec('displayHome'),
          'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
          'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent'),
          'nb_products' => $this->nbProducts,
          'products'=> $this->cat_products
      ));

Que je met dans initContent.

  • Like 1

Share this post


Link to post
Share on other sites
On 04/06/2017 at 7:11 PM, olishop said:

si tu es sur la 1.7, il suffit de cocher "accueil" dans "Catégories associées" dans la page du produit (1er onglet : essentiel) et il apparaitra dans la page d'accueil

le même pour la 1.6 (fiche produit  -> associations)

Share this post


Link to post
Share on other sites
Hello !

I try to display the data of a single product (selection by its id 32) on my homepage, i'm on PS 1.7.3.

I already managed to display the title and the short description via the FrontController:

Public static function getProductName ($ id) {
$ langID = Context :: getContext () -> language-> id;
$ product = new Product ($ id, false, $ langID);

echo ($ product-> name);
}

public static function getProductDescription ($ id) {
$ langID = Context :: getContext () -> language-> id;
$ product = new Product ($ id, false, $ langID);

echo ($ product-> description_short);
}

and calling the variables like that in my tpl:

{FrontController :: getProductName (32)}
{FrontController :: getProductDescription (32)}

It works, but I don't know how to display the image (cover) and features. Is it possible in the same way?

Thanks for help :)

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More