Jump to content

Prestashop 1.6.1 override products


Recommended Posts

Bonjour,

 

Je suis en train de migrer vers la version 1.6.1 de prestashop.

Je rencontre un soucis avec l'override admin de la classe products.

La méthode semble avoir changé. J'ai un peu de mal a trouver un exemple.

 

voici le code que j'avais fait, comment le rendre compatible avec cette nouvelle version ?

 

Je vous remercie d'avance pour votre aide.

<?php

class Product extends ProductCore {

    //==========================================================================
    // Surcharge xxx
    //==========================================================================

    public $b1_titre;

    public $b2_icon1;
    public $b2_texte1;
    public $b2_icon2;
    public $b2_texte2;
    public $b2_icon3;
    public $b2_texte3;

    public $b3_titre;
    public $b3_texte;
    public $b3_illustration;
    public $b3_video;

    public $b4_titre;
    public $b4_texte;
    public $b4_illustration;
    public $b4_video;

    public $b5_titre;
    public $b5_illustration;

    public $b6_titre;
    public $b6_illustration;
    public $b6_icon1;
    public $b6_texte1;
    public $b6_icon2;
    public $b6_texte2;
    public $b6_icon3;
    public $b6_texte3;
    public $b6_icon4;
    public $b6_texte4;

    public $b7_titre;
    public $b7_icon1;
    public $b7_titre1;
    public $b7_texte1;
    public $b7_icon2;
    public $b7_titre2;
    public $b7_texte2;
    public $b7_icon3;
    public $b7_titre3;
    public $b7_texte3;
    public $b7_icon4;
    public $b7_titre4;
    public $b7_texte4;

    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        Product::$definition['fields']['b1_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b2_icon1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b2_texte1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b2_icon2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b2_texte2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b2_icon3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b2_texte3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b3_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b3_texte'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b3_illustration'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b3_video'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b4_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b4_texte'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b4_illustration'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b4_video'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b5_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b5_illustration'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b6_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_illustration'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_icon1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_texte1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_icon2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_texte2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_icon3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_texte3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_icon4'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b6_texte4'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        Product::$definition['fields']['b7_titre'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_icon1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_titre1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_texte1'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_icon2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_titre2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_texte2'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_icon3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_titre3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_texte3'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_icon4'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_titre4'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
        Product::$definition['fields']['b7_texte4'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');

        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

    //==========================================================================

    public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
        $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
        $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,
        $use_customer_price = true)
    {
        if ($id_product == 0 && !empty($id_product_attribute)) {
            $quotation_product = new QuotationProduct((int)$id_product_attribute);

            if (!empty($quotation_product->id)) {
                if ($only_reduc) {
                    if ($usetax)
                        return ($quotation_product->final_price_with_tax - $quotation_product->final_price_with_tax_discount);
                    else
                        return ($quotation_product->final_price_without_tax - $quotation_product->final_price_without_tax_discount);
                }

                if ($usereduc) {
                    if ($usetax)
                        return $quotation_product->final_price_with_tax_discount;
                    else
                        return $quotation_product->final_price_without_tax_discount;
                }else {
                    if ($usetax)
                        return $quotation_product->final_price_with_tax;
                    else
                        return $quotation_product->final_price_without_tax;
                }
            }
        }
        return parent::getPriceStatic($id_product, $usetax, $id_product_attribute, $decimals, $divisor,
            $only_reduc, $usereduc, $quantity, $force_associated_tax, $id_customer, $id_cart,
            $id_address, $specific_price_output, $with_ecotax, $use_group_reduction, $context,
            $use_customer_price);
    }
}

?>
Edited by Tetardo (see edit history)
Link to comment
Share on other sites

Bonjour,

 

j'ai le message suivant en backoffice, les champs sont bien existants dans la db et ils sont remplis.

Si je vire b1_titre, il me fait une nouvel erreur sur la variable suivante.

Notice à la ligne 45 du fichier /home/www/dev2.dystri.com/cache/smarty/compile/69/6b/f4/696bf42930d4c84096a8dae7c14e362fa8dc1bc0.file.b1.tpl.php
[8] Undefined property: Product::$b1_titre

et celui ci sur la page produit dans le front:


Notice: Undefined property: Product::$b2_icon1 in /home/www/dev2.dystri.com/cache/smarty/compile/96/57/ac/9657ac5fd283f4f5d28337a321bf89943f6dda0f.file.product_b2.tpl.php on line 27

Notice: Undefined property: Product::$b3_titre in /home/www/dev2.dystri.com/cache/smarty/compile/09/06/4d/09064dc253bb7c5e98a2beb4e13fcebb6c0ade77.file.product_b3.tpl.php on line 27

Notice: Undefined property: Product::$b4_titre in /home/www/dev2.dystri.com/cache/smarty/compile/25/71/28/257128352a3b7fe6e8b6ecc43edcb5bdc19c9bd4.file.product_b4.tpl.php on line 27

Notice: Undefined property: Product::$b5_titre in /home/www/dev2.dystri.com/cache/smarty/compile/eb/86/d1/eb86d1b22592ffa8b463cead390dcba10c5c20ab.file.product_b5.tpl.php on line 27

il y a d'autres erreurs du même genre a la suite, je ne colle pas tout c'est inutile.

 

Je te remercie d'avance :)

Link to comment
Share on other sites

