Wstdhz Posted August 21, 2019 Share Posted August 21, 2019 Bonjour, J'aimerais assigner une variable SMARTY à l'onglet "Produits Phare" (module HomeFeatured natif 1.6) de ma page d'accueil afin de pouvoir appliquer une condition d'affichage sur product-list.tpl à cet onglet seulement. Quelqu'un saurait m'éclairer sur le processus? En vous remerciant 😀 Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 dans le php du module $this->smarty->assign (array('ma_variable' => $valeur_de_la_variable)); dans le tpl {$ma_variable} Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Bonjour Eolia, quelle valeur suis-je supposé renseigner? Merci. Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 ben je ne sais pas c'est vous qui avez une condition à mettre. ensuite un if dans le tpl: {if $ma_variable == 'pouet'} j'affiche ceci {else} j'affiche cela {/if} Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Le problème c'est que je ne trouve justement pas de variable associée au module HomeFeatured pour pouvoir faire un {if $HomeFeatured} <li class="col-lg-4">VOIR PLUS</li> {/if} dans product-list.tpl par exemple. Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 J'aimerais donc en assigner une au module mais je sèche sur la valeur? Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 (edited) ok, donc en fait vous voulez pouvoir utiliser une variable globale, c'est autre chose. Dans Classes/frontController.php vous pourriez ajouter votre variable lors de l'assignement 'homeFeatured' => Module::getInstanceByName('HomeFeatured')) && $module->active, et vous pourrez utiliser votre variable n'importe où sur votre site. Edited August 21, 2019 by Eolia (see edit history) Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Comme ceci? Syntax error. $this->smarty->assign (array('homeFeatured' => Module::getInstanceByName('HomeFeatured')) && $module->active; Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 il vous manque 2 )) à la fin^^ Et je n'ai pas écrit de cette façon, il est plus simple de l'ajouter dans la liste déjà existante des assignations: $this->context->smarty->assign(array( // Useful for layout.tpl 'mobile_device' => $this->context->getMobileDevice(), 'link' => $link, 'cart' => $cart, 'currency' => $currency, 'currencyRate' => (float)$currency->getConversationRate(), 'cookie' => $this->context->cookie, 'page_name' => $page_name, 'hide_left_column' => !$this->display_column_left, 'hide_right_column' => !$this->display_column_right, 'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__, 'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__, 'force_ssl' => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'), 'content_dir' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__, 'base_uri' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''), 'tpl_dir' => _PS_THEME_DIR_, 'tpl_uri' => _THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'lang_iso' => $this->context->language->iso_code, 'lang_id' => (int)$this->context->language->id, 'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code, 'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))), 'cart_qties' => (int)$cart->nbProducts(), 'currencies' => Currency::getCurrencies(), 'languages' => $languages, 'meta_language' => implode(',', $meta_language), 'priceDisplay' => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer), 'is_logged' => (bool)$this->context->customer->isLogged(), 'is_guest' => (bool)$this->context->customer->isGuest(), 'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'), 'use_taxes' => (int)Configuration::get('PS_TAX'), 'show_taxes' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')), 'display_tax_label' => (bool)$display_tax_label, 'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices), 'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE'), 'request' => $link->getPaginationLink(false, false, false, true), 'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'), 'quick_view' => (bool)Configuration::get('PS_QUICK_VIEW'), 'shop_phone' => Configuration::get('PS_SHOP_PHONE'), 'compared_products' => is_array($compared_products) ? $compared_products : array(), 'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'), 'currencySign' => $currency->sign, // backward compat, see global.tpl 'currencyFormat' => $currency->format, // backward compat 'currencyBlank' => $currency->blank, // backward compat 'homeFeatured' => (bool)Module::getInstanceByName('HomeFeatured')) && $module->active, // variable ajoutée )); Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 $this->context->smarty->assign(array( // Useful for layout.tpl 'mobile_device' => $this->context->getMobileDevice(), 'feature_special' => Module::getInstanceByName('HomeFeatured') && $module->active(), 'link' => $link, 'cart' => $cart, Voici donc mon assignation à controller.php Et la condition dans product-list.tpl : {if $feature_special} <li class="col-lg-4">VOIR PLUS DE PRODUITS</li> {/if} Plus d'erreur de syntaxe mais la <li> n'apparaît toujours pas. Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 {var_dump($feature_special)} affiche quoi dans le tpl ? Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 bool(false) Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 mettre homefeatured en minuscule, désolé, erreur de typo Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 J'ai déjà essayé, voici l'erreur : Notice: Undefined variable: module in /home/www/test/prestashop/classes/controller/FrontController.php on line 431 Fatal error: Uncaught Error: Call to a member function active() on null in /home/www/test/prestashop/classes/controller/FrontController.php:431 Stack trace: #0 /home/www/test/prestashop/override/classes/controller/FrontController.php(202): FrontControllerCore->init() #1 /home/www/test/prestashop/classes/controller/Controller.php(170): FrontController->init() #2 /home/www/test/prestashop/override/classes/Dispatcher.php(335): ControllerCore->run() #3 /home/www/test/prestashop/override/classes/Dispatcher.php(107): Dispatcher->dispatch_16() #4 /home/www/test/prestashop/index.php(28): Dispatcher->dispatch() #5 {main} thrown in /home/www/test/prestashop/classes/controller/FrontController.php on line 431 Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 (edited) On reprend, on a juste fait de la n'importe quoi là. Avant l'assign: if($module = Module::getInstanceByName('homefeatured') && $module->active) $feature_special = true; else $feature_special = false; et dans l'assign: 'feature_special' => $feature_special, Edited August 21, 2019 by Eolia (see edit history) Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 (edited) Voici donc le code : if ($module = Module::getInstanceByName('homefeatured') && $module->active) $feature_special = true; else $feature_special = false; $this->context->smarty->assign(array( // Useful for layout.tpl 'mobile_device' => $this->context->getMobileDevice(), 'feature_special' => $feature_special, 'link' => $link, {if $feature_special} <a href="test"><li class="col-lg-4">VOIR PLUS DE PRODUITS PHARES</li></a> {/if} Et l'erreur : Notice: Undefined variable: module in /home/www/pixloc/prestashop/classes/controller/FrontController.php on line 428 Notice: Trying to get property of non-object in /home/www/pixloc/prestashop/classes/controller/FrontController.php on line 428 Edited August 21, 2019 by Jesse (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 if (($module = Module::getInstanceByName('homefeatured')) && $module->active) Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Plus d'erreur mais la puce s'affiche sur tous les onglets et non seulement sur HomeFeature 🤔 Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 ben il faut mettre votre code dans le bon tpl aussi^^ Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 product-list.tpl Ça fonctionne pour l'onglet Nouveaux Produits. {if $new_products} <a href="test"><li class="col-lg-4">VOIR PLUS DE NOUVEAUTÉS</li></a> {/if} {if $feature_special} <a href="test"><li class="col-lg-4">VOIR PLUS DE PRODUITS PHARES</li></a> {/if} </ul> J'ai déjà essayé dans les tpl du module de produits phare mais ça n'affiche rien même sans condition SMARTY. Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 Vous avez des produits phares ? Parce que s'il n'y en a pas il y a une condition plus haut dans le tpl Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Oui les produits sont en place dans l'onglet. J'aimerais juste rajouter un encadré pour que le visiteur puisse voir le reste de la sélection en accédant à la catégorie dédiée Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 Punaise... Où comment se prendre la tête... Supprimez tout et ajoutez en bas de votre product-list.tpl: {if isset($id) && $id == 'homefeatured'} <li class="ajax_block_product col-xs-12 col-sm-12 col-md-12 col-lg-12"> <a href="VOTRE LIEN" title="{l s='Voir tous les produits' mod='homefeatured'}" class="home-btn btn btn-std3 col-lg-12">{l s='Voir tous les produits' mod='homefeatured'}</a> </li> {/if} Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Ça fonctionne! Merci Eolia, tu m'enlèves une belle épine du pied Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 Expliquer clairement son besoin dès le 1er post nous aurait fait gagner du temps plutôt que d'attendre le 13ème^^ Link to comment Share on other sites More sharing options...
Wstdhz Posted August 21, 2019 Author Share Posted August 21, 2019 Je pensais qu'il s'agissait de voie vers la solution. On peut appeler n'importe quel module avec $id comme tu l'as fais? {if isset($id) && $id == 'homefeatured'} Link to comment Share on other sites More sharing options...
Eolia Posted August 21, 2019 Share Posted August 21, 2019 le product-list.tpl est appelé par différents élements: modules, pages catégories, fabricants, promotions etc. L'$id est envoyé à ce tpl pour servir d'id html pour cet affichage dans le cas de son utilisation par des modules mais ce n'est pas obligé, d'où le if isset() Pour la home, oui ca fonctionne: 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