diff --git a/FuncionesImaxMultiEAN.php b/FuncionesImaxMultiEAN.php index b0d92c7..35fd65f 100644 --- a/FuncionesImaxMultiEAN.php +++ b/FuncionesImaxMultiEAN.php @@ -14,12 +14,20 @@ class FuncionesImaxMultiEAN { public function storeEAN($productId, $ean, $combinationId = 0) { $sql = 'INSERT INTO ' . _DB_PREFIX_.$this->modulo->prefijo . "multiean (id_product, id_product_attribute, ean13) VALUES ('$productId', '$combinationId', '$ean')"; - return Db::getInstance()->execute($sql); + try { + return Db::getInstance()->execute($sql); + } catch (Exception $e) { + return false; + } } public function deleteEAN($productId, $ean, $combinationId = 0) { $sql = 'DELETE FROM ' . _DB_PREFIX_ . $this->modulo->prefijo . "multiean WHERE id_product = '$productId' AND id_product_attribute = '$combinationId' AND ean13 = '$ean'"; - return Db::getInstance()->execute($sql); + try { + return Db::getInstance()->execute($sql); + } catch (Exception $e) { + return false; + } } public function getProductByEan($ean) { diff --git a/config.xml b/config.xml index 5253431..571cec0 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ imaxmultiean - + diff --git a/imaxmultiean.php b/imaxmultiean.php index cda2954..58af655 100644 --- a/imaxmultiean.php +++ b/imaxmultiean.php @@ -22,7 +22,7 @@ class ImaxMultiEAN extends Module { $this->name = 'imaxmultiean'; $this->tab = 'administration'; $this->path = _PS_MODULE_DIR_ . $this->name . '/'; - $this->version = '1.3'; + $this->version = '1.4'; $this->author = 'Informax'; $this->need_instance = 0; $this->idManual = ''; diff --git a/sql-install.php b/sql-install.php index 479207e..b430265 100644 --- a/sql-install.php +++ b/sql-install.php @@ -6,7 +6,8 @@ $sql[] = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_.self::prefijo."multiean` ( `id_product` INT(10) NOT NULL, `id_product_attribute` INT(10) NOT NULL, `ean13` VARCHAR(255) NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `unique_ean_per_product_combination` (`id_product`, `ean13`) ) COLLATE='utf8_general_ci' ENGINE=MyIsam;"; diff --git a/templates/hook/admin_products_extra.tpl b/templates/hook/admin_products_extra.tpl index f7c9242..b7c8161 100644 --- a/templates/hook/admin_products_extra.tpl +++ b/templates/hook/admin_products_extra.tpl @@ -101,7 +101,12 @@ $(function(){ let combinationId = $(this).data('id_combinacion'); let eanInput = combinationId ? $('#new_combination_' + combinationId + '_ean') : $('#new_product_ean'); - data.ean = eanInput.val(); + data.ean = eanInput.val().trim(); + + if (!data.ean) { + showErrorMessage('El campo EAN no puede estar vacío.'); + return; + } if (combinationId) { data.combinationId = combinationId; diff --git a/upgrade/upgrade-1.4.php b/upgrade/upgrade-1.4.php new file mode 100644 index 0000000..b0109cd --- /dev/null +++ b/upgrade/upgrade-1.4.php @@ -0,0 +1,16 @@ +prefijo."multiean` + ADD UNIQUE KEY `unique_ean_per_product_combination` (`id_product`, `ean13`);"; + + foreach ($sql as $query) { + if (Db::getInstance()->execute($query) == false) { + return false; + } + } + + return true; +}