gngngngn Posted May 2 Posted May 2 (edited) Bonjour, Tous les champs de ma surcharge fonctionne, mais je n'arrive pas à voir pourquoi les checkboxes, elles ne s'affichent pas : public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) { //Définition des nouveaux champs self::$definition['fields']['custom_field'] = array( 'type' => 'checkbox', 'label' => 'Options', 'desc' => 'description checkboxes', 'name' => 'options', 'values' => [ 'query' => [ [ 'id_checkbox_options' => 0, 'checkbox_options_name' => 'Option 0' ], [ 'id_checkbox_options' => 1, 'checkbox_options_name' => 'Option 1' ], [ 'checkbox_options_options' => 2, 'checkbox_options_name' => 'Option 2' ], [ 'checkbox_options_options' => 3, 'checkbox_options_name' => 'Option 3' ], [ 'id_checkbox_options' => 4, 'checkbox_options_name' => 'option 4' ] ], 'id' => 'id_checkbox_options', 'name' => 'checkbox_options_name', ], ); self::$definition['fields']['custom_field_lang'] = [ 'type' => self::TYPE_STRING, 'lang' => true, 'required' => false, 'size' => 255 ]; self::$definition['fields']['custom_field_lang_wysiwyg'] = [ 'type' => self::TYPE_HTML, 'lang' => true, 'required' => false, 'validate' => 'isCleanHtml' ]; self::$definition['fields']['custom_field_file'] = [ 'type' => self::TYPE_STRING, 'lang' => false, 'required' => false, 'validate' => 'isCleanHtml' ]; parent::__construct($id_product, $full, $id_lang, $id_shop, $context); } Dans mon TPL : {if $custom_field} TEST {/if} Une âme charitable pourrait m'indiquer mon erreur svp? Merci ! Edited May 2 by gngngngn (see edit history) Share this post Link to post Share on other sites More sharing options...
Prestachamps Posted May 2 Posted May 2 (edited) Bonjour, Dans la définition, vous pouvez définir uniquement les champs personnalisés et les valeurs que vous pouvez ajouter comme suit dans le constructeur après la définition : J'ai testé et ça marche : $this->custom_field = array( 'query' => [ [ 'id_checkbox_options' => 0, 'checkbox_options_name' => 'Option 0' ], [ 'id_checkbox_options' => 1, 'checkbox_options_name' => 'Option 1' ], [ 'checkbox_options_options' => 2, 'checkbox_options_name' => 'Option 2' ], [ 'checkbox_options_options' => 3, 'checkbox_options_name' => 'Option 3' ], [ 'id_checkbox_options' => 4, 'checkbox_options_name' => 'option 4' ] ], 'id' => 'id_checkbox_options', 'name' => 'checkbox_options_name', ); Vous pouvez accéder au champ personnalisé dans le TPL comme suit : {$product.custom_field|dump} Veuillez regarder la capture d'écran : https://prnt.sc/izmccShjK3t1 J'espère que j'ai pu aider Cordialement, Leo Edited May 2 by Prestachamps (see edit history) Share this post Link to post Share on other sites More sharing options...
gngngngn Posted May 2 Posted May 2 (edited) Merci beaucoup @Prestachamps 💪, néanmoins j'ai probablement omis un détail : Je suis dans le Controller : ProductController :: formAction; Route : admin_product_form (je n'arrive pas à écrire l'html pour que les checkbox soit enregistrée lors du clique sur enregistrer) Le but de la checkbox est d'être enregistrée sur une nouvelle colonne de la table ps_product, ça vous parle? Cordialement, Cyrille Edited May 2 by gngngngn (see edit history) Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 2 Posted May 2 Une piste peut être https://www.h-hennes.fr/blog/2017/10/19/prestashop-1-7-ajouter-des-champs-produit/ Share this post Link to post Share on other sites More sharing options...
gngngngn Posted May 2 Posted May 2 (edited) @Merci @Mediacom87, Je suis bien parti de là, mais il n'y a aucune piste pour les checkboxes, et c'est uniquement ce dont j'ai besoin. Je ne vois personne en parler, je suis le seul à vouloir mettre des checkbox sur le product admin? Cordialement, Cyrille Edited May 2 by gngngngn (see edit history) Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 2 Posted May 2 option name doit, à mon avis être toujours pareil pour un groupe d'option et tu récupère les valeurs de ces options. 1 Share this post Link to post Share on other sites More sharing options...
gngngngn Posted May 2 Posted May 2 (edited) Merci beaucoup @Mediacom87, J'ai donc procédé comme suit. Le formulaire indique que les réglages ont bien étés mis à jours mais aucune modification n'apparait dans la base de donnée. {foreach from=$guides item=guide} <div class="row"> <fieldset class="form-group mb-0"> <label class="form-control-label"><input type="checkbox" value="{$guide.id_cms}" name="options"> {$guide.original_title }</label> </fieldset> </div> {/foreach} {/if} EDIT : Donc ça avance, mais il ne m'enregistre qu'un seul résultat, une piste pour enregistrer un tableau des résultats? Je pourrais avec serialize(), mais j'imagine que Symfony doit gérer ça directement : extrafields.tpl {foreach from=$guides item=guide} <div class="row"> <fieldset class="form-group mb-0"> <label class="form-control-label"><input type="checkbox" value="{$guide.id_cms}" name="custom_field[]"> {$guide.original_title }</label> </fieldset> </div> {/foreach} {/if} Product.php (override de ProductCore) self::$definition['fields']['custom_field'] = array( 'type' => 'checkbox', 'label' => 'Options', 'desc' => 'description checkboxes', 'name' => 'custom_field', Il me prend bien le tableau lors du POST : Cordialement, Cyrille Edited May 2 by gngngngn (see edit history) Share this post Link to post Share on other sites More sharing options...
gngngngn Posted May 7 Posted May 7 @Mediacom87, je crois que je viens de vous acheter un livre sur Rakuten Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 8 Posted May 8 Il y a 17 heures, gngngngn a dit : @Mediacom87, je crois que je viens de vous acheter un livre sur Rakuten j'ai laissé un indice très précis 🙂 Share this post Link to post 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