Commit 18479c48992a0e84c7e35f5dfa7a6565aa89adce
1 parent
f9175a0c
Validamos, que el ean13 no esté vacío antes de ser almacenado. El ean13 entre co…
…mbinaciones de un mismo producto no puede ser repetido.
Showing
6 changed files
with
36 additions
and
6 deletions
FuncionesImaxMultiEAN.php
| @@ -14,12 +14,20 @@ class FuncionesImaxMultiEAN { | @@ -14,12 +14,20 @@ class FuncionesImaxMultiEAN { | ||
| 14 | 14 | ||
| 15 | public function storeEAN($productId, $ean, $combinationId = 0) { | 15 | public function storeEAN($productId, $ean, $combinationId = 0) { |
| 16 | $sql = 'INSERT INTO ' . _DB_PREFIX_.$this->modulo->prefijo . "multiean (id_product, id_product_attribute, ean13) VALUES ('$productId', '$combinationId', '$ean')"; | 16 | $sql = 'INSERT INTO ' . _DB_PREFIX_.$this->modulo->prefijo . "multiean (id_product, id_product_attribute, ean13) VALUES ('$productId', '$combinationId', '$ean')"; |
| 17 | - return Db::getInstance()->execute($sql); | 17 | + try { |
| 18 | + return Db::getInstance()->execute($sql); | ||
| 19 | + } catch (Exception $e) { | ||
| 20 | + return false; | ||
| 21 | + } | ||
| 18 | } | 22 | } |
| 19 | 23 | ||
| 20 | public function deleteEAN($productId, $ean, $combinationId = 0) { | 24 | public function deleteEAN($productId, $ean, $combinationId = 0) { |
| 21 | $sql = 'DELETE FROM ' . _DB_PREFIX_ . $this->modulo->prefijo . "multiean WHERE id_product = '$productId' AND id_product_attribute = '$combinationId' AND ean13 = '$ean'"; | 25 | $sql = 'DELETE FROM ' . _DB_PREFIX_ . $this->modulo->prefijo . "multiean WHERE id_product = '$productId' AND id_product_attribute = '$combinationId' AND ean13 = '$ean'"; |
| 22 | - return Db::getInstance()->execute($sql); | 26 | + try { |
| 27 | + return Db::getInstance()->execute($sql); | ||
| 28 | + } catch (Exception $e) { | ||
| 29 | + return false; | ||
| 30 | + } | ||
| 23 | } | 31 | } |
| 24 | 32 | ||
| 25 | public function getProductByEan($ean) { | 33 | public function getProductByEan($ean) { |
config.xml
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | <module> | 2 | <module> |
| 3 | <name>imaxmultiean</name> | 3 | <name>imaxmultiean</name> |
| 4 | <displayName><![CDATA[Gestor de EANs Múltiples]]></displayName> | 4 | <displayName><![CDATA[Gestor de EANs Múltiples]]></displayName> |
| 5 | - <version><![CDATA[1.3]]></version> | 5 | + <version><![CDATA[1.4]]></version> |
| 6 | <description><![CDATA[Permite añadir y gestionar múltiples códigos EAN para cada producto y combinación.]]></description> | 6 | <description><![CDATA[Permite añadir y gestionar múltiples códigos EAN para cada producto y combinación.]]></description> |
| 7 | <author><![CDATA[Informax]]></author> | 7 | <author><![CDATA[Informax]]></author> |
| 8 | <tab><![CDATA[administration]]></tab> | 8 | <tab><![CDATA[administration]]></tab> |
imaxmultiean.php
| @@ -22,7 +22,7 @@ class ImaxMultiEAN extends Module { | @@ -22,7 +22,7 @@ class ImaxMultiEAN extends Module { | ||
| 22 | $this->name = 'imaxmultiean'; | 22 | $this->name = 'imaxmultiean'; |
| 23 | $this->tab = 'administration'; | 23 | $this->tab = 'administration'; |
| 24 | $this->path = _PS_MODULE_DIR_ . $this->name . '/'; | 24 | $this->path = _PS_MODULE_DIR_ . $this->name . '/'; |
| 25 | - $this->version = '1.3'; | 25 | + $this->version = '1.4'; |
| 26 | $this->author = 'Informax'; | 26 | $this->author = 'Informax'; |
| 27 | $this->need_instance = 0; | 27 | $this->need_instance = 0; |
| 28 | $this->idManual = ''; | 28 | $this->idManual = ''; |
sql-install.php
| @@ -6,7 +6,8 @@ $sql[] = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_.self::prefijo."multiean` ( | @@ -6,7 +6,8 @@ $sql[] = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_.self::prefijo."multiean` ( | ||
| 6 | `id_product` INT(10) NOT NULL, | 6 | `id_product` INT(10) NOT NULL, |
| 7 | `id_product_attribute` INT(10) NOT NULL, | 7 | `id_product_attribute` INT(10) NOT NULL, |
| 8 | `ean13` VARCHAR(255) NOT NULL, | 8 | `ean13` VARCHAR(255) NOT NULL, |
| 9 | - PRIMARY KEY (`id`) | 9 | + PRIMARY KEY (`id`), |
| 10 | + UNIQUE KEY `unique_ean_per_product_combination` (`id_product`, `ean13`) | ||
| 10 | ) | 11 | ) |
| 11 | COLLATE='utf8_general_ci' | 12 | COLLATE='utf8_general_ci' |
| 12 | ENGINE=MyIsam;"; | 13 | ENGINE=MyIsam;"; |
templates/hook/admin_products_extra.tpl
| @@ -101,7 +101,12 @@ $(function(){ | @@ -101,7 +101,12 @@ $(function(){ | ||
| 101 | 101 | ||
| 102 | let combinationId = $(this).data('id_combinacion'); | 102 | let combinationId = $(this).data('id_combinacion'); |
| 103 | let eanInput = combinationId ? $('#new_combination_' + combinationId + '_ean') : $('#new_product_ean'); | 103 | let eanInput = combinationId ? $('#new_combination_' + combinationId + '_ean') : $('#new_product_ean'); |
| 104 | - data.ean = eanInput.val(); | 104 | + data.ean = eanInput.val().trim(); |
| 105 | + | ||
| 106 | + if (!data.ean) { | ||
| 107 | + showErrorMessage('El campo EAN no puede estar vacío.'); | ||
| 108 | + return; | ||
| 109 | + } | ||
| 105 | 110 | ||
| 106 | if (combinationId) { | 111 | if (combinationId) { |
| 107 | data.combinationId = combinationId; | 112 | data.combinationId = combinationId; |
upgrade/upgrade-1.4.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +function upgrade_module_1_4($module) { | ||
| 4 | + $sql = array(); | ||
| 5 | + | ||
| 6 | + $sql[] = "ALTER TABLE `"._DB_PREFIX_.$module->prefijo."multiean` | ||
| 7 | + ADD UNIQUE KEY `unique_ean_per_product_combination` (`id_product`, `ean13`);"; | ||
| 8 | + | ||
| 9 | + foreach ($sql as $query) { | ||
| 10 | + if (Db::getInstance()->execute($query) == false) { | ||
| 11 | + return false; | ||
| 12 | + } | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + return true; | ||
| 16 | +} |