Commit 03ad6d198913c80079862fb4bc91f3f162725007

Authored by Adrian
1 parent 35e9527b

Mejoras estéticas en la intefaz del módulo en la ficha del producto. Implementac…

…ión con prestashop 8.
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.6]]></version> 5 + <version><![CDATA[1.7]]></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>
functionsForm.php
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 */ 5 */
6 class imaxForm { 6 class imaxForm {
7 7
8 - private $sinFormulario, $formulario = '', $modulo; 8 + private $sinFormulario, $formulario = '', $modulo, $context, $_path, $_modulePath, $ajax, $idLang, $idShop;
9 9
10 function __construct($modulo, $modulePath = '', $action = '', $method = 'post', $name = '', $enctype = '', $extras = false, $sinFormulario = false, $pathToModule = '', $ajax = false) { 10 function __construct($modulo, $modulePath = '', $action = '', $method = 'post', $name = '', $enctype = '', $extras = false, $sinFormulario = false, $pathToModule = '', $ajax = false) {
11 if ($action == '') { 11 if ($action == '') {
imaxAcordeon.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * @version 1.3 3 * @version 1.3
4 */ 4 */
5 class imaxAcordeon { 5 class imaxAcordeon {
  6 + private $context, $_path;
6 7
7 function __construct($modulePath) { 8 function __construct($modulePath) {
8 $this->context = Context::getContext(); 9 $this->context = Context::getContext();
imaxmultiean.php
@@ -11,7 +11,7 @@ class ImaxMultiEAN extends Module { @@ -11,7 +11,7 @@ class ImaxMultiEAN extends Module {
11 var $idShop; 11 var $idShop;
12 var $idLang; 12 var $idLang;
13 var $idTab; 13 var $idTab;
14 - private $_html = ''; 14 + private $_html = '', $path, $idManual, $forceCheck, $sufijo, $prefijo;
15 15
16 private static $funciones; 16 private static $funciones;
17 17
@@ -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.6'; 25 + $this->version = '1.7';
26 $this->author = 'Informax'; 26 $this->author = 'Informax';
27 $this->need_instance = 0; 27 $this->need_instance = 0;
28 $this->idManual = ''; 28 $this->idManual = '';
templates/hook/admin_products_extra.tpl
@@ -3,24 +3,30 @@ @@ -3,24 +3,30 @@
3 font-family: Arial, sans-serif; 3 font-family: Arial, sans-serif;
4 width: 50%; 4 width: 50%;
5 } 5 }
6 -  
7 - #multiEAN h3, #multiEAN h4 { 6 +
  7 + #multiEAN h3{
  8 + padding-top: 25px;
  9 + }
  10 +
  11 + #multiEAN h3,
  12 + #multiEAN h4 {
8 color: #333; 13 color: #333;
  14 + }
  15 +
  16 + #multiEAN hr {
9 border-bottom: 2px solid #ddd; 17 border-bottom: 2px solid #ddd;
10 - padding-bottom: 10px;  
11 - margin-bottom: 15px;  
12 } 18 }
13 - 19 +
14 #multiEAN p { 20 #multiEAN p {
15 color: #555; 21 color: #555;
16 margin-bottom: 10px; 22 margin-bottom: 10px;
17 } 23 }
18 - 24 +
19 #multiEAN ul { 25 #multiEAN ul {
20 list-style-type: none; 26 list-style-type: none;
21 padding: 0; 27 padding: 0;
22 } 28 }
23 - 29 +
24 #multiEAN li { 30 #multiEAN li {
25 margin: 10px 0; 31 margin: 10px 0;
26 background: #f9f9f9; 32 background: #f9f9f9;
@@ -28,7 +34,7 @@ @@ -28,7 +34,7 @@
28 border-radius: 5px; 34 border-radius: 5px;
29 position: relative; 35 position: relative;
30 } 36 }
31 - 37 +
32 #multiEAN .borrarEAN { 38 #multiEAN .borrarEAN {
33 color: #f44336; 39 color: #f44336;
34 cursor: pointer; 40 cursor: pointer;
@@ -39,7 +45,7 @@ @@ -39,7 +45,7 @@
39 text-decoration: none; 45 text-decoration: none;
40 font-size: 0.9em; 46 font-size: 0.9em;
41 } 47 }
42 - 48 +
43 #multiEAN button { 49 #multiEAN button {
44 background-color: #4CAF50; 50 background-color: #4CAF50;
45 color: white; 51 color: white;
@@ -48,14 +54,14 @@ @@ -48,14 +54,14 @@
48 border-radius: 5px; 54 border-radius: 5px;
49 cursor: pointer; 55 cursor: pointer;
50 transition: background-color 0.2s; 56 transition: background-color 0.2s;
51 - display: block; 57 + display: block;
52 margin: 10px 0; 58 margin: 10px 0;
53 } 59 }
54 - 60 +
55 #multiEAN button:hover { 61 #multiEAN button:hover {
56 background-color: #45a049; 62 background-color: #45a049;
57 } 63 }
58 - 64 +
59 #multiEAN input[type="text"] { 65 #multiEAN input[type="text"] {
60 padding: 10px; 66 padding: 10px;
61 border: 1px solid #ddd; 67 border: 1px solid #ddd;
@@ -64,7 +70,6 @@ @@ -64,7 +70,6 @@
64 box-sizing: border-box; 70 box-sizing: border-box;
65 margin-bottom: 10px; 71 margin-bottom: 10px;
66 } 72 }
67 -  
68 </style> 73 </style>
69 74
70 <div id="multiEAN"> 75 <div id="multiEAN">
@@ -77,50 +82,56 @@ @@ -77,50 +82,56 @@
77 </ul> 82 </ul>
78 <input type="text" id="new_product_ean" placeholder="Introduce el nuevo EAN" /> 83 <input type="text" id="new_product_ean" placeholder="Introduce el nuevo EAN" />
79 <button class="guardarEAN">Agregar EAN al producto</button> 84 <button class="guardarEAN">Agregar EAN al producto</button>
80 -  
81 -{foreach $combinations_details as $combination}  
82 - <h4>Combinación: {$combination.attribute_name}</h4>  
83 - <p>EANs:</p>  
84 - <ul id="combination_{$combination.id}_eans_list">  
85 - {foreach $combination.eans as $ean}  
86 - <li>{$ean.ean13} <span class="borrarEAN" data-ean13='{$ean.ean13}' data-id_combinacion='{$combination.id}'>[Eliminar]</span></li>  
87 - {/foreach}  
88 - </ul>  
89 - <input type="text" id="new_combination_{$combination.id}_ean" placeholder="Introduce el nuevo EAN para esta combinación" />  
90 - <button class="guardarEAN" data-id_combinacion='{$combination.id}'>Agregar EAN a la combinación</button>  
91 -{/foreach} 85 + <hr>
  86 + {foreach $combinations_details as $combination}
  87 + <h4>Combinación: {$combination.attribute_name}</h4>
  88 + <p>EANs:</p>
  89 + <ul id="combination_{$combination.id}_eans_list">
  90 + {foreach $combination.eans as $ean}
  91 + <li>{$ean.ean13} <span class="borrarEAN" data-ean13='{$ean.ean13}'
  92 + data-id_combinacion='{$combination.id}'>[Eliminar]</span></li>
  93 + {/foreach}
  94 + </ul>
  95 + <input type="text" id="new_combination_{$combination.id}_ean"
  96 + placeholder="Introduce el nuevo EAN para esta combinación" />
  97 + <button class="guardarEAN" data-id_combinacion='{$combination.id}'>Agregar EAN a la combinación</button>
  98 + <hr>
  99 + {/foreach}
