kerlin Posted November 8, 2019 Share Posted November 8, 2019 Bonjour, Je dois, pour la première fois, créer un module de toutes pièces pour un PS 1.7.5.2. Ce module doit permettre à l'admin d'ajouter des données dans le BO clients, données qui seront ensuite affichées sur une page accessible via un nouveau bouton sur le compte client en front. Avec l'aide des tutos comme celui-ci : https://www.h-hennes.fr/blog/2017/10/10/prestashop-1-7-ajouter-des-champs-clients/ j'ai réussi à créer l'ébauche du module : il s'installe, crée une nouvelle table avec de nouveaux champs, champs qui sont bien affichés dans l'édition du compte client en admin. Mais quand on entre des données dans les champs, elles ne sont pas enregistrées dans la bdd. Le principe devrait un peu fonctionner comme l'ajout d'adresses sur la fiche d'un client en admin : un form qu'on remplit, les données sont enregistrées et affichées dans un tableau visible pour l'admin en bo, et par le client en front sur son compte. Quelqu'un aurait-il déjà réalisé cela et pourrait-il m'indiquer des pistes ? Merci d'avance PS voici le code actuel du php du module <?php /** * 2007-2019 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2019 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) { exit; } class Programcustomer extends Module { protected $config_form = false; public function __construct() { $this->name = 'programcustomer'; $this->tab = 'administration'; $this->version = '1.0.1'; $this->author = 'CdS'; $this->need_instance = 0; /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = false; parent::__construct(); $this->displayName = $this->l('Program Editions 7 Customers Commission'); $this->description = $this->l('Add commissions table on customer account for Program Eidtions7'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module ?'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); } /** * Don't forget to create update methods if needed: * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update */ public function install() { Configuration::updateValue('PROGRAMCUSTOMER_LIVE_MODE', false); include(dirname(__FILE__).'/sql/install.php'); return parent::install() && $this->registerHook('header') && $this->registerHook('backOfficeHeader') && $this->registerHook('actionObjectCustomerAddAfter') && $this->registerHook('validateCustomerFormFields') && $this->registerHook('actionCustomerAccountUpdate') && $this->registerHook('displayAdminCustomers') && $this->registerHook('displayAdminCustomersForm') && $this->registerHook('actionAdminCustomersControllerSaveAfter') && $this->registerHook('actionAdminCustomersFormModifier') && $this->registerHook('additionalCustomerFormFields') && $this->registerHook('displayCustomerAccount'); } public function uninstall() { Configuration::deleteByName('PROGRAMCUSTOMER_LIVE_MODE'); include(dirname(__FILE__).'/sql/uninstall.php'); return parent::uninstall(); } /** * Add the CSS & JavaScript files you want to be loaded in the BO. */ public function hookBackOfficeHeader() { if (Tools::getValue('module_name') == $this->name) { $this->context->controller->addJS($this->_path.'views/js/back.js'); $this->context->controller->addCSS($this->_path.'views/css/back.css'); } } /** * Add the CSS & JavaScript files you want to be added on the FO. */ public function hookHeader() { $this->context->controller->addJS($this->_path.'/views/js/front.js'); $this->context->controller->addCSS($this->_path.'/views/css/front.css'); } //ajout champs dans compte client BO public function hookactionAdminCustomersFormModifier($params) { //Création d'un nouveau fieldset $params['fields'][$this->name] = array( 'form' => array( 'legend' => array( 'title' => $this->l('Commissions paid table with Program editions7'), 'icon' => 'icon-tags', ), 'description' => $this->l('Add paid commissions with book title, date payment and commission amount following the source.'), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Book Title'), 'name' => $this->name.'_titlebook', ), array( 'type' => 'date', 'label' => $this->l('Date payment'), 'name' => $this->name.'_datecomm', ), array( 'type' => 'text', 'label' => $this->l('Printed by Editions7'), 'name' => $this->name.'_commbroched', ), array( 'type' => 'text', 'label' => $this->l('Printed by Others'), 'name' => $this->name.'_commbrochoth', ), array( 'type' => 'text', 'label' => $this->l('Ebook by Editions7'), 'name' => $this->name.'_commebooked', ), array( 'type' => 'text', 'label' => $this->l('Ebook by Others'), 'name' => $this->name.'_commebookoth', ), ) ) ); //Pour remonter les valeurs des champs $params['fields_value'][$this->name.'_titlebook'] = 'Titre livre'; $params['fields_value'][$this->name.'_datecomm'] = ''; $params['fields_value'][$this->name.'_commbroched'] = '0'; $params['fields_value'][$this->name.'_commbrochoth'] = '0'; $params['fields_value'][$this->name.'_commebooked'] = '0'; $params['fields_value'][$this->name.'_commebookoth'] = '0'; } //enregistrement des données public function hookactionAdminCustomersControllerSaveAfter($params) { $title_book = Tools::getValue($this->name.'_titlebook'); $date_com = Tools::getValue($this->name.'_datecomm'); $comm_broched = Tools::getValue($this->name.'_commbroched'); $comm_brochoth = Tools::getValue($this->name.'_commbrochoth'); $comm_ebooked = Tools::getValue($this->name.'_commebooked'); $comm_ebookoth = Tools::getValue($this->name.'_commebookoth'); } } Link to comment 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