Jump to content

submit form dans hookDisplayAdminProductsExtra


Recommended Posts

Bonjour à tous, 

Merci par avance pour votre aide. 

Je cherche a enregistrer dans une base de donné les valeurs de mon formulaire qui est and un "hookDisplayAdminProductsExtra"

public function install()
    {

      $sql= "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."MyParam`(`ID_Produit` INT(16) NOT NULL PRIMARY KEY ,`Key` VARCHAR(256) )";

      if(!$result=Db::getInstance()->Execute($sql))
        return false;

        Configuration::updateValue('MYPARAM_LIVE_MODE', false);

        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('backOfficeHeader')&&
            $this->registerHook('displayAdminProductsExtra')&&
            $this->registerHook('hookActionProductSave');
    }

    public function uninstall()
    {
        Configuration::deleteByName('MYPARAM_LIVE_MODE');
        $sql='DROP TABLE `' . _DB_PREFIX_ . 'MyParam`';
        if(!$result=Db::getInstance()->Execute($sql))
          return false;
        return parent::uninstall();
    }
public function MyParamProductForm()
    {
      // Get default language
      $defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');

      // Init Fields form array
      $fieldsForm[0]['form'] = [
          'legend' => [
              'title' => $this->l('Settings'),
          ],
          'input' => [
            array(
              'type' => 'switch',
              'label' => $this->l('Produit Parametrable'),
              'name' => 'MYPARAM_IS_ACTIVE',
              'is_bool' => true,
              'desc' => $this->l('Autoriser un module de configuration produit ShapeDiver'),
              'values' => array(
                  array(
                      'id' => 'active_on',
                      'value' => true,
                      'label' => $this->l('Yes')
                  ),
                  array(
                      'id' => 'active_off',
                      'value' => false,
                      'label' => $this->l('No')
                  )
              ),
            ),
            [
                  'type' => 'text',
                  'label' => $this->l('Ticket ShapeDiver'),
                  'name' => 'MYPARAM_TICKET',
                  'required' => false
              ]
          ],
          'buttons' => array(
                            'save-and-stay' => array(
                            'title' => $this->l('Save and Stay'),
                            'name' => 'submitAdd'.$this->table.'AndStay',
                            'type' => 'submit',
                            'class' => 'btn btn-default pull-right',
                            'icon' => 'process-icon-save',
              ),
          ),
      ];

      $helper = new HelperForm();
      $helper->show_toolbar = false;
      $helper->table = $this->name;
      $helper->module = $this;
      $helper->identifier = $this->identifier;
      $helper->submit_action = 'submitEditExtraTab';
      $helper->currentIndex = $this->context->link->getAdminLink('AdminProducts', false);
      $helper->token = Tools::getAdminTokenLite('AdminProducts');
      $helper->toolbar_btn = array(
                   'save' =>
                        array(
                              'short' => 'Save',
                              'desc' => $this->l('Save'),
                              'href' => AdminController::$currentIndex,
                       ),
               );

      // Load current value

      $query = new DbQuery();
      $query->select('*')
            ->from('MyParam')
            ->where('ID_Produit = ' . (int)$_GET['id_product']);
      $results = Db::getInstance()->executeS($query);
      foreach ($results as $result) {
        $helper->fields_value['MYPARAM_TICKET'] = $result['Key'];
      }
      return $helper->generateForm($fieldsForm);
    }

J'ai essayé avec "hookActionProductSave" mais je ne sais pas comment appeler ce bout de code quand je change la valeur du champ "MYPARAM_TICKET" et click sur SAVE ? 

public function hookActionProductSave($params) {
      $db = Db::getInstance();
      $ID_Prodduit = Tools::getValue('id_product');
      $key = "Value of MYPARAM_TICKET"; // je ne sais pas encore comment recuperer la valeur du champ dans le formulaire
      Db::getInstance()->insert('MyParam', array(
      'ID_Produit' => (int)$ID_Prodduit,
      'Key' => pSQL($key),
      ));

    }

 

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...