92 </div> 100 </div>
93 101
94 <script> 102 <script>
95 -$(function(){  
96 - $('.guardarEAN').click(function(ev){  
97 - ev.preventDefault();  
98 - let data = {  
99 - accion: 'storeEAN',  
100 - productId: "{$product_id}",  
101 - };  
102 -  
103 - let combinationId = $(this).data('id_combinacion');  
104 - let eanInput = combinationId ? $('#new_combination_' + combinationId + '_ean') : $('#new_product_ean');  
105 - data.ean = eanInput.val().trim();  
106 -  
107 - if (!data.ean) {  
108 - showErrorMessage('El campo EAN no puede estar vacío.');  
109 - return;  
110 - }  
111 -  
112 - if (combinationId) {  
113 - data.combinationId = combinationId;  
114 - }  
115 -  
116 - $.getJSON('//{$urlBase}/imaxmultiean_ajax.php?callback=?', data, function (respuesta) { 103 + $(function() {
  104 + $('.guardarEAN').click(function(ev) {
  105 + ev.preventDefault();
  106 + let data = {
  107 + accion: 'storeEAN',
  108 + productId: "{$product_id}",
  109 + };
  110 +
  111 + let combinationId = $(this).data('id_combinacion');
  112 + let eanInput = combinationId ? $('#new_combination_' + combinationId + '_ean') : $(
  113 + '#new_product_ean');
  114 + data.ean = eanInput.val().trim();
  115 +
  116 + if (!data.ean) {
  117 + showErrorMessage('El campo EAN no puede estar vacío.');
  118 + return;
  119 + }
  120 +
  121 + if (combinationId) {
  122 + data.combinationId = combinationId;
  123 + }
  124 +
  125 + $.getJSON('//{$urlBase}/imaxmultiean_ajax.php?callback=?', data, function (respuesta) {
117 if (respuesta.ok) { 126 if (respuesta.ok) {
118 showSuccessMessage('EAN almacenado con éxito.'); 127 showSuccessMessage('EAN almacenado con éxito.');
119 128
120 - let eanList = combinationId ? $('#combination_' + combinationId + '_eans_list') : $('#product_eans_list');  
121 - let eanItem = $('<li>').text(data.ean).append($('<span>').addClass('borrarEAN').attr('data-ean13', data.ean).text('[Eliminar]')); 129 + let eanList = combinationId ? $('#combination_' + combinationId + '_eans_list') : $(
  130 + '#product_eans_list');
  131 + let eanItem = $('<li>').text(data.ean).append($('<span>').addClass('borrarEAN').attr(
  132 + 'data-ean13', data.ean).text('[Eliminar]'));
122 eanList.append(eanItem); 133 eanList.append(eanItem);
123 - 134 +
124 eanInput.val(''); // Limpiar el campo de entrada 135 eanInput.val(''); // Limpiar el campo de entrada
125 136
126 } else { 137 } else {
@@ -130,32 +141,30 @@ $(function(){ @@ -130,32 +141,30 @@ $(function(){
130 }); 141 });
131 142
132 // En este bloque, usaremos la delegación de eventos para asegurarnos de que también funcione para los elementos EAN recién agregados. 143 // En este bloque, usaremos la delegación de eventos para asegurarnos de que también funcione para los elementos EAN recién agregados.
133 - $(document).on('click', '.borrarEAN', function(){  
134 - let data = {  
135 - accion: 'deleteEAN',  
136 - productId: "{$product_id}",  
137 - ean: $(this).data('ean13'),  
138 - }; 144 + $(document).on('click', '.borrarEAN', function() {
  145 + let data = {
  146 + accion: 'deleteEAN',
  147 + productId: "{$product_id}",
  148 + ean: $(this).data('ean13'),
  149 + };
  150 +
  151 + let combinationId = $(this).data('id_combinacion');
  152 + if (combinationId) {
  153 + data.combinationId = combinationId;
  154 + }
139 155
140 - let combinationId = $(this).data('id_combinacion');  
141 - if (combinationId) {  
142 - data.combinationId = combinationId;  
143 - } 156 + let eanItem = $(this).closest('li'); // Referencia al elemento <li> que contiene el EAN
144 157
145 - let eanItem = $(this).closest('li'); // Referencia al elemento <li> que contiene el EAN 158 + $.getJSON('//{$urlBase}/imaxmultiean_ajax.php?callback=?', data, function (respuesta) {
  159 + if (respuesta.ok) {
  160 + showSuccessMessage('EAN eliminado con éxito.');
146 161
147 - $.getJSON('//{$urlBase}/imaxmultiean_ajax.php?callback=?', data, function (respuesta) {  
148 - if (respuesta.ok) {  
149 - showSuccessMessage('EAN eliminado con éxito.');  
150 -  
151 - eanItem.remove(); // Remover el elemento <li> del DOM 162 + eanItem.remove(); // Remover el elemento <li> del DOM
152 163
153 - } else {  
154 - showErrorMessage('Hubo un error al eliminar el EAN.');  
155 - }  
156 - }); 164 + } else {
  165 + showErrorMessage('Hubo un error al eliminar el EAN.');
  166 + }
  167 + });
  168 + });
157 }); 169 });
158 -});  
159 -  
160 -  
161 </script> 170 </script>
162 \ No newline at end of file 171 \ No newline at end of file