Changeset 3270560
- Timestamp:
- 04/10/2025 03:33:47 PM (11 months ago)
- Location:
- perseo-software/trunk
- Files:
-
- 4 edited
-
PluginPerseo.php (modified) (2 diffs)
-
PluginPerseoClientes.php (modified) (1 diff)
-
README.md (modified) (4 diffs)
-
includes/PluginPerseo_cron.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
perseo-software/trunk/PluginPerseo.php
r3242181 r3270560 4 4 Plugin URI: https://perseo.ec/ 5 5 Description: Este Plugins integra el Sistema Contable Perseo Web y PC con la tienda Woocommerce 6 Version: 3 1.06 Version: 32.0 7 7 Author: Perseo Soft S.A. - Ecuador 8 8 Author URI: https://perseo.ec … … 13 13 */ 14 14 15 $version_Plugin = '3 0.0';15 $version_Plugin = '32.0'; 16 16 define('PERSEO_DIR_PATH', plugin_dir_path(__FILE__)); 17 17 define('PERSEOCONFIGBASE', get_option('pluginperseo_configuracion')); -
perseo-software/trunk/PluginPerseoClientes.php
r3242181 r3270560 1 1 <?php 2 $version_Plugin = '3 1.0';2 $version_Plugin = '32.0'; 3 3 //define('PERSEO_DIR_PATH', plugin_dir_path(__FILE__)); 4 4 //////////////////////////////////////////////////////////////// -
perseo-software/trunk/README.md
r3242181 r3270560 1 1 === PluginPerseo === 2 2 3 Contributors: Perseo Soft S.A. - Ecuador3 Contributors: Perseo Soft S.A. - Ecuador 4 4 Donate Link: https://perseo.ec/ 5 5 Tags: auto publish, content marketing … … 7 7 Tested up to: 6.7.2 8 8 Requires PHP: 7.4 9 Stable tag: 3 1.09 Stable tag: 32.0 10 10 License: GPLv2 or later 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 12 13 14 13 This Pluing integrates the Accounting System Perseo Web and PC with the store. 15 16 14 == Description == 17 15 … … 31 29 == Installation == 32 30 33 34 31 Contact your Perseo Software support. 35 32 36 33 == Frequently Asked Questions == 37 34 38 35 = A question that someone might have = 39 36 40 37 An answer to that question. 41 38 42 39 = What about foo bar? = 43 40 44 41 Answer to foo bar dilemma. 45 42 … … 47 44 48 45 1. perseo-1.jpg 49 2. == Changelog == 46 2. == Changelog == 47 = 32.0 = 48 49 - Correcciones de sincronizacion de imagenes 50 51 == Changelog == 50 52 = 31.0 = 51 * Correcciones de sincronizacion de categorias 52 * Recomendaciones: Eliminar categorias para que se vuelvan a sincronizar automaticamente. 53 53 54 - Correcciones de sincronizacion de categorias 55 - Recomendaciones: Eliminar categorias para que se vuelvan a sincronizar automaticamente. 56 54 57 == Changelog == 55 58 = 30.0 = 56 * Correcciones de optimización y correcciones varias 59 60 - Correcciones de optimización y correcciones varias 57 61 58 62 == Changelog == 59 63 = 29.0 = 60 * Correccion errores tarifas 61 64 65 - Correccion errores tarifas 66 62 67 == Changelog == 63 68 = 28.0 = 64 * Actualizar campo fecha_sync 65 69 70 - Actualizar campo fecha_sync 71 66 72 == Changelog == 67 73 = 27.0 = 68 * Actualizacion iva y parametros. 74 75 - Actualizacion iva y parametros. 69 76 70 77 == Changelog == 71 78 = 26.0 = 72 * Actualizacion api. 73 79 80 - Actualizacion api. 81 74 82 == Changelog == 75 83 = 25.0 = 76 * Actualizacion pc. 84 85 - Actualizacion pc. 77 86 78 87 == Changelog == 79 88 = 24.0 = 80 * Actualizacion pc. 89 90 - Actualizacion pc. 81 91 82 92 == Changelog == 83 93 = 23.0 = 84 * Actualizacion precios . 94 95 - Actualizacion precios . 85 96 86 97 == Changelog == 87 98 = 22.0 = 88 * Actualizacion . 99 100 - Actualizacion . 89 101 90 102 == Changelog == 91 103 = 21.0 = 92 * Actualizacion . 104 105 - Actualizacion . 93 106 94 107 == Changelog == 95 108 = 20.0 = 96 * Actualizacion . 109 110 - Actualizacion . 97 111 98 112 == Changelog == 99 113 = 17.0 = 100 * Actualizacion . 114 115 - Actualizacion . 101 116 102 117 = 16.0 = 103 * Actualizacion . 118 119 - Actualizacion . 104 120 105 121 = 15.0 = 106 * Actualizacion . 122 123 - Actualizacion . 107 124 108 125 = 14.0 = 109 * Actualizacion . 126 127 - Actualizacion . 110 128 111 129 = 13.0 = 112 * Actualizacion . 130 131 - Actualizacion . 113 132 114 133 = 12.0 = 115 * Actualizacion . 134 135 - Actualizacion . 116 136 117 137 = 11.0 = 118 * Actualizacion . 138 139 - Actualizacion . 119 140 120 141 = 10.0 = 121 * Actualizacion . 142 143 - Actualizacion . 122 144 123 145 = 9.0 = 124 * Actualizacion . 146 147 - Actualizacion . 125 148 126 149 = 8.0 = 127 * Actualizacion . 150 151 - Actualizacion . 128 152 129 153 = 7.0 = 130 * Actualizacion . 154 155 - Actualizacion . 131 156 132 157 = 6.0 = 133 * Actualizacion . 158 159 - Actualizacion . 134 160 135 161 = 5.0 = 136 * Actualizacion de correo. 162 163 - Actualizacion de correo. 137 164 138 165 = 5.0 = 139 * Actualizacion de imagenes. 166 167 - Actualizacion de imagenes. 140 168 141 169 = 4.0 = 142 * Actualizacion de stock. 170 171 - Actualizacion de stock. 143 172 144 173 = 3.0 = 145 * A change since the previous version. 174 175 - A change since the previous version. 146 176 147 177 = 2.0 = 148 * A change since the previous version. 149 * Fixed a pagination bug. 178 179 - A change since the previous version. 180 - Fixed a pagination bug. 150 181 151 182 = 1.1 = 152 * A change since the previous version. 153 * Fixed a pagination bug. 183 184 - A change since the previous version. 185 - Fixed a pagination bug. 154 186 155 187 = 1.0 = 156 * New: Basic functionalities for this plugin. 188 189 - New: Basic functionalities for this plugin. 157 190 158 191 == Upgrade Notice == 159 192 160 193 = 1.1 = 161 Actualizacion de imagenes 194 Actualizacion de imagenes -
perseo-software/trunk/includes/PluginPerseo_cron.php
r3242181 r3270560 1250 1250 private function procesar_imagenes_producto($productoID, $idPost, $wpdb, $table_prefix, $perseo_urlimagen, $perseo_config) 1251 1251 { 1252 // 🔹 Limpiar cache para evitar inconsistencias al agregar nuevas imágenes 1253 static $imagenes_cache = []; 1254 // Forzar la actualización del cache para este producto específico 1255 unset($imagenes_cache[$productoID]); 1256 1252 1257 // 🔹 Obtener imágenes del producto desde la API en una sola llamada 1253 static $imagenes_cache = [];1254 1258 if (!isset($imagenes_cache[$productoID])) { 1255 1259 $body = ['api_key' => $perseo_config['perseotoken'], 'productosid' => $productoID]; … … 1266 1270 1267 1271 $imagenes_cache[$productoID] = json_decode(wp_remote_retrieve_body($response), true)['productos_imagenes'] ?? []; 1272 1273 // Log para depuración 1274 //error_log("Producto {$productoID}: " . count($imagenes_cache[$productoID]) . " imágenes obtenidas de la API"); 1268 1275 } 1269 1276 … … 1277 1284 // 🔹 Obtener imágenes ya asociadas al producto 1278 1285 $imagenes_existentes = $wpdb->get_results($wpdb->prepare( 1279 "SELECT ID, guid FROM {$table_prefix}posts WHERE post_parent = %d AND post_type = 'attachment'",1286 "SELECT ID, guid, post_title FROM {$table_prefix}posts WHERE post_parent = %d AND post_type = 'attachment'", 1280 1287 $idPost 1281 1288 ), OBJECT_K); … … 1285 1292 wp_mkdir_p($base_upload_path); // Crear el directorio si no existe 1286 1293 1294 // 🔹 Lista para seguimiento de imágenes procesadas 1295 $imagenes_procesadas = []; 1287 1296 $thumbnail_id = null; 1288 1297 $gallery_ids = []; 1289 1298 $counter = 1; 1290 1299 1291 foreach ($imagenes as $imagen) { 1300 // Procesar las imágenes de la API 1301 foreach ($imagenes as $index => $imagen) { 1292 1302 if ($imagen["ecommerce"] != 1) { 1303 //error_log("Imagen {$index} para producto {$productoID} no está habilitada para eCommerce, omitiendo"); 1293 1304 continue; // Solo procesamos imágenes habilitadas para eCommerce 1294 1305 } 1295 1306 1296 $file_name = "{$productoID}_imagen_{$counter}.png"; 1307 // Usar un ID único para cada imagen basado en su índice en el array 1308 $imagen_index = isset($imagen['imagenid']) ? $imagen['imagenid'] : $counter; 1309 $file_name = "{$productoID}_imagen_{$imagen_index}.png"; 1297 1310 $file_path = "{$base_upload_path}/{$file_name}"; 1298 1311 $file_url = "{$upload_dir['baseurl']}/" . date('Y') . "/" . date('m') . "/{$file_name}"; 1299 1312 1300 // 🔹 Evitar insertar imágenes duplicadas 1301 $duplicada = false; 1302 foreach ($imagenes_existentes as $img) { 1303 if ($img->guid === $file_url) { 1304 $duplicada = true; 1313 // Log para depuración 1314 //error_log("Procesando imagen {$imagen_index} para producto {$productoID}"); 1315 1316 // Verificar si ya existe la imagen con el mismo nombre 1317 $imagen_existente_id = null; 1318 foreach ($imagenes_existentes as $id => $img) { 1319 if (basename($img->guid) === $file_name || $img->post_title === sanitize_file_name($file_name)) { 1320 $imagen_existente_id = $id; 1305 1321 break; 1306 1322 } 1307 1323 } 1308 if ($duplicada) { 1309 continue; 1310 } 1311 1312 // 🔹 Guardar imagen en el sistema de archivos 1324 1325 // 🔹 Guardar imagen en el sistema de archivos (siempre, para actualizar contenido) 1313 1326 $image_data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $imagen['imagen'])); 1314 1327 if (file_put_contents($file_path, $image_data) === false) { … … 1317 1330 } 1318 1331 1319 // 🔹 Insertar la imagen como adjunto en WordPress 1320 $attachment = [ 1321 'post_mime_type' => 'image/png', 1322 'post_title' => sanitize_file_name($file_name), 1323 'post_content' => '', 1324 'post_status' => 'inherit', 1325 'guid' => $file_url, 1326 'post_parent' => $idPost 1327 ]; 1328 1329 $attachment_id = wp_insert_attachment($attachment, $file_path, $idPost); 1330 if (is_wp_error($attachment_id)) { 1331 error_log("Error al insertar la imagen como adjunto para el producto {$productoID}"); 1332 continue; 1333 } 1334 1335 // 🔹 Generar metadatos de la imagen 1336 require_once ABSPATH . 'wp-admin/includes/image.php'; 1337 $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file_path); 1338 wp_update_attachment_metadata($attachment_id, $attachment_metadata); 1332 $attachment_id = null; 1333 1334 // Si ya existe la imagen, actualizamos sus metadatos 1335 if ($imagen_existente_id) { 1336 $attachment_id = $imagen_existente_id; 1337 1338 // Actualizar metadata de la imagen 1339 require_once ABSPATH . 'wp-admin/includes/image.php'; 1340 $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file_path); 1341 wp_update_attachment_metadata($attachment_id, $attachment_metadata); 1342 } else { 1343 // 🔹 Insertar la imagen como nuevo adjunto en WordPress 1344 $attachment = [ 1345 'post_mime_type' => 'image/png', 1346 'post_title' => sanitize_file_name($file_name), 1347 'post_content' => '', 1348 'post_status' => 'inherit', 1349 'guid' => $file_url, 1350 'post_parent' => $idPost 1351 ]; 1352 1353 $attachment_id = wp_insert_attachment($attachment, $file_path, $idPost); 1354 if (is_wp_error($attachment_id)) { 1355 error_log("Error al insertar la imagen como adjunto para el producto {$productoID}"); 1356 continue; 1357 } 1358 1359 // 🔹 Generar metadatos de la imagen 1360 require_once ABSPATH . 'wp-admin/includes/image.php'; 1361 $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file_path); 1362 wp_update_attachment_metadata($attachment_id, $attachment_metadata); 1363 } 1364 1365 // Marcar que esta imagen fue procesada 1366 $imagenes_procesadas[] = $attachment_id; 1339 1367 1340 1368 // 🔹 Asignar como imagen destacada o añadir a la galería 1341 if ($imagen['primera'] == 1 && !$thumbnail_id) {1369 if ($imagen['primera'] == 1) { 1342 1370 $thumbnail_id = $attachment_id; // Guardar como imagen destacada 1343 } else { 1344 $gallery_ids[] = $attachment_id; // Agregar a la galería 1371 //error_log("Imagen {$attachment_id} marcada como destacada para producto {$productoID}"); 1372 } 1373 1374 // Siempre añadir a la galería (incluyendo la destacada) 1375 if (!in_array($attachment_id, $gallery_ids)) { 1376 $gallery_ids[] = $attachment_id; 1377 //error_log("Imagen {$attachment_id} añadida a la galería para producto {$productoID}"); 1345 1378 } 1346 1379 1347 1380 $counter++; 1348 1381 } 1382 1383 // 🔹 Eliminar imágenes antiguas que ya no existen en la API 1384 foreach ($imagenes_existentes as $id => $img) { 1385 if (!in_array($id, $imagenes_procesadas)) { 1386 //error_log("Eliminando imagen obsoleta ID {$id} para producto {$productoID}"); 1387 wp_delete_attachment($id, true); // Eliminar permanentemente 1388 } 1389 } 1390 1391 // Log para depuración 1392 error_log("Producto {$productoID}: Procesadas " . count($imagenes_procesadas) . " imágenes, " . count($gallery_ids) . " en galería"); 1349 1393 1350 1394 // 🔹 Asignar imagen destacada al producto … … 1353 1397 } 1354 1398 1355 // 🔹 Asignar galería de imágenes al producto 1399 // 🔹 Asignar galería de imágenes al producto (siempre actualizar toda la galería) 1356 1400 if (!empty($gallery_ids)) { 1357 1401 update_post_meta($idPost, '_product_image_gallery', implode(',', $gallery_ids)); 1358 } 1402 } else { 1403 delete_post_meta($idPost, '_product_image_gallery'); 1404 } 1405 // Forzar una actualización completa del caché de WordPress 1406 wp_cache_flush(); 1407 clean_post_cache($idPost); 1408 1409 // Limpiar caché específica de imágenes adjuntas 1410 foreach ($imagenes_procesadas as $attachment_id) { 1411 clean_attachment_cache($attachment_id); 1412 } 1413 1414 // Regenerar caché de thumbnails 1415 update_option('_transient_timeout_wc_product_gallery_' . $idPost, 1); 1416 delete_transient('wc_product_gallery_' . $idPost); 1359 1417 } 1360 1418 }
Note: See TracChangeset
for help on using the changeset viewer.