Beezkit Posted June 1, 2017 Share Posted June 1, 2017 (edited) 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 June 1, 2017 by Beezkit (see edit history) Link to comment Share on other sites More sharing options...
BeComWeb Posted June 2, 2017 Share Posted June 2, 2017 Est il possible d'obtenir la variable $products dans d'autre .tpl genre sur l'index.tpl ou autre ? Et elle contient quoi selon toi cette variable $products ? Link to comment Share on other sites More sharing options...
Christophe Boix Posted June 3, 2017 Share Posted June 3, 2017 (edited) 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 June 6, 2017 by Christophe Boix (see edit history) Link to comment Share on other sites More sharing options...
olishop Posted June 4, 2017 Share Posted June 4, 2017 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 Link to comment Share on other sites More sharing options...
Beezkit Posted June 6, 2017 Author Share Posted June 6, 2017 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. Link to comment Share on other sites More sharing options...
Beezkit Posted June 6, 2017 Author Share Posted June 6, 2017 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. 1 Link to comment Share on other sites More sharing options...
Pedro Pinto Posted February 12, 2018 Share Posted February 12, 2018 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) Link to comment Share on other sites More sharing options...
Natanaël Posted June 25, 2018 Share Posted June 25, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now