Changeset 3457385
- Timestamp:
- 02/09/2026 07:33:06 PM (4 weeks ago)
- Location:
- shipping-servientrega-woocommerce/trunk
- Files:
-
- 5 edited
-
includes/admin/general.php (modified) (7 diffs)
-
includes/class-method-shipping-servientrega-wc.php (modified) (2 diffs)
-
includes/class-shipping-servientrega-wc.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
-
shipping-servientrega-wc.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipping-servientrega-woocommerce/trunk/includes/admin/general.php
r3311699 r3457385 35 35 $wc_main_settings['servientrega_product_type'] = (isset($_POST['servientrega_product_type'])) ? sanitize_text_field($_POST['servientrega_product_type']) : ''; 36 36 $wc_main_settings['servientrega_print_type'] = (isset($_POST['servientrega_print_type'])) ? sanitize_text_field($_POST['servientrega_print_type']) : ''; 37 38 // Guardar configuración de rangos de peso. 39 $wc_main_settings['servientrega_premier_max_weight'] = ''; 40 $wc_main_settings['servientrega_industrial_min_weight'] = ''; 41 42 if (isset($_POST['servientrega_premier_max_weight']) && is_numeric($_POST['servientrega_premier_max_weight'])) { 43 $premier_max = floatval(sanitize_text_field($_POST['servientrega_premier_max_weight'])); 44 if ($premier_max > 0) { 45 $wc_main_settings['servientrega_premier_max_weight'] = $premier_max; 46 } 47 } 48 49 if (isset($_POST['servientrega_industrial_min_weight']) && is_numeric($_POST['servientrega_industrial_min_weight'])) { 50 $industrial_min = floatval(sanitize_text_field($_POST['servientrega_industrial_min_weight'])); 51 if ($industrial_min > 0) { 52 $wc_main_settings['servientrega_industrial_min_weight'] = $industrial_min; 53 } 54 } 37 55 38 56 update_option('woocommerce_servientrega_shipping_settings', $wc_main_settings); … … 81 99 ]; 82 100 101 // Usar peso de prueba para determinar tipo de producto. 102 $test_weight = 3; // kg de prueba. 103 $product_type_test = Shipping_Servientrega_WC::determine_product_type_by_weight( 104 $test_weight, 105 $wc_main_settings['servientrega_product_type'] 106 ); 107 83 108 $params = array( 84 109 'Num_Guia' => 0, … … 86 111 'Num_Piezas' => 1, 87 112 'Des_TipoTrayecto' => 1, 88 'Ide_Producto' => (int)$ wc_main_settings['servientrega_product_type'],113 'Ide_Producto' => (int)$product_type_test, 89 114 'Ide_Destinatarios' => '00000000-0000-0000-0000-000000000000', 90 115 'Ide_Manifiesto' => '00000000-0000-0000-0000-000000000000', … … 110 135 'idePaisOrigen' => 1, 111 136 'idePaisDestino' => 1, 112 'Des_IdArchivoOrigen' => 1,137 'Des_IdArchivoOrigen' => 0, 113 138 'Des_DireccionRemitente' => '', 114 139 'Num_PesoFacturado' => 0, … … 135 160 ); 136 161 137 if($ wc_main_settings['servientrega_product_type']== 6){162 if($product_type_test == 6){ 138 163 $params['objEnviosUnidadEmpaqueCargue'] = [ 139 164 'EnviosUnidadEmpaqueCargue' => $unidades … … 150 175 151 176 $params = [ 152 'IdProducto' => $ wc_main_settings['servientrega_product_type'],177 'IdProducto' => $product_type_test, 153 178 'NumeroPiezas' => 1, 154 179 'Piezas' => 155 180 [ 156 181 [ 157 'Peso' => $ wc_main_settings['servientrega_product_type']== 2 ? 3 : 1,182 'Peso' => $product_type_test == 2 ? 3 : 1, 158 183 'Largo' => 10, 159 184 'Ancho' => 5, … … 299 324 </td> 300 325 </tr>'; 326 327 // Sección de configuración automática por peso. 328 $htmlGeneral .= '<tr valign="top" id="weight_range_config"> 329 <td colspan="2"> 330 <hr style="margin: 20px 0; border: 0; border-top: 1px solid #ddd;"> 331 <h3 style="margin: 10px 0;">' . __('Configuración automática por peso') . '</h3> 332 <p style="color: #666; font-size: 12px; margin: 5px 0 15px 0;"> 333 ' . __('Configure rangos de peso para seleccionar automáticamente el tipo de producto entre Mercancía Premier y Mercancía Industrial. Si no se configura, se usará el tipo seleccionado manualmente arriba. El tipo "Documento unitario" se mantiene como selección manual.') . ' 334 </p> 335 </td> 336 </tr>'; 337 338 $htmlGeneral .= '<tr valign="top"> 339 <td style="width:25%;font-weight:bold;"> 340 <label for="servientrega_premier_max_weight">' . __('Peso máximo para Premier (kg)') . '</label> 341 <span class="woocommerce-help-tip" data-tip="' . __('Peso máximo en kilogramos para usar Mercancía Premier. Pesos superiores usarán Mercancía Industrial automáticamente. Ejemplo: 6') . '"></span> 342 </td> 343 <td scope="row" class="titledesc" style="display: block;margin-bottom: 20px;margin-top: 3px;"> 344 <fieldset style="padding:3px;"> 345 <input 346 type="number" 347 step="1" 348 min="1" 349 name="servientrega_premier_max_weight" 350 id="servientrega_premier_max_weight" 351 value="' . (isset($general_settings['servientrega_premier_max_weight']) ? esc_attr($general_settings['servientrega_premier_max_weight']) : '') . '" 352 placeholder="6" 353 class="input-text regular-input" 354 style="width: 150px;" 355 /> 356 <p style="color: #666; font-size: 11px; margin-top: 5px;"> 357 ' . __('Ejemplo: Si configura 6 kg, pedidos hasta 6 kg usarán Premier (tipo 2), y desde 7 kg usarán Industrial (tipo 6).') . ' 358 </p> 359 </fieldset> 360 </td> 361 </tr>'; 362 363 $htmlGeneral .= '<tr valign="top"> 364 <td style="width:25%;font-weight:bold;"> 365 <label for="servientrega_industrial_min_weight"> 366 ' . __('Peso mínimo para Industrial (kg)') . ' <em style="font-weight:normal;">' . __('(Opcional)') . '</em> 367 </label> 368 <span class="woocommerce-help-tip" data-tip="' . __('Peso mínimo en kilogramos para usar Mercancía Industrial. Dejar vacío para usar automáticamente el siguiente valor al máximo de Premier.') . '"></span> 369 </td> 370 <td scope="row" class="titledesc" style="display: block;margin-bottom: 20px;margin-top: 3px;"> 371 <fieldset style="padding:3px;"> 372 <input 373 type="number" 374 step="1" 375 min="1" 376 name="servientrega_industrial_min_weight" 377 id="servientrega_industrial_min_weight" 378 value="' . (isset($general_settings['servientrega_industrial_min_weight']) ? esc_attr($general_settings['servientrega_industrial_min_weight']) : '') . '" 379 placeholder="7" 380 class="input-text regular-input" 381 style="width: 150px;" 382 /> 383 <p style="color: #666; font-size: 11px; margin-top: 5px;"> 384 ' . __('Dejar vacío para usar el rango automático. Solo configure si necesita un gap entre rangos (ej: Premier hasta 6kg, Industrial desde 7kg).') . ' 385 </p> 386 </fieldset> 387 </td> 388 </tr>'; 389 301 390 $htmlGeneral .= '<tr valign="top"> 302 391 <td style="width:25%;font-weight:bold;"> -
shipping-servientrega-woocommerce/trunk/includes/class-method-shipping-servientrega-wc.php
r3037317 r3457385 34 34 $this->servientrega_print_type = isset($wc_main_settings['servientrega_print_type']) ? $wc_main_settings['servientrega_print_type'] : 2; 35 35 $this->rates_servientrega = isset($wc_main_settings['rate']) ? $wc_main_settings['rate'] : []; 36 // Cargar configuración de rangos de peso. 37 $this->servientrega_premier_max_weight = isset($wc_main_settings['servientrega_premier_max_weight']) ? floatval($wc_main_settings['servientrega_premier_max_weight']) : 0; 38 $this->servientrega_industrial_min_weight = isset($wc_main_settings['servientrega_industrial_min_weight']) ? floatval($wc_main_settings['servientrega_industrial_min_weight']) : 0; 36 39 37 40 $this->supports = array( … … 195 198 public function calculate_cost(array $data_products, $origin, $destine) 196 199 { 200 // Determinar el tipo de producto basado en el peso. 201 $product_type = Shipping_Servientrega_WC::determine_product_type_by_weight( 202 $data_products['weight'], 203 $this->servientrega_product_type 204 ); 205 197 206 $params = [ 198 'IdProducto' => $ this->servientrega_product_type,199 'NumeroPiezas' => $ this->servientrega_product_type === 6 ? count($data_products['pieces']) : 1,200 'Piezas' => $ this->servientrega_product_type === 6 ? $data_products['pieces'] :207 'IdProducto' => $product_type, 208 'NumeroPiezas' => $product_type === 6 ? count($data_products['pieces']) : 1, 209 'Piezas' => $product_type === 6 ? $data_products['pieces'] : 201 210 [ 202 211 [ -
shipping-servientrega-woocommerce/trunk/includes/class-shipping-servientrega-wc.php
r3311655 r3457385 137 137 $namesProducts = implode(" ", $data_products['name_products']); 138 138 139 // Determinar tipo de producto basado en peso del pedido. 140 $product_type_by_weight = self::determine_product_type_by_weight( 141 $data_products['weight'], 142 $instance->servientrega_product_type 143 ); 144 139 145 $params = [ 140 146 'Num_Guia' => 0, … … 142 148 'Num_Piezas' => count($data_products['units']), 143 149 'Des_TipoTrayecto' => 1, //nacional 2 internacional 144 'Ide_Producto' => (int)$ instance->servientrega_product_type, //mercancia premier150 'Ide_Producto' => (int)$product_type_by_weight, 145 151 'Ide_Destinatarios' => '00000000-0000-0000-0000-000000000000', 146 152 'Ide_Manifiesto' => '00000000-0000-0000-0000-000000000000', … … 191 197 $order_id_origin = self::get_parent_id($order); 192 198 193 if($ instance->servientrega_product_type== 6){199 if($product_type_by_weight == 6){ 194 200 $params['objEnviosUnidadEmpaqueCargue'] = [ 195 201 'EnviosUnidadEmpaqueCargue' => $data_products['units'] … … 370 376 } 371 377 378 /** 379 * Determina el tipo de producto basándose en el peso y la configuración de rangos. 380 * 381 * @param float $weight Peso en kilogramos del pedido. 382 * @param int $manual_type Tipo de producto seleccionado manualmente (1, 2 o 6). 383 * @return int Tipo de producto a usar (1, 2 o 6). 384 */ 385 public static function determine_product_type_by_weight(float $weight, int $manual_type): int 386 { 387 // Si es tipo 1 (Documento unitario), siempre usar el manual. 388 if ($manual_type == 1) { 389 return 1; 390 } 391 392 // Obtener configuración de rangos de peso. 393 $wc_settings = get_option('woocommerce_servientrega_shipping_settings'); 394 $premier_max_weight = isset($wc_settings['servientrega_premier_max_weight']) 395 ? floatval($wc_settings['servientrega_premier_max_weight']) 396 : 0; 397 $industrial_min_weight = isset($wc_settings['servientrega_industrial_min_weight']) 398 ? floatval($wc_settings['servientrega_industrial_min_weight']) 399 : 0; 400 401 // Si no hay configuración de rangos, usar el tipo manual. 402 if ($premier_max_weight <= 0) { 403 return (int)$manual_type; 404 } 405 406 // Determinar el peso mínimo para Industrial. 407 // Si no está configurado, usar premier_max + 0.1. 408 if ($industrial_min_weight <= 0) { 409 $industrial_min_weight = $premier_max_weight + 1; 410 } 411 412 // Aplicar lógica de rangos. 413 if ($weight <= $premier_max_weight) { 414 return 2; // Mercancía Premier. 415 } elseif ($weight >= $industrial_min_weight) { 416 return 6; // Mercancía Industrial. 417 } 418 419 // Si está en el gap entre rangos, usar el tipo manual. 420 return (int)$manual_type; 421 } 422 372 423 public static function generate_stickers($guide_number) 373 424 { … … 523 574 524 575 } 576 577 578 -
shipping-servientrega-woocommerce/trunk/readme.txt
r3311699 r3457385 4 4 Tags: commerce, e-commerce, commerce, WordPress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, Colombia, servientrega 5 5 Requires at least: 6.0 6 Tested up to: 6.8.1 7 Requires PHP: 8.1 8 Stable tag: 7.0.6 6 Tested up to: 6.9 7 Requires PHP: 8.2 8 Stable tag: 7.0.7 9 WC requires at least: 9.0 10 WC tested up to: 10.4 9 11 License: GNU General Public License v3.0 10 12 License URI: http://www.gnu.org/licenses/gpl-3.0.html -
shipping-servientrega-woocommerce/trunk/shipping-servientrega-wc.php
r3311699 r3457385 3 3 * Plugin Name: Shipping Servientrega Woocommerce 4 4 * Description: Shipping Servientrega Woocommerce is available for Colombia 5 * Version: 7.0. 65 * Version: 7.0.7 6 6 * Author: Saúl Morales Pacheco 7 7 * Author URI: https://saulmoralespa.com 8 8 * License: GNU General Public License v3.0 9 9 * License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 * WC tested up to: 9.8.510 * WC tested up to: 10.4 11 11 * WC requires at least: 4.0 12 * Requires at least: 6.0 13 * Tested up to: 6.9 14 * Requires PHP: 8.2 15 * Requires Plugins: woocommerce,departamentos-y-ciudades-de-colombia-para-woocommerce 12 16 */ 13 17 … … 17 21 18 22 if(!defined('SHIPPING_SERVIENTREGA_WC_SS_VERSION')){ 19 define('SHIPPING_SERVIENTREGA_WC_SS_VERSION', '7.0. 6');23 define('SHIPPING_SERVIENTREGA_WC_SS_VERSION', '7.0.7'); 20 24 } 21 25 … … 30 34 ); 31 35 32 function shipping_servientrega_wc_ss_init() 36 function shipping_servientrega_wc_ss_init(): void 33 37 { 34 38 if ( ! shipping_servientrega_wc_ss_requirements() ) … … 39 43 } 40 44 41 function shipping_servientrega_wc_ss_notices( $notice ) { 45 function shipping_servientrega_wc_ss_notices( $notice ): void 46 { 42 47 ?> 43 48 <div class="error notice"> … … 47 52 } 48 53 49 function shipping_servientrega_wc_ss_requirements(){ 54 function shipping_servientrega_wc_ss_requirements(): bool 55 { 50 56 51 57 if ( ! function_exists( 'is_plugin_active' ) ) require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); … … 97 103 function() { 98 104 shipping_servientrega_wc_ss_notices( 'Shipping Servientrega Woocommerce requiere la extensión soap se encuentre instalada' ); 99 }100 );101 }102 return false;103 }104 105 if ( ! is_plugin_active(106 'woocommerce/woocommerce.php'107 ) ) {108 if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {109 add_action(110 'admin_notices',111 function() {112 shipping_servientrega_wc_ss_notices( 'Shipping Servientrega Woocommerce requiere que se encuentre instalado y activo el plugin: Woocommerce' );113 105 } 114 106 ); … … 168 160 $default_country = $woo_countries->get_base_country(); 169 161 170 if ( ! in_array( $default_country, array( 'CO' ), true )) {162 if ($default_country !== 'CO') { 171 163 if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { 172 164 add_action( … … 216 208 } 217 209 218 function activate_shipping_servientrega_wc_ss(){ 210 function activate_shipping_servientrega_wc_ss(): void 211 { 219 212 wp_schedule_event( time(), 'twicedaily', 'shipping_servientrega_wc_ss_schedule' ); 220 213 } 221 214 222 function deactivation_shipping_servientrega_wc_ss(){ 215 function deactivation_shipping_servientrega_wc_ss(): void 216 { 223 217 delete_option('servientrega_validation_error'); 224 218 wp_clear_scheduled_hook( 'shipping_servientrega_wc_ss_schedule' );
Note: See TracChangeset
for help on using the changeset viewer.