Jump to content

Produit sur la page d'accueil


Recommended Posts

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)
Link to comment
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
Link to comment
Share on other sites

  • 8 months later...
  • 4 months later...
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 :)
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...