akrom1kas Posted January 10, 2023 Share Posted January 10, 2023 Hello, I need help on how to save data in my database <?php if (!defined('_PS_VERSION_')) { exit; } class Naujas extends Module { protected bool $config_form = false; public function __construct() { $this->name = 'naujas'; $this->tab = 'migration_tools'; $this->version = '1.0.0'; $this->author = 'Mindaugas'; $this->need_instance = 1; /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('naujas'); $this->description = $this->l('naujas naujas naujas'); $this->confirmUninstall = $this->l('Ar tikrai norite istrinti?'); $this->ps_versions_compliancy = array('min' => '1.6', '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() { include(dirname(__FILE__).'/sql/install.php'); return parent::install() && $this->registerHook('header') && $this->registerHook('displayBackOfficeHeader') && $this->registerHook('displayFooter'); } public function uninstall() { include(dirname(__FILE__).'/sql/uninstall.php'); return parent::uninstall(); } /** * Load the configuration form */ public function getContent() { /** * If values have been submitted in the form, process. */ if (((bool)Tools::isSubmit('submitNaujasModule')) == true) { $this->postProcess(); } $this->context->smarty->assign('module_dir', $this->_path); $output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl'); return $output.$this->renderForm(); } /** * Create the form that will be displayed in the configuration of your module. */ protected function renderForm() { $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $helper->module = $this; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); $helper->identifier = $this->identifier; $helper->submit_action = 'submitNaujasModule'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFormValues(), /* Add values for your inputs */ 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id, ); return $helper->generateForm(array($this->getConfigForm())); } /** * Create the structure of your form. */ protected function getConfigForm() { return array( 'form' => array( 'legend' => array( 'title' => $this->l('Nustatymai'), 'icon' => 'icon-cogs', ), 'input' => array( array( 'col' => 3, 'type' => 'text', 'name' => 'importavimo_nuoroda', 'label' => $this->l('Importavimo nuoroda:'), ), array( 'col' => 3, 'type' => 'text', 'name' => 'prekiu_nuoroda', 'label' => $this->l('Prekių nuoroda:'), ), array( 'col' => 3, 'type' => 'text', 'name' => 'vardas', 'label' => $this->l('Prisijungimo vardas:'), ), array( 'col' => 3, 'type' => 'text', 'name' => 'password', 'label' => $this->l('Prisijungimo slaptažodis:'), ), ), 'submit' => array( 'title' => $this->l('Save'), ), ), ); } /** * Set values for the inputs. */ protected function getConfigFormValues() { return array( 'importavimo_nuoroda' => Configuration::get('importavimo_nuoroda'), 'prekiu_nuoroda' => Configuration::get('prekiu_nuoroda'), 'vardas' => Configuration::get('vardas'), 'password' => Configuration::get('password', null), ); } /** * Save form data. */ protected function postProcess() { $form_values = $this->getConfigFormValues(); foreach (array_keys($form_values) as $key) { Configuration::updateValue($key, Tools::getValue($key)); } } /** * Add the CSS & JavaScript files you want to be loaded in the BO. */ public function hookDisplayBackOfficeHeader() { if (Tools::getValue('configure') == $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'); } // // public function hookDisplayFooter() // { // $test = "testing!"; // echo $test; // die; // } } 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