  • 2 weeks later...

Bonjour,

je viens de faire un override de la classe product pour ajouter un champ dans le BO et ca marche chez moi... version 1.6.1.0

 

voici mon product.php, j'ai egalement supprimé le class_index.php du dossier cache.

<?php
 
class Product extends ProductCore
{
    public $h1_prod;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
      Product::$definition['fields']['h1_prod'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString');
      parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
 
}
Edited by Alexandre-KM (see edit history)
Link to comment
Share on other sites

Pas de problème pour moi non plus suite à la migration.

 

seule différence, j'utilise self:: et non ClassName:: pour ajouter les champs depuis le constructeur.

 

bien évidemment supprimer le fichier class_index.php du répertoire cache.

 

Ch.

Link to comment
Share on other sites

si les overrides ne fonctionnent plus vérifiez dans le back office qu'ils ne soient pas désactivés

 

Alors là merci pour l'info je n'avais pas capté que la MAJ passait les override en desactivé ! :)

 

Tu viens de m'épargner du debug ! :=

  • Like 1
Link to comment
Share on other sites

Merci a tous pour vos réponses !

En fait, tout fonctionne, si vous avez toujours un soucis :

- activer les overrides dans le backoffice
- supprimer le fichier /cache/class_index.php (voir le fichier /override/readme_override.txt) 

Tout devrait rentrer dans l'ordre :)

 

Bonne journée à tous !

Link to comment
Share on other sites

Bonjour,

j'ai lu le tuto sur les bonnes pratiques de la classe Db mais j'ai pas eu d'exemple concret.

en fait j'aimerai introduire une clause WHERE dans ma requete update mais je ne sais pas comment m'y prendre. un exemple svp.

 

Je ne suis pas sûr que ce sujet soi le bon endroit pour poster ta question.

 

Néanmoins, pour ton update :

 

update($table, $data, $where = '', $limit = 0, $null_values = false, $use_cache = true, $add_prefix = true)

 

$table : le nom de la table

$data : un tableau PHP des valeurs avec le nom de champs en clé

$where : c'est quand meme explicite, tu mets ta clause where ici donc par exemple pour un update d'une commande ' id_order = 1 AND current_state = 2 '

 

C'est juste une clause where telle qu'écrite en SQL standard.

 

Voili voilou.

 

Edited by Stefan.K (see edit history)
Link to comment
Share on other sites

@Gregory Roussac, pour ma part c'est bon, tu peux clôturer, merci ^^

@K.M.R72, ta demande est bien sur les overrides, mais on parle de compatibilité sur ce post. Tu devrais ouvrir un nouveau post avec un sujet plus adapté, tu auras je pense plus de réponse :)

@Stefan.K, merci pour la réponse et je suis d'accord avec toi.

 

Bonne journée à tous :)

Edited by Tetardo (see edit history)
  • Like 1
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...