Bonjour,

Je tente de créer un petit module me permettant d'ajouter un champ txt (url) sur le back office d'un produit. Ensuite s'il la variable de ce champ n'est pas vide sur la partie front je supprime le bouton "Ajouter au panier" ainsi que la quantité pour mettre un bouton "Voir le produit" qui renvoi sur l'url enregistré dans le back office.

J'ai fait ce code*
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
if (!defined('_PS_VERSION_')) {
    exit;
}
 
class CustomButton extends Module
{
    public function __construct()
    {
        $this->name = 'custombutton';
        $this->tab = 'front_office_features';
        $this->version = '1.0.0';
        $this->author = 'VotreNom';
        $this->need_instance = 0;
 
        parent::__construct();
 
        $this->displayName = $this->l('Bouton personnalisé');
        $this->description = $this->l('Ajoute un bouton personnalisé sur la page produit.');
 
        $this->controllers = array('admin');
 
        // Appels des hooks
        $this->registerHook('displayProductButtons');
        $this->registerHook('actionAdminControllerSetMedia');
        $this->registerHook('displayFooterProduct');
    }
 
    public function install()
    {
        if (!parent::install() ||
            !$this->registerHook('displayFooterProduct') ||
            !Db::getInstance()->execute('
                CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'product_custombutton` (
                    `id_product` INT(10) UNSIGNED NOT NULL,
                    `custom_button_text` VARCHAR(255) NOT NULL,
                    PRIMARY KEY (`id_product`)
                ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;
            ')
        ) {
            return false;
        }
 
        return true;
    }
 
    public function uninstall()
    {
        if (!parent::uninstall() ||
            !Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'product_custombutton`;')
        ) {
            return false;
        }
 
        return true;
    }
 
    // Hook pour afficher le champ personnalisé dans le back office
    public function hookDisplayProductButtons($params)
    {
        $id_product = (int)$params['product']['id_product'];
        $custom_button_text = Db::getInstance()->getValue('
            SELECT `custom_button_text`
            FROM `' . _DB_PREFIX_ . 'product_custombutton`
            WHERE `id_product` = ' . $id_product
        );
 
        $this->context->smarty->assign(array(
            'custom_button_text' => $custom_button_text,
            'id_product' => $id_product,
        ));
 
        return $this->display(__FILE__, 'views/templates/admin/custom_button_form.tpl');
    }
 
    // Hook pour ajouter les styles et scripts dans le back office
    public function hookActionAdminControllerSetMedia()
    {
        $this->context->controller->addCSS($this->_path . 'views/css/admin/custom_button.css');
    }
 
    // Hook pour afficher le bouton personnalisé dans le front office
    public function hookDisplayFooterProduct($params)
    {
        $id_product = (int)$params['product']['id_product'];
        $custom_button_text = Db::getInstance()->getValue('
            SELECT `custom_button_text`
            FROM `' . _DB_PREFIX_ . 'product_custombutton`
            WHERE `id_product` = ' . $id_product
        );
 
        if (!empty($custom_button_text)) {
            $this->context->smarty->assign(array(
                'custom_button_text' => $custom_button_text,
            ));
 
            return $this->display(__FILE__, 'views/templates/front/custom_button.tpl');
        }
 
        // Afficher le bouton "Ajouter au panier" par défaut
        return null;
    }
}
dans un fichier*custombutton.php et les templates correspondantes pour l'admin*views/templates/admin/custom_button_form.tpl avec*
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
{l s='Bouton personnalisé'}<br>
<input type="text" name="custom_button_text" value="{$custom_button_text}" class="fixed-width-lg">
mais rien ne s'affiche dans l'admin

j'ai vérifié les hooks sont bien attachés, la table a bien été créé, le module bien actif.

une idée ? j'ai fait une bétise mais je ne trouve pas..

Merci d'avance pour votre aide