Prestashop 1.4 : Afficher le prix produit sans l’écotaxe

Ce tutoriel est compatible avec les versions de Prestashop suivantes :
1.4 +
Cet article est assez ancien, malgré toute l'attention que j' apporte à mes contenus il est possible que celui-ci ne soit plus d'actualité.
N'hésitez pas à me le signaler si nécessaire via le formulaire de contact.

Par défaut l’affichage du prix des produits sous Prestashop ( version 1.4 ) inclus l’écotaxe dans son montant.
Si pour différentes raison il vous est nécessaire de modifier cet affichage voici comment l’afficher sans l’écotaxe.

Pour commencer il est nécessaire de surcharger la classe Product dans le fichier override/classes/Product.php
Dans cette classe nous allons ajouter 2 fonctions qui vont récupérer les prix sans l’écotaxe.

<?php
 
/**
 * Surcharge de la classe produits
 *
 */
class Product extends ProductCore {
 
 
    /**
     * Reprise de la fonction getPrice mais en appellant la fonction getProductPriceStatic avec le paramètre ecotaxe à false
     *
     * @param boolean $tax With taxes or not (optional)
     * @param integer $id_product_attribute Product attribute id (optional)
     * @param integer $decimals Number of decimals (optional)
     * @param integer $divisor Util when paying many time without fees (optional)
     * @return float Product price in euros
     */
    public function getPriceWithoutEcotax($tax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1) {
        return Product::getPriceStatic((int) ($this->id), $tax, $id_product_attribute, $decimals, $divisor, $only_reduc, $usereduc, $quantity,false, NULL, NULL, NULL, $this ,false);
    }
    
    /**
     * Reprise de la fonction getPrice mais en appellant la fonction getProductPriceStatic avec le paramètre ecotaxe à false
     *
     * @param boolean $notax
     * @param intege $id_product_attribute
     * @return float Product price in euros
     */
    public function getPriceWithoutReductWithoutEcotax($notax = false, $id_product_attribute = false)
    {
        return Product::getPriceStatic((int)($this->id), !$notax, $id_product_attribute, 6, NULL, false, false,$quantity,false, NULL, NULL, NULL, $this ,false);
    }
 
}
 
?>

Une fois les nouvelles fonctions mises en place, il faut modifier le fichier product.tpl de votre thème et remplacer les lignes qui appellent les fonctions :

{if !$priceDisplay || $priceDisplay == 2}
     {assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, 2)}
     {assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}
{elseif $priceDisplay == 1}
    {assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, 2)}
    {assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL)}
{/if}

Par des appels aux nouvelles fonctions

{if !$priceDisplay || $priceDisplay == 2}
     {assign var='productPrice' value=$product->getPriceWithoutEcotax(true, $smarty.const.NULL, 2)}
     {assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReductWithoutEcotax(false, $smarty.const.NULL)}
{elseif $priceDisplay == 1}
      {assign var='productPrice' value=$product->getPriceWithoutEcotax(false, $smarty.const.NULL, 2)}
      {assign var='productPriceWithoutRedution' value=$product->getPriceWithoutReductWithoutEcotax(true, $smarty.const.NULL)}
{/if}

Une fois cette modification effectuée le prix sera bien affiché sans tenir compte de l’écotaxe

.Prix sans écotaxe

2 réflexions sur “Prestashop 1.4 : Afficher le prix produit sans l’écotaxe”

Répondre à herve Annuler la réponse

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *