diff --git a/ChangeLog.md b/ChangeLog.md index 055095c..1b28883 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,7 @@ ## 4.1.40.0 - Correction de l'enregistrement des correspondances entre statuts des commandes de dolibarr vers WooCommerce +- Mise à jour de la configuration à l'activation du module ## 4.1.39.0 - Optimisation et correction de la tache planifiée de mise à jour des stocks diff --git a/class/data/eCommerceSite.class.php b/class/data/eCommerceSite.class.php index 9d54cbd..128e0ee 100644 --- a/class/data/eCommerceSite.class.php +++ b/class/data/eCommerceSite.class.php @@ -847,6 +847,44 @@ function setEntityValues($entity) } } + /** + * Upgrade the parameters configuration to the new setup + * + * @return int <0 if KO, >0 if OK + */ + public function upgradeParameters() + { + global $user; + + // setup + if (!isset($this->authentication_type)) $this->authentication_type = 'oauth1_header'; + // stock + if (!isset($this->parameters['order_actions']['valid_invoice_fk_warehouse'])) $this->parameters['order_actions']['valid_invoice_fk_warehouse'] = $this->parameters['order_actions']['valid_order_fk_warehouse']; + if (!isset($this->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'])) $this->parameters['order_actions']['valid_supplier_invoice_fk_warehouse'] = $this->parameters['order_actions']['valid_order_fk_warehouse']; + // extra fields + $table_elements = [ 'societe', 'product', 'commande', 'commandedet' ]; + foreach ($table_elements as $table_element) { + if (!isset($this->parameters['extra_fields'][$table_element])) { + if (isset($this->parameters['ef_crp'][$table_element])) { + foreach ($this->parameters['ef_crp'][$table_element] as $key => $info) { + $this->parameters['extra_fields'][$table_element]['activated']['mdt'][$key] = $info['activated']; + $this->parameters['extra_fields'][$table_element]['values']['mdt'][$key] = $info['correspondences']; + } + } + if ($table_element == 'product' && isset($this->parameters['ef_crp_attribute'])) { + foreach ($this->parameters['ef_crp_attribute'] as $key => $info) { + $this->parameters['extra_fields'][$table_element]['activated']['att'][$key] = $info['activated']; + $this->parameters['extra_fields'][$table_element]['values']['att'][$key] = $info['correspondences']; + } + } + } + } + if (isset($this->parameters['ef_crp'])) unset($this->parameters['ef_crp']); + if (isset($this->parameters['ef_crp_attribute'])) unset($this->parameters['ef_crp_attribute']); + + return $this->update($user); + } + /** * Method to output saved errors * diff --git a/core/modules/modECommerceNg.class.php b/core/modules/modECommerceNg.class.php index 0c1f1b1..3d27753 100644 --- a/core/modules/modECommerceNg.class.php +++ b/core/modules/modECommerceNg.class.php @@ -454,9 +454,22 @@ function init($options = '') // Delete semaphore token for cron jobs require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; dolibarr_del_const($this->db, 'ECOMMERCE_PROCESSING_WEBHOOK_SYNCHRONIZATION', 0); - dolibarr_del_const($this->db, 'ECOMMERCE_CHECK_WEBHOOKS_STATUS', 0); $result=$this->load_tables($options); + + // Upgrade site configuration to new setup cards + $eCommerceSite = new eCommerceSite($this->db); + $sites = $eCommerceSite->listSites('object'); + if (is_array($sites)) { + foreach ($sites as $site) { + $result = $site->upgradeParameters(); + if ($result < 0) { + setEventMessages($site->error, $site->errors, 'errors'); + return 0; + } + } + } + $this->addSettlementTerms(); $this->addAnonymousCompany(); return $this->_init($sql, $options);