Commit 18479c48992a0e84c7e35f5dfa7a6565aa89adce

Authored by Adrian
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.
FuncionesImaxMultiEAN.php
... ... @@ -14,12 +14,20 @@ class FuncionesImaxMultiEAN {
14 14  
15 15 public function storeEAN($productId, $ean, $combinationId = 0) {
16 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 24 public function deleteEAN($productId, $ean, $combinationId = 0) {
21 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 33 public function getProductByEan($ean) {
... ...
config.xml
... ... @@ -2,7 +2,7 @@
2 2 <module>
3 3 <name>imaxmultiean</name>
4 4 <displayName><![CDATA[Gestor de EANs Múltiples]]></displayName>
5   - <version><![CDATA[1.3]]></version>
  5 + <version><![CDATA[1.4]]></version>
6 6 <description><![CDATA[Permite añadir y gestionar múltiples códigos EAN para cada producto y combinación.]]></description>
7 7 <author><![CDATA[Informax]]></author>
8 8 <tab><![CDATA[administration]]></tab>
... ...
imaxmultiean.php
... ... @@ -22,7 +22,7 @@ class ImaxMultiEAN extends Module {
22 22 $this->name = 'imaxmultiean';
23 23 $this->tab = 'administration';
24 24 $this->path = _PS_MODULE_DIR_ . $this->name . '/';
25   - $this->version = '1.3';
  25 + $this->version = '1.4';
26 26 $this->author = 'Informax';
27 27 $this->need_instance = 0;
28 28 $this->idManual = '';
... ...
sql-install.php
... ... @@ -6,7 +6,8 @@ $sql[] = &quot;CREATE TABLE IF NOT EXISTS `&quot;._DB_PREFIX_.self::prefijo.&quot;multiean` (
6 6 `id_product` INT(10) NOT NULL,
7 7 `id_product_attribute` INT(10) NOT NULL,
8 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 12 COLLATE='utf8_general_ci'
12 13 ENGINE=MyIsam;";
... ...
templates/hook/admin_products_extra.tpl
... ... @@ -101,7 +101,12 @@ $(function(){
101 101  
102 102 let combinationId = $(this).data('id_combinacion');
103 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 111 if (combinationId) {
107 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 +}
... ...