Que vous soyez marchand, intégrateur ou développeur sous PrestaShop, vous avez peu être vu évolué le CMS e-commerce et vous avez forcément déjà dû créer des conditions d’affichage par exemple. Voyons comment créer des conditions avec les variables PrestaShop 1.7.
Variables Smarty de PrestaShop 1.7
Pour créer des conditions sous PrestaShop, il faut d’abord coder avec les variables smarty qu’on retrouve dans les fichiers d’apparence au format .tpl dans chaque thème PrestaShop.
Je vous parlais déjà des variables smarty utilisées dans les anciennes versions de PrestaShop mais ces variables ne sont plus fonctionnelles dans PrestaShop 1.7. Changement ou nouveauté : peu importe. Il faut se familiariser avec ces outils très utiles pour votre boutique.
Pour afficher les variables smarty avec PrestaShop, c’est comme avant : vous tapez {debug} dans le fichier .tpl souhaité. Par exemple, à la fin du fichier www/themes/classic/templates/_partials/head.tpl :
Pensez bien dans l’admin > paramètres avancés > performances, à forcer la compilation et à désactiver le cache !
Vous obtenez alors après rechargement de la page une popup qui s’ouvre avec la liste complète des variables smarty utilisées dans PrestaShop 1.7 : c’est la console de debug Smarty de PrestaShop. Avez ça vous êtes « presque » le roi de PrestaShop ahah ^^
Ce qui nous intéresse, c’est donc ces fameuses variables dont voici la liste complète pas interprétée car les noms sont évocateurs :
| $HOOK_HEADER | Smarty_Variable Object (3) ->value = « » ->nocache = false ->scope = « file:_partials/head.tpl » |
|---|---|
| $HOOK_HOME | Smarty_Variable Object (3) ->value = » <div id= »carousel » data-ride= »caro… » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $SCRIPT_NAME | Smarty_Variable Object (3) ->value = « /prestashop1720/index.php » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $breadcrumb | Smarty_Variable Object (3) ->value = Array (2) links => Array (1) 0 => Array (2) title => « Accueil » url => « http://localhost/prestashop1720/ » count => 1 ->nocache = false ->scope = « file:_partials/head.tpl » |
| $cart | Smarty_Variable Object (3) ->value = Array (13) products => Array (0) totals => Array (3) total => Array (4) type => « total » label => « Total » amount => 0 value => « 0,00 € » total_including_tax => Array (4) type => « total » label => « Total (tax incl.) » amount => 0 value => « 0,00 € » total_excluding_tax => Array (4) type => « total » label => « Total (tax excl.) » amount => 0 value => « 0,00 € » subtotals => Array (4) products => Array (4) type => « products » label => « Sous-total » amount => 0 value => « 0,00 € » discounts => null shipping => Array (4) type => « shipping » label => « Livraison » amount => 0 value => « gratuit » tax => null products_count => 0 summary_string => « 0 articles » labels => Array (2) tax_short => « (TTC) » tax_long => « (TTC) » id_address_delivery => 0 id_address_invoice => 0 is_virtual => false vouchers => Array (2) allowed => 0 added => Array (0) discounts => Array (0) minimalPurchase => 0 minimalPurchaseRequired => « » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $configuration | Smarty_Variable Object (3) ->value = Array (10) display_taxes_label => true low_quantity_threshold => 3 is_b2b => false is_catalog => false show_prices => true opt_in => Array (1) partner => true quantity_discount => Array (2) type => « discount » label => « Réduction » voucher_enabled => 0 return_enabled => 0 number_of_days_for_return => 14 ->nocache = false ->scope = « file:_partials/head.tpl » |
| $currency | Smarty_Variable Object (3) ->value = Array (4) name => « euro » iso_code => « EUR » iso_code_num => « 978 » sign => « € » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $customer | Smarty_Variable Object (3) ->value = Array (29) lastname => null firstname => null email => null last_passwd_gen => null birthday => null newsletter => null newsletter_date_add => null ip_registration_newsletter => null optin => null website => null company => null siret => null ape => null outstanding_allow_amount => 0 max_payment_days => 0 note => null is_guest => 0 id_shop => null id_shop_group => null id_default_group => 1 date_add => null date_upd => null reset_password_token => null reset_password_validity => null id => null is_logged => false gender => Array (3) type => null name => null id => null risk => Array (4) name => null color => null percent => null id => null addresses => Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $field_required | Smarty_Variable Object (3) ->value = Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $javascript | Smarty_Variable Object (3) ->value = Array (2) head => Array (2) external => Array (0) inline => Array (0) bottom => Array (2) external => Array (8) corejs => Array (7) id => « corejs » type => « external » path => « /prestashop1720/themes/core.js » uri => « http://localhost/prestashop1720/theme… » priority => 0 attribute => « » server => « local » theme-main => Array (7) id => « theme-main » type => « external » path => « /prestashop1720/themes/classic/assets… » uri => « http://localhost/prestashop1720/theme… » priority => 50 attribute => « » server => « local » jquery-ui => Array (7) id => « jquery-ui » type => « external » path => « /prestashop1720/js/jquery/ui/jquery-u… » uri => « http://localhost/prestashop1720/js/jq… » priority => 90 attribute => « » server => « local » modules-responsiveslides => Array (7) id => « modules-responsiveslides » type => « external » path => « /prestashop1720/modules/ps_imageslide… » uri => « http://localhost/prestashop1720/modul… » priority => 150 attribute => « » server => « local » modules-homeslider => Array (7) id => « modules-homeslider » type => « external » path => « /prestashop1720/modules/ps_imageslide… » uri => « http://localhost/prestashop1720/modul… » priority => 150 attribute => « » server => « local » modules-searchbar => Array (7) id => « modules-searchbar » type => « external » path => « /prestashop1720/modules/ps_searchbar/… » uri => « http://localhost/prestashop1720/modul… » priority => 150 attribute => « » server => « local » modules-shoppingcart => Array (7) id => « modules-shoppingcart » type => « external » path => « /prestashop1720/modules/ps_shoppingca… » uri => « http://localhost/prestashop1720/modul… » priority => 150 attribute => « » server => « local » theme-custom => Array (7) id => « theme-custom » type => « external » path => « /prestashop1720/themes/classic/assets… » uri => « http://localhost/prestashop1720/theme… » priority => 1000 attribute => « » server => « local » inline => Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $js_custom_vars | Smarty_Variable Object (3) ->value = Array (1) prestashop => Array (14) cart => Array (13) products => Array (0) totals => Array (3) total => Array (4) type => « total » label => « Total » amount => 0 value => « 0,00 € » total_including_tax => Array (4) type => « total » label => « Total (tax incl.) » amount => 0 value => « 0,00 € » total_excluding_tax => Array (4) type => « total » label => « Total (tax excl.) » amount => 0 value => « 0,00 € » subtotals => Array (4) products => Array (4) type => « products » label => « Sous-total » amount => 0 value => « 0,00 € » discounts => null shipping => Array (4) type => « shipping » label => « Livraison » amount => 0 value => « gratuit » tax => null products_count => 0 summary_string => « 0 articles » labels => Array (2) tax_short => « (TTC) » tax_long => « (TTC) » id_address_delivery => 0 id_address_invoice => 0 is_virtual => false vouchers => Array (2) allowed => 0 added => Array (0) discounts => Array (0) minimalPurchase => 0 minimalPurchaseRequired => « » currency => Array (4) name => « euro » iso_code => « EUR » iso_code_num => « 978 » sign => « € » customer => Array (29) lastname => null firstname => null email => null last_passwd_gen => null birthday => null newsletter => null newsletter_date_add => null ip_registration_newsletter => null optin => null website => null company => null siret => null ape => null outstanding_allow_amount => 0 max_payment_days => 0 note => null is_guest => 0 id_shop => null id_shop_group => null id_default_group => 1 date_add => null date_upd => null reset_password_token => null reset_password_validity => null id => null is_logged => false gender => Array (3) type => null name => null id => null risk => Array (4) name => null color => null percent => null id => null addresses => Array (0) language => Array (8) name => « Français (French) » iso_code => « fr » locale => « fr-FR » language_code => « fr » is_rtl => « 0 » date_format_lite => « d/m/Y » date_format_full => « d/m/Y H:i:s » id => 1 page => Array (6) title => « » canonical => null meta => Array (4) title => « PrestaShop1720 » description => « Boutique propulsée par PrestaShop » keywords => « » robots => « index » page_name => « index » body_classes => Array (7) lang-fr => true lang-rtl => false country-FR => true currency-EUR => true layout-full-width => true page-index => true tax-display-enabled => true admin_notifications => Array (0) shop => Array (12) name => « PrestaShop1720 » email => « test@test.fr » registration_number => false long => false lat => false logo => « /prestashop1720/img/logo.png » stores_icon => « /prestashop1720/img/logo_stores.png » favicon => « /prestashop1720/img/favicon.ico » favicon_update_time => « 1324977642 » address => Array (7) formatted => « PrestaShop1720<br>France » address1 => false address2 => false postcode => false city => false state => null country => « France » phone => false fax => false urls => Array (19) base_url => « http://localhost/prestashop1720/ » current_url => « http://localhost/prestashop1720/ » shop_domain_url => « http://localhost » img_ps_url => « http://localhost/prestashop1720/img/ » img_cat_url => « http://localhost/prestashop1720/img/c/ » img_lang_url => « http://localhost/prestashop1720/img/l/ » img_prod_url => « http://localhost/prestashop1720/img/p/ » img_manu_url => « http://localhost/prestashop1720/img/m/ » img_sup_url => « http://localhost/prestashop1720/img/su/ » img_ship_url => « http://localhost/prestashop1720/img/s/ » img_store_url => « http://localhost/prestashop1720/img/st/ » img_col_url => « http://localhost/prestashop1720/img/co/ » img_url => « http://localhost/prestashop1720/theme… » css_url => « http://localhost/prestashop1720/theme… » js_url => « http://localhost/prestashop1720/theme… » pic_url => « http://localhost/prestashop1720/upload/ » pages => Array (32) address => « http://localhost/prestashop1720/adresse » addresses => « http://localhost/prestashop1720/adresses » authentication => « http://localhost/prestashop1720/conne… » cart => « http://localhost/prestashop1720/panier » category => « http://localhost/prestashop1720/index… » cms => « http://localhost/prestashop1720/index… » contact => « http://localhost/prestashop1720/nous-… » discount => « http://localhost/prestashop1720/reduc… » guest_tracking => « http://localhost/prestashop1720/suivi… » history => « http://localhost/prestashop1720/histo… » identity => « http://localhost/prestashop1720/identite » index => « http://localhost/prestashop1720/ » my_account => « http://localhost/prestashop1720/mon-c… » order_confirmation => « http://localhost/prestashop1720/confi… » order_detail => « http://localhost/prestashop1720/index… » order_follow => « http://localhost/prestashop1720/suivi… » order => « http://localhost/prestashop1720/commande » order_return => « http://localhost/prestashop1720/index… » order_slip => « http://localhost/prestashop1720/avoirs » pagenotfound => « http://localhost/prestashop1720/page-… » password => « http://localhost/prestashop1720/recup… » pdf_invoice => « http://localhost/prestashop1720/index… » pdf_order_return => « http://localhost/prestashop1720/index… » pdf_order_slip => « http://localhost/prestashop1720/index… » prices_drop => « http://localhost/prestashop1720/promo… » product => « http://localhost/prestashop1720/index… » search => « http://localhost/prestashop1720/reche… » sitemap => « http://localhost/prestashop1720/plan-… » stores => « http://localhost/prestashop1720/magasins » supplier => « http://localhost/prestashop1720/fourn… » register => « http://localhost/prestashop1720/conne… » order_login => « http://localhost/prestashop1720/comma… » theme_assets => « /prestashop1720/themes/classic/assets/ » actions => Array (1) logout => « http://localhost/prestashop1720/?mylo… » configuration => Array (10) display_taxes_label => true low_quantity_threshold => 3 is_b2b => false is_catalog => false show_prices => true opt_in => Array (1) partner => true quantity_discount => Array (2) type => « discount » label => « Réduction » voucher_enabled => 0 return_enabled => 0 number_of_days_for_return => 14 field_required => Array (0) breadcrumb => Array (2) links => Array (1) 0 => Array (2) title => « Accueil » url => « http://localhost/prestashop1720/ » count => 1 link => Link Object (2) ->protocol_link = « http:// » ->protocol_content = « http:// » time => 1501764642 static_token => « f124b7c777e7915df5dfa373aa4def96 » token => « 268c1f40e17417fcdd4a7331ba375bea » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $language | Smarty_Variable Object (3) ->value = Array (8) name => « Français (French) » iso_code => « fr » locale => « fr-FR » language_code => « fr » is_rtl => « 0 » date_format_lite => « d/m/Y » date_format_full => « d/m/Y H:i:s » id => 1 ->nocache = false ->scope = « file:_partials/head.tpl » |
| $layout | Smarty_Variable Object (3) ->value = « layouts/layout-full-width.tpl » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $link | Smarty_Variable Object (3) ->value = Link Object (2) ->protocol_link = « http:// » ->protocol_content = « http:// » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $notifications | Smarty_Variable Object (3) ->value = Array (4) error => Array (0) warning => Array (0) success => Array (0) info => Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $page | Smarty_Variable Object (3) ->value = Array (6) title => « » canonical => null meta => Array (4) title => « PrestaShop1720 » description => « Boutique propulsée par PrestaShop » keywords => « » robots => « index » page_name => « index » body_classes => Array (7) lang-fr => true lang-rtl => false country-FR => true currency-EUR => true layout-full-width => true page-index => true tax-display-enabled => true admin_notifications => Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $request_uri | Smarty_Variable Object (3) ->value = « /prestashop1720/ » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $shop | Smarty_Variable Object (3) ->value = Array (12) name => « PrestaShop1720 » email => « test@test.fr » registration_number => false long => false lat => false logo => « /prestashop1720/img/logo.png » stores_icon => « /prestashop1720/img/logo_stores.png » favicon => « /prestashop1720/img/favicon.ico » favicon_update_time => « 1324977642 » address => Array (7) formatted => « PrestaShop1720<br>France » address1 => false address2 => false postcode => false city => false state => null country => « France » phone => false fax => false ->nocache = false ->scope = « file:_partials/head.tpl » |
| $smarty | Smarty_Variable Object (3) ->value = null ->nocache = false ->scope = « file:_partials/head.tpl » |
| $static_token | Smarty_Variable Object (3) ->value = « f124b7c777e7915df5dfa373aa4def96 » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $stylesheets | Smarty_Variable Object (3) ->value = Array (2) external => Array (5) theme-main => Array (7) id => « theme-main » type => « external » path => « /prestashop1720/themes/classic/assets… » uri => « http://localhost/prestashop1720/theme… » media => « all » priority => 50 server => « local » jquery-ui => Array (7) id => « jquery-ui » type => « external » path => « /prestashop1720/js/jquery/ui/themes/b… » uri => « http://localhost/prestashop1720/js/jq… » media => « all » priority => 90 server => « local » jquery-ui-theme => Array (7) id => « jquery-ui-theme » type => « external » path => « /prestashop1720/js/jquery/ui/themes/b… » uri => « http://localhost/prestashop1720/js/jq… » media => « all » priority => 95 server => « local » modules-homeslider => Array (7) id => « modules-homeslider » type => « external » path => « /prestashop1720/modules/ps_imageslide… » uri => « http://localhost/prestashop1720/modul… » media => « all » priority => 150 server => « local » theme-custom => Array (7) id => « theme-custom » type => « external » path => « /prestashop1720/themes/classic/assets… » uri => « http://localhost/prestashop1720/theme… » media => « all » priority => 1000 server => « local » inline => Array (0) ->nocache = false ->scope = « file:_partials/head.tpl » |
| $time | Smarty_Variable Object (3) ->value = 1501764642 ->nocache = false ->scope = « file:_partials/head.tpl » |
| $token | Smarty_Variable Object (3) ->value = « 268c1f40e17417fcdd4a7331ba375bea » ->nocache = false ->scope = « file:_partials/head.tpl » |
| $urls | Smarty_Variable Object (3) ->value = Array (19) base_url => « http://localhost/prestashop1720/ » current_url => « http://localhost/prestashop1720/ » shop_domain_url => « http://localhost » img_ps_url => « http://localhost/prestashop1720/img/ » img_cat_url => « http://localhost/prestashop1720/img/c/ » img_lang_url => « http://localhost/prestashop1720/img/l/ » img_prod_url => « http://localhost/prestashop1720/img/p/ » img_manu_url => « http://localhost/prestashop1720/img/m/ » img_sup_url => « http://localhost/prestashop1720/img/su/ » img_ship_url => « http://localhost/prestashop1720/img/s/ » img_store_url => « http://localhost/prestashop1720/img/st/ » img_col_url => « http://localhost/prestashop1720/img/co/ » img_url => « http://localhost/prestashop1720/theme… » css_url => « http://localhost/prestashop1720/theme… » js_url => « http://localhost/prestashop1720/theme… » pic_url => « http://localhost/prestashop1720/upload/ » pages => Array (32) address => « http://localhost/prestashop1720/adresse » addresses => « http://localhost/prestashop1720/adresses » authentication => « http://localhost/prestashop1720/conne… » cart => « http://localhost/prestashop1720/panier » category => « http://localhost/prestashop1720/index… » cms => « http://localhost/prestashop1720/index… » contact => « http://localhost/prestashop1720/nous-… » discount => « http://localhost/prestashop1720/reduc… » guest_tracking => « http://localhost/prestashop1720/suivi… » history => « http://localhost/prestashop1720/histo… » identity => « http://localhost/prestashop1720/identite » index => « http://localhost/prestashop1720/ » my_account => « http://localhost/prestashop1720/mon-c… » order_confirmation => « http://localhost/prestashop1720/confi… » order_detail => « http://localhost/prestashop1720/index… » order_follow => « http://localhost/prestashop1720/suivi… » order => « http://localhost/prestashop1720/commande » order_return => « http://localhost/prestashop1720/index… » order_slip => « http://localhost/prestashop1720/avoirs » pagenotfound => « http://localhost/prestashop1720/page-… » password => « http://localhost/prestashop1720/recup… » pdf_invoice => « http://localhost/prestashop1720/index… » pdf_order_return => « http://localhost/prestashop1720/index… » pdf_order_slip => « http://localhost/prestashop1720/index… » prices_drop => « http://localhost/prestashop1720/promo… » product => « http://localhost/prestashop1720/index… » search => « http://localhost/prestashop1720/reche… » sitemap => « http://localhost/prestashop1720/plan-… » stores => « http://localhost/prestashop1720/magasins » supplier => « http://localhost/prestashop1720/fourn… » register => « http://localhost/prestashop1720/conne… » order_login => « http://localhost/prestashop1720/comma… » theme_assets => « /prestashop1720/themes/classic/assets/ » actions => Array (1) logout => « http://localhost/prestashop1720/?mylo… » ->nocache = false ->scope = « file:_partials/head.tpl » |
Créer des conditions avec PrestaShop 1.7
Une fois qu’on a vu comment récupérer les variables de PrestaShop, on a vu le plus gros finalement. Le reste est identique aux versions précédentes de PrestaShop à savoir pour quelques exemples :
Afficher un élément si le client connecté :
Afficher un élément si le client n’est pas connecté (notez le point d’exclamation avant la variable) :
Afficher un élément si c’est la page d’accueil :
Afficher le franco de port si le montant du panier est supérieur à 39.62 euros (le test n’est pas affiché en ajax mais pratique pour l’afficher sur la fiche produit) :
Afficher le montant du panier (ok c’est pas une condition mais peu être pratique) :
Afficher un message personnalisé à votre client si il est connecté :
Afficher un message si la langue du site est le français :
La dernière condition est un bonus car peu être très pratique et surtout génératrice de chiffre f’affaires en offrant à vos clients une landing page personnalisée en fonction de l’url appelée (dans mon cas, j’ai indiqué que les utilisateurs appelant l’url avec le paramètre « twitter » ont accès à un message dédié, il faut alors personnaliser votre newsletter en fonction par exemple) :
Vous venez de découvrir comment afficher les variables PrestaShop 1.7, comment créer des conditions d’affichage avec PrestaShop 1.7 et surtout comment générer plus de ventes en utilisant de manière efficace les conditions.
