Plugin Directory

Changeset 3261412


Ignore:
Timestamp:
03/25/2025 10:08:46 AM (12 months ago)
Author:
seuroficial
Message:

v2.2.22

Location:
seur/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • seur/trunk/assets/css/seur-setting.css

    r1836328 r3261412  
    3636    padding-top: 13px;
    3737  }
     38
     39#seur_uploads_dir button {
     40    vertical-align: middle;
     41}
  • seur/trunk/assets/js/seur-custom-rates.js

    r2643080 r3261412  
    4848    var custom_rates_page_edit      = 'admin.php?page=seur_edit_rate&edit_id=';
    4949
     50    function validatePostcodeFormat(postcode) {
     51        const pattern = /^(\*|[A-Z0-9]+\*|[A-Z0-9]+\.\.[A-Z0-9]+|[A-Z0-9]+)$/i;
     52        return pattern.test(postcode);
     53    }
     54
     55    function validatePostcodes(postcodes) {
     56        const lines = postcodes.split("\n").map(line => line.trim()); // Separar por líneas y eliminar espacios
     57        return lines.every(line => validatePostcodeFormat(line)); // Verificar que todas las líneas sean válidas
     58    }
    5059
    5160    /* Data Insert Starts Here */
    5261
    5362    $(document).on('submit', '#emp-SaveForm', function() {
    54 
    55        $.post( custom_rates_page_create, $(this).serialize())
    56         .done(function(data){
     63        const postcode = document.getElementById("postcode").value;
     64        if (!validatePostcodes(postcode)) {
     65            event.preventDefault(); // Detiene el envío del formulario
    5766            $("#dis").fadeOut();
    58             $("#dis").fadeIn('slow', function(){
    59                  $("#dis").html('<div class="alert alert-info">'+data+'</div>');
    60                  $("#emp-SaveForm")[0].reset();
    61              });
    62          });
    63          return false;
     67            $("#dis").fadeIn('slow', function () {
     68                $("#dis").html('<div class="notice notice notice-error"><p>Postcode: Formato inválido</p></div>');
     69            });
     70        } else {
     71            $.post(custom_rates_page_create, $(this).serialize())
     72                .done(function (data) {
     73                    $("#dis").fadeOut();
     74                    $("#dis").fadeIn('slow', function () {
     75                        $("#dis").html('<div class="alert alert-info"><p>' + data + '</p></div>');
     76                        $("#emp-SaveForm")[0].reset();
     77                    });
     78                });
     79            return false;
     80        }
    6481    });
    6582    /* Data Insert Ends Here */
     
    93110        var id = $(this).attr("id");
    94111        var edit_id = id;
    95         if(confirm('Sure to Edit ID ' +edit_id))
    96         {
    97             $(".content-loader").fadeOut('slow', function()
    98              {
    99                 $(".content-loader").load( custom_rates_page_edit + edit_id );
    100                 $(".content-loader").delay( 3000 ).fadeIn('slow');
    101                 $("#btn-add").hide();
    102                 $("#btn-view").show();
    103             });
    104         }
    105         return false;
     112        $(".content-loader").fadeOut('slow', function()
     113         {
     114            $(".content-loader").load( custom_rates_page_edit + edit_id );
     115            $(".content-loader").delay( 3000 ).fadeIn('slow');
     116            $("#btn-add").hide();
     117            $("#btn-view").show();
     118        });
     119        return false;
    106120    });
    107121    /* Get Edit ID  */
     
    109123    /* Update Record  */
    110124    $(document).on('submit', '#emp-UpdateForm', function() {
    111 
    112        $.post( custom_rates_page_update , $(this).serialize())
    113         .done(function(data){
     125        const postcode = document.getElementById("postcode").value;
     126        if (!validatePostcodes(postcode)) {
     127            event.preventDefault(); // Detiene el envío del formulario
    114128            $("#dis").fadeOut();
    115             $("#dis").fadeIn('slow', function(){
    116                  $("#dis").html('<div class="alert alert-info">'+data+'</div>');
    117                  $("#emp-UpdateForm")[0].reset();
    118                  $("body").fadeOut('slow', function()
    119                  {
    120                     $("body").delay( 2000 ).fadeOut('slow');
    121                     window.location.href=custom_rates_page;
    122                  });
    123              });
    124         });
    125         return false;
     129            $("#dis").fadeIn('slow', function () {
     130                $("#dis").html('<div class="notice notice notice-error"><p>Postcode: Formato inválido</p></div>');
     131            });
     132        } else {
     133            edit_id = $(this).find('input[name="id"]').val();
     134            $.post(custom_rates_page_update, $(this).serialize())
     135            .done(function (data) {
     136                $("#dis").fadeOut();
     137                $("#dis").fadeIn('slow', function () {
     138                    $("#dis").html('<div class="alert alert-info">' + data + '</div>');
     139                    $("#emp-UpdateForm")[0].reset();
     140                });
     141            });
     142            return false;
     143        }
    126144    });
    127145    /* Update Record  */
  • seur/trunk/classes/class-seur-global.php

    r3254005 r3261412  
    10711071    public function is_seur_order($order_id) {
    10721072        global $wpdb;
     1073        global $post;
    10731074        $sql = $wpdb->prepare(
    1074             "SELECT distinct o.order_id
    1075             FROM {$wpdb->prefix}woocommerce_order_items o
    1076             inner join {$wpdb->prefix}woocommerce_order_itemmeta om on om.order_item_id = o.order_item_id
    1077             where om.meta_key = %s and (om.meta_value like %s)
    1078             AND o.order_id = %d",
    1079             ['method_id', 'seur', $order_id]
     1075            "SELECT distinct o.order_id
     1076            FROM {$wpdb->prefix}woocommerce_order_items o
     1077            inner join {$wpdb->prefix}woocommerce_order_itemmeta om on om.order_item_id = o.order_item_id
     1078            where om.meta_key = %s and (om.meta_value like %s)
     1079            AND o.order_id = %d
     1080            UNION
     1081            SELECT distinct p.ID
     1082            FROM {$wpdb->prefix}posts p
     1083            inner join {$wpdb->prefix}postmeta m on m.post_id = p.ID
     1084            where post_type = %s
     1085            and meta_key like %s
     1086            and ID = %d",
     1087            ['method_id', 'seur', $order_id, 'shop_order', 'shipping', $post->ID]
    10801088        );
    10811089        $sql = str_replace('seur', '%seur%', $sql);
     1090        $sql = str_replace('shipping', '_seur_shipping%', $sql);
     1091
    10821092        $result = $wpdb->get_results($sql);
    10831093        return !empty($result);
  • seur/trunk/core/defines/defines-loader.php

    r3119152 r3261412  
    2828define( 'SEUR_TBL_SCR', 'seur_custom_rates' );
    2929define( 'SEUR_CLASSES', SEUR_PLUGIN_PATH . 'core/classes/' );
    30 
     30define('SEUR_RATES_POSTALCODE_DESCRIPTION', esc_html__('Postcodes containing wildcards (e.g. CB23*) or fully numeric ranges (e.g. 90210..99000) are also supported. ', 'seur'));
    3131
    3232if ( ! defined( 'SEUR_DEBUG' ) ) {
  • seur/trunk/core/functions/functions.php

    r3254005 r3261412  
    149149    wp_enqueue_script( 'seur-tooltip', SEUR_PLUGIN_URL . 'assets/js/tooltip.js', array( 'jquery-ui-tooltip' ), SEUR_OFFICIAL_VERSION );
    150150    wp_enqueue_script( 'seur-switchery', SEUR_PLUGIN_URL . 'assets/js/switchery.min.js', array(), SEUR_OFFICIAL_VERSION );
     151    wp_enqueue_script( 'seur-admin', SEUR_PLUGIN_URL . 'assets/js/seur-advanced-settings.js', array(), SEUR_OFFICIAL_VERSION );
    151152}
    152153
     
    603604           FROM $table
    604605           WHERE type = %s
    605              AND (country = %s)
     606             AND country = %s
    606607             AND (state = %s OR state = '*')
    607              AND (postcode = %s OR postcode = '*')
    608608             AND (min".$type." <= %f AND max".$type." > %f)
    609609           LIMIT 1),
     
    615615           WHERE type = %s
    616616             AND (country = %s OR country = '*')
    617              AND (state = %s)
    618              AND (postcode = %s OR postcode = '*')
    619              AND (min".$type." <= %f AND max".$type." > %f)
    620            LIMIT 1),
    621           '*'
    622       )
    623       AND postcode = COALESCE(
    624           (SELECT %s
    625            FROM $table
    626            WHERE type = %s
    627              AND (country = %s OR country = '*')
    628              AND (state = %s OR state = '*')
    629              AND (postcode = %s)
     617             AND state = %s
    630618             AND (min".$type." <= %f AND max".$type." > %f)
    631619           LIMIT 1),
     
    639627        $query,
    640628        $type,
    641         $country,  $type, $country, $state, $postcode, $price_weight, $price_weight,
    642         $state,    $type, $country, $state, $postcode, $price_weight, $price_weight,
    643         $postcode, $type, $country, $state, $postcode, $price_weight, $price_weight,
     629        $country,  $type, $country, $state, $price_weight, $price_weight,
     630        $state,    $type, $country, $state, $price_weight, $price_weight,
    644631        $price_weight, $price_weight
    645632    );
     
    647634    $results = $wpdb->get_results($query, 'ARRAY_A');
    648635
     636    // Filtrar resultados
     637    $filteredResults = array_filter($results, function ($row) use ($postcode) {
     638        return matchPostcode($postcode, $row['postcode']);
     639    });
     640
    649641    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
    650642        $log = new WC_Logger();
    651         $log->add( 'seur', 'Tarifas disponibles encontradas: ' . print_r( $results, true ) );
    652     }
    653 
    654     return $results;
    655 }
    656 
     643        $log->add( 'seur', 'Tarifas disponibles encontradas: ' . print_r( $filteredResults, true ) );
     644    }
     645    return $filteredResults;
     646}
     647
     648function matchPostcode($postcode, $rules) {
     649    $rules = explode("\n", $rules); // Separar líneas en un array
     650
     651    foreach ($rules as $rule) {
     652        $rule = trim($rule);
     653
     654        // Comprobación por prefijo (ejemplo: 00*)
     655        if (str_ends_with($rule, '*')) {
     656            $prefix = rtrim($rule, '*');
     657            if (strpos($postcode, $prefix) === 0) {
     658                return true; // Coincidencia con prefijo
     659            }
     660        }
     661
     662        // Comprobación por rango (ejemplo: 11001..11012)
     663        if (strpos($rule, '..') !== false) {
     664            [$start, $end] = explode('..', $rule);
     665            if ($postcode >= $start && $postcode <= $end) {
     666                return true; // Coincidencia con el rango
     667            }
     668        }
     669
     670        // Coincidencia exacta
     671        if ($postcode === $rule) {
     672            return true;
     673        }
     674    }
     675
     676    return false; // No hay coincidencia
     677}
    657678/**
    658679 * SEUR Get User Settings
     
    12401261        $order->update_meta_data('_seur_shipping_order_label_downloaded', 'yes');
    12411262        $order->update_meta_data('_seur_shipping_packages', $numpackages);
    1242         $order->update_meta_data('_seur_shipping_weight', $weight);
     1263        $order->update_meta_data('_seur_shipping_weight', $labelData['customer_weight']);
    12431264        $order->update_meta_data('_seur_shipping_change_service', $changeService);
    12441265        $order->save_meta_data();
     
    13801401    $preparedData['customer_city']        = seur_clean_data( $order_data[0]['city'] );
    13811402    $preparedData['customer_postcode']    = $order_data[0]['postcode'];
    1382     $preparedData['customer_weight']      = $order_data[0]['weight'];
     1403    $preparedData['customer_weight']      = $order_data[0]['weight'] ?: $weight;
    13831404    $preparedData['customer_first_name']  = seur_clean_data( $order_data[0]['first_name'] );
    13841405    $preparedData['customer_last_name']   = seur_clean_data( $order_data[0]['last_name'] );
     
    17491770function seur_get_order_weight($order) {
    17501771    $label_ids = seur_get_labels_ids($order->get_id());
     1772
    17511773    $weight = $order->get_meta('_seur_shipping_weight') ?:
    17521774        isset($label_ids[0]) && get_post_meta($label_ids[0], '_seur_shipping_weight', true) ?:
    17531775        $order->get_meta('_seur_cart_weight', true);
    1754     $order->update_meta_data('_seur_shipping_weight', $weight);
    1755     $order->update_meta_data('_seur_cart_weight', $weight);
    1756     $order->save_meta_data();
    1757     if ($label_ids) {
    1758         update_post_meta($label_ids[0], '_seur_shipping_weight', $weight);
     1776    if ($weight) {
     1777        $order->update_meta_data('_seur_shipping_weight', $weight);
     1778        $order->update_meta_data('_seur_cart_weight', $weight);
     1779        $order->save_meta_data();
     1780        if ($label_ids) {
     1781            update_post_meta($label_ids[0], '_seur_shipping_weight', $weight);
     1782        }
    17591783    }
    17601784    return $weight;
    17611785}
     1786
     1787function seur_regenerate_upload_dir_callback() {
     1788    // Asegurar que WordPress está cargado
     1789    if (!defined('ABSPATH')) {
     1790        exit;
     1791    }
     1792
     1793    // Incluir el archivo PHP que realiza la acción
     1794    $file_path = SEUR_PLUGIN_PATH . 'core/pages/regenerate-upload-dir.php';
     1795
     1796    if (file_exists($file_path)) {
     1797        ob_start();
     1798        include $file_path;
     1799        $output = ob_get_clean();
     1800        echo $output;
     1801    } else {
     1802        echo "Error: No se encontró el archivo de procesamiento.";
     1803    }
     1804
     1805    wp_die(); // Importante para que WordPress finalice correctamente el AJAX
     1806}
     1807add_action('wp_ajax_seur_regenerate_upload_dir', 'seur_regenerate_upload_dir_callback');
     1808
     1809
     1810function validatePostcodeFormat($postcode) {
     1811    /*
     1812    Un asterisco solo
     1813    Prefijo alfanumérico seguido de *
     1814    Dos valores alfanuméricos separados por ..
     1815    Un valor alfanumérico sin * ni ..
     1816    */
     1817    $pattern = '/^(\*|[A-Z0-9]+\*|[A-Z0-9]+\.\.[A-Z0-9]+|[A-Z0-9]+)$/i';
     1818    return preg_match($pattern, $postcode);
     1819}
     1820
     1821function validatePostcodes($postcodes) {
     1822    $lines = explode("\n", $postcodes);
     1823
     1824    foreach ($lines as $line) {
     1825        $line = trim($line);
     1826        if (!validatePostcodeFormat($line)) {
     1827            return false;
     1828        }
     1829    }
     1830    return true;
     1831}
  • seur/trunk/core/installer.php

    r3179024 r3261412  
    3636            country varchar(50) NOT NULL default '',
    3737            state varchar(200) NOT NULL default '',
    38             postcode varchar(7) NOT NULL default '00000',
     38            postcode varchar(200) NOT NULL default '*',
    3939            minprice decimal(20,2) unsigned NOT NULL default '0.00',
    4040            maxprice decimal(20,2) unsigned NOT NULL default '0.00',
     
    866866        update_option( 'seur_aduana_origen_field', 'D' );
    867867        update_option( 'seur_aduana_destino_field', 'D' );
    868         update_option( 'seur_tipo_mercancia_field', 'C' );
    869         update_option( 'seur_id_mercancia_field', '400' );
    870         update_option( 'seur_descripcion_field', 'MANUFACTURAS DIVERSAS' );
     868        update_option( 'seur_tipo_mercancia_field', 'C' );
     869        update_option( 'seur_id_mercancia_field', '400' );
     870        update_option( 'seur_descripcion_field', 'MANUFACTURAS DIVERSAS' );
    871871        update_option( 'seur_add_advanced_settings_field_pre', '1' );
    872872    }
     
    874874}
    875875
     876function seur_upgrade_2222() {
     877    seur_upgrade_db_105();
     878}
     879
     880function seur_upgrade_db_105() {
     881    global $wpdb;
     882    $table_name = $wpdb->prefix . 'seur_custom_rates';
     883    $column_name = 'postcode';
     884
     885    // Verificar si la columna 'postcode' existe antes de modificarla
     886    $column_exists = $wpdb->get_results("SHOW COLUMNS FROM `$table_name` LIKE '$column_name'");
     887    if (!empty($column_exists)) {
     888        // Modificar la columna 'postcode' a VARCHAR(200) con valor por defecto '*'
     889        $wpdb->query("ALTER TABLE `$table_name` MODIFY `$column_name` VARCHAR(200) NOT NULL DEFAULT '*'");
     890        update_option('seur_db_version', SEUR_DB_VERSION);
     891    }
     892}
     893
     894function seur_run_upgrade() {
     895    $current_version = get_option('seur-official-version', '2.1.1');
     896
     897    if (version_compare($current_version, '2.2.22', '<')) {
     898        seur_upgrade_2222();
     899        update_option('seur-official-version', '2.2.22');
     900    }
     901}
     902
     903seur_run_upgrade();
  • seur/trunk/core/labels-cpt/labels-cpt.php

    r3234068 r3261412  
    251251    $customer_city     = seur_clean_data( $order_data[0]['city'] );
    252252    $customer_postcode = $order_data[0]['postcode'];
    253     $customer_weight  = $order_data[0]['weight'];
    254 
    255     if ( ! $customer_weight ) {
    256         $customer_weight = $weight;
    257     }
    258 
     253    $customer_weight  = $order_data[0]['weight'] ?: $weight;
    259254    $customer_address_1   = seur_clean_data( $order_data[0]['address_1'] );
    260255    $customer_address_2   = seur_clean_data( $order_data[0]['address_2'] );
     
    334329                    </p>
    335330
    336                 </div>
    337 
     331                </div>
     332
     333                <p><strong><?php esc_html_e('Weight: ','seur');?></strong></p><?php echo esc_html( $customer_weight ); ?>
    338334                <p>
    339335                    <strong><?php esc_html_e( 'Customer notes about Order: ', 'seur' ); ?></strong><br />
  • seur/trunk/core/pages/rates/seur-add-form.php

    r3176965 r3261412  
    7676            </tr>
    7777            <tr>
    78                 <td id="postcode"><?php esc_html_e( 'Postcode', 'seur' ); ?></td>
    79                 <td><input title="<?php esc_html_e( 'Type a Postcode', 'seur' ); ?>" type='text' name='postcode' class='form-control' placeholder='EX : 08023' required=""></td>
     78                <td><?php esc_html_e( 'Postcode', 'seur' ); ?></td>
     79                <td><textarea title="<?php esc_html_e( 'Type a Postcode', 'seur' ); ?>" name="postcode" id="postcode" placeholder="<?php echo esc_html("List 1 postcode per line");?>" class="form-control" cols="29" rows="5" required=""></textarea>
     80                    <br><span class="description"><?php echo SEUR_RATES_POSTALCODE_DESCRIPTION . esc_html__('Add 1 per line'); ?></span>
     81                </td>
    8082            </tr>
    8183            <tr>
  • seur/trunk/core/pages/rates/seur-create-rate.php

    r3119152 r3261412  
    3333            $seur_rateprice = sanitize_text_field( wp_unslash( $_POST['rateprice'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    3434            $seur_rate_type = sanitize_text_field( wp_unslash( $_POST['rate_type'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    35             $seur_postcode  = seur_sanitize_postcode( sanitize_text_field( wp_unslash( $_POST['postcode'] ) ), $seur_country ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
     35            $seur_postcode  = sanitize_textarea_field( wp_unslash( $_POST['postcode'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    3636
    3737            if ( empty( $seur_city ) ) {
     
    4646            if ( empty( $seur_postcode ) || '00000' === $seur_postcode || '0000' === $seur_postcode || '*' === $seur_postcode ) {
    4747                $seur_postcode = '*';
    48             }
     48            } else {
     49                if (!validatePostcodes($seur_postcode)) {
     50                    echo '<div class="notice notice-error"><p>' . esc_html__( 'The postcode is not valid', 'seur' ) . '</p></div>';
     51                    exit;
     52                }
     53            }
    4954            if ( empty( $seur_rateprice ) ) {
    5055                $seur_rateprice = '0';
  • seur/trunk/core/pages/rates/seur-edit-form.php

    r3183810 r3261412  
    3838    // translators: %s is the type of rate (e.g., weight, price).
    3939    $title_max = sprintf( __( 'The product %s is less than this field', 'seur' ), esc_html( $rates_type ) );
     40    ?>
    4041
    41 
    42     ?>
    43     <style type="text/css">
    44     #dis{
    45         display:none;
    46     }
    47     </style>
    4842    <div id="dis">
    4943    </div>
     44
    5045    <form method='post' id='emp-UpdateForm' action='#'>
    5146        <table class='table table-bordered'>
     
    141136            <tr>
    142137                <td><?php esc_html_e( 'Postcode', 'seur' ); ?></td>
    143                 <td><input title="<?php esc_html_e( 'SEUR field description', 'seur' ); ?>" type='text' name='postcode' value='<?php echo esc_html( $getrate->postcode ); ?>' class='form-control' placeholder='EX : 08023' required=""></td>
     138                <td><textarea title="<?php esc_html_e( 'Type a Postcode', 'seur' ); ?>" name="postcode" id="postcode" class="form-control" cols="29" rows="5" required=""><?php echo esc_html( $getrate->postcode ); ?></textarea>
     139                    <br><span class="description"><?php echo SEUR_RATES_POSTALCODE_DESCRIPTION . esc_html__('Add 1 per line'); ?></span>
     140                </td>
    144141            </tr>
    145142            <tr>
     
    168165    <?php
    169166}
     167//seur_search_availables_rates('ES','*', '*', 0.5);
  • seur/trunk/core/pages/rates/seur-import-custom-rates.php

    r3254005 r3261412  
    9999    $output = fopen( 'php://output', 'w' );
    100100
     101    // Reemplazar los saltos de línea en los códigos postales para exportar
    101102    // Eliminar las columnas "created_at" y "updated_at"
    102103    foreach ( $rates as &$row ) {
     104        $row['postcode'] = str_replace("\r\n", "|", $row['postcode']);
    103105        unset( $row['created_at'], $row['updated_at'] );
    104106    }
     
    154156            // Leer el resto del archivo línea por línea
    155157            foreach ( $csv_lines as $line ) {
     158                if (empty($line)) {
     159                    break;
     160                }
    156161                $data   = str_getcsv( $line );
    157162                $record = array_combine( $header, $data );
     
    190195                    }
    191196                }
     197
     198                // Validar el campo postcode si no está vacío
     199                if (!empty($record['postcode'])) {
     200                    $record_postcode = $record['postcode'];
     201                    if (strpos($record['postcode'], "|") !== false) {
     202                        $record['postcode'] = str_replace("|", "\r\n", $record['postcode']);
     203                    }
     204                    if (!validatePostcodes($record['postcode'])) {
     205                        $error_messages[] = "El valor de postcode '{$record_postcode}' no tiene formato válido.";
     206                    }
     207                }
    192208
    193209                // Verificar si el ID existe
     
    284300        <li><strong>country</strong>: País al que se aplica la tarifa. Use "*" para aplicar a todos los países.</li>
    285301        <li><strong>state</strong>: Estado o provincia al que se aplica la tarifa. Use "*" para aplicar a todos los estados.</li>
    286         <li><strong>postcode</strong>: Código postal al que se aplica la tarifa.</li>
     302        <li><strong>postcode</strong>: Código postal al que se aplica la tarifa. <?php echo SEUR_RATES_POSTALCODE_DESCRIPTION .' Separar los valores con "|", por ejemplo: 01*|02*|03001..03010'; ?></li>
    287303        <li><strong>minprice</strong>: Precio mínimo para aplicar la tarifa.</li>
    288304        <li><strong>maxprice</strong>: Precio máximo para aplicar la tarifa.</li>
  • seur/trunk/core/pages/rates/seur-update.php

    r3119152 r3261412  
    3333            $seur_rateprice = sanitize_text_field( wp_unslash( $_POST['rateprice'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    3434            $seur_rate_type = sanitize_text_field( wp_unslash( $_POST['rate_type'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    35             $seur_postcode  = sanitize_text_field( wp_unslash( $_POST['postcode'] ), $seur_country ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
     35            $seur_postcode  = sanitize_textarea_field( wp_unslash( $_POST['postcode'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
    3636
    3737            if ( empty( $seur_minprice ) ) {
     
    4040            if ( empty( $seur_postcode ) || '00000' === $seur_postcode || '0000' === $seur_postcode || '*' === $seur_postcode ) {
    4141                $seur_postcode = '*';
    42             }
     42            } else {
     43                if (!validatePostcodes($seur_postcode)) {
     44                    echo '<div class="notice notice notice-error"><p>' . esc_html__( 'The postcode is not valid', 'seur' ) . '</p></div>';
     45                    exit;
     46                }
     47            }
    4348            if ( empty( $seur_rateprice ) ) {
    4449                $seur_rateprice = '0';
  • seur/trunk/core/pages/setting-options/advanced-settings.php

    r3176965 r3261412  
    205205    <input title="<?php esc_html_e( 'SEUR field description', 'seur' ); ?>" type="text" name="seur_descripcion_field" value="<?php echo esc_html( seur()->get_option( 'seur_descripcion_field' ) ); ?>" size="40" />
    206206    <?php
     207}
     208
     209
     210function seur_uploads_dir_field() {
     211    $uploads_dir = seur()->get_option('seur_uploads_dir');
     212    if (!file_exists($uploads_dir)) {
     213        echo '<div id="seur_uploads_dir">'.esc_html('Directory not found').'&nbsp;
     214                <button type="button" class="button" onclick="seur_create_upload_folder_ajax()">'.esc_html('Regenerate folder').'</button>
     215              </div>';
     216    } else {
     217        echo '<div id="seur_uploads_dir">'.esc_html($uploads_dir).'</div>';
     218        if (!is_writable($uploads_dir)) {
     219            echo '<br><strong>'.esc_html('Directory is not writable').'!!!</strong>';
     220        }
     221    }
    207222}
    208223
     
    227242    add_settings_field( 'seur_id_mercancia_field', esc_html__( 'ID of goods', 'seur' ), 'seur_id_mercancia_field', 'seur-advanced-settings-options', 'seur-advanced-settings-section' );
    228243    add_settings_field( 'seur_descripcion_field', esc_html__( 'International description', 'seur' ), 'seur_descripcion_field', 'seur-advanced-settings-options', 'seur-advanced-settings-section' );
     244    add_settings_field( 'seur_uploads_dir', esc_html__( 'Upload directory', 'seur' ), 'seur_uploads_dir_field', 'seur-advanced-settings-options', 'seur-advanced-settings-section' );
    229245
    230246    // register all setings.
     
    244260    register_setting( 'seur-advanced-settings-section', 'seur_id_mercancia_field' );
    245261    register_setting( 'seur-advanced-settings-section', 'seur_descripcion_field' );
     262    register_setting( 'seur-advanced-settings-section', 'seur_uploads_dir' );
    246263
    247264}
  • seur/trunk/core/woocommerce/includes/seur-woo-functions.php

    r3254005 r3261412  
    2121    return $return;
    2222}
     23
    2324// Store cart weight in the database.
    24 /*********************************************
    25  * COMMENT THIS CODE WHILE WOOCOMMERCE RESOLVE THE BUG
    26  * woocommerce_checkout_update_order_meta not hiring with new WC Checkout Block
    27  ********************************************/
    28 /* add_action( 'woocommerce_checkout_update_order_meta', 'seur_add_cart_weight' );
    29 function seur_add_cart_weight( $order_id )
     25add_action( 'woocommerce_update_order', 'seur_add_cart_weight_hpos' );
     26function seur_add_cart_weight_hpos( $order_id )
    3027{
    31     $order = new WC_Order( $order_id );
    32 
    33     $ship_methods = maybe_unserialize( $order->get_shipping_methods() );
    34     foreach ( $ship_methods as $ship_method ) {
    35         $product_name = $ship_method['name'];
    36     }
    37 
    38     $products = seur()->get_products();
    39     foreach ( $products as $code => $product ) {
    40         $custom_name = get_option($product['field'].'_custom_name_field')?get_option($product['field'].'_custom_name_field'):$code;
    41         if ($custom_name == $product_name) {
    42             $order->update_meta_data('_seur_shipping', 'seur' );
    43             $order->update_meta_data('_seur_shipping_method_service_real_name', $code );
    44             $order->update_meta_data('_seur_shipping_method_service', sanitize_title( $product_name ) );
    45             break;
     28    if (WC()->cart) {
     29        $order = new WC_Order($order_id);
     30
     31        $ship_methods = maybe_unserialize($order->get_shipping_methods());
     32        foreach ($ship_methods as $ship_method) {
     33            $product_name = $ship_method['name'];
    4634        }
    47     }
    48 
    49     $weight = WC()->cart->cart_contents_weight;
    50     $order->update_meta_data('_seur_cart_weight', $weight );
    51     $order->save_meta_data();
    52 } */
    53 /*********************************************
    54  * ADDED THIS ACTION WHILE WOOCOMMERCE RESOLVE THE BUG
    55  * woocommerce_checkout_update_order_meta not hiring with new WC Checkout Block
    56  ********************************************/
    57 add_action( 'woocommerce_thankyou', 'seur_add_cart_weight_bis' );
    58 function seur_add_cart_weight_bis( $order_id )
    59 {
    60     if (!is_numeric($order_id)) {
    61         return;
    62     }
    63 
    64     $order = new WC_Order( $order_id );
    65     $ship_methods = maybe_unserialize( $order->get_shipping_methods() );
    66     foreach ( $ship_methods as $ship_method ) {
    67         $product_name = $ship_method['name'];
    68     }
    69 
    70     $products = seur()->get_products();
    71     foreach ( $products as $code => $product ) {
    72         $custom_name = get_option($product['field'].'_custom_name_field')?get_option($product['field'].'_custom_name_field'):$code;
    73         if ($custom_name == $product_name) {
    74             $order->update_meta_data('_seur_shipping', 'seur' );
    75             $order->update_meta_data('_seur_shipping_method_service_real_name', $code );
    76             $order->update_meta_data('_seur_shipping_method_service', sanitize_title( $product_name ) );
    77             break;
     35
     36        $products = seur()->get_products();
     37        foreach ($products as $code => $product) {
     38            $custom_name = get_option($product['field'] . '_custom_name_field') ? get_option($product['field'] . '_custom_name_field') : $code;
     39            if ($custom_name == $product_name) {
     40                $order->update_meta_data('_seur_shipping', 'seur');
     41                $order->update_meta_data('_seur_shipping_method_service_real_name', $code);
     42                $order->update_meta_data('_seur_shipping_method_service', sanitize_title($product_name));
     43                break;
     44            }
    7845        }
    79     }
    80 
    81     // Compute total order weight if not computed already (by seur_add_cart_weight())
    82     if ( empty($order->get_meta('_seur_cart_weight')) ) {
    83         $items        = $order->get_items();
    84         $total_weight = 0.0;
    85         foreach ( $items as $item ) {
    86             $hidden = $item->get_meta( '_bundled_item_hidden' );
    87             // Do not add the hidden items inside the pack
    88             if ( $hidden != 'yes' ) {
    89                 $product_quantity = $item->get_quantity();
    90                 $product_weight   = $item->get_product()->get_weight(); // Obtiene el peso del producto
    91                 $total_weight    += (float) $product_weight * (float) $product_quantity;
    92             }
    93         }
    94 
    95         $order->update_meta_data( '_seur_cart_weight', $total_weight );
    96     }
    97 
    98     $order->save_meta_data();
    99 }
    100 // When the event woocommerce_checkout_update_order_meta is triggered we can obtain the cart weight
    101 // from Woocommerce (which should more accurate that any calculation we can perform).
    102 // But the event is not triggered in all versions (see bug), so there is a second point where weight is computed (above).
     46
     47        $weight = WC()->cart->cart_contents_weight;
     48        $order->update_meta_data('_seur_cart_weight', $weight);
     49        $order->save_meta_data();
     50    }
     51}
    10352add_action('woocommerce_checkout_update_order_meta', 'seur_add_cart_weight');
    10453function seur_add_cart_weight( $order_id ) {
     
    13382    global $post;
    13483    if ( $column == 'total_weight' ) {
    135         $weight = get_post_meta( $post->ID, '_seur_cart_weight', true );
     84        $weight = get_post_meta( $post->ID, '_seur_cart_weight', true ) ?:
     85            get_post_meta($post->ID, '_seur_shipping_weight', true);
    13686        if ( $weight > 0 ) {
    13787            print esc_html( $weight ) . ' ' . esc_attr( get_option( 'woocommerce_weight_unit' ) );
     
    14393function seur_custom_order_weight_column_hpos( $column, $order) {
    14494    if ( $column == 'total_weight' ) {
    145         $weight = $order->get_meta(  '_seur_cart_weight', true );
     95        $weight = $order->get_meta(  '_seur_cart_weight', true ) ?:
     96            $order->get_meta('_seur_shipping_weight', true);
    14697        if ( $weight > 0 ) {
    14798            print esc_html( $weight ) . ' ' . esc_attr( get_option( 'woocommerce_weight_unit' ) );
     
    313264    $action        = $wp_list_table->current_action();
    314265
    315     if ( ! isset( $_REQUEST['id'] ) ) {
     266    if (isset($_REQUEST['id'])) {
     267        $post_ids      = array_map( 'absint', (array) $_REQUEST['id'] );
     268    }
     269    if (isset($_REQUEST['post'])) {
     270        $post_ids      = array_map( 'absint', (array) $_REQUEST['post'] );
     271    }
     272    if (!isset($post_ids)) {
    316273        return;
    317274    }
    318275
    319     $post_ids      = array_map( 'absint', (array) $_REQUEST['id'] );
    320276    $report_action = 'marked_seur-createlabel';
    321277
  • seur/trunk/languages/seur-es_ES.po

    r3159775 r3261412  
    14711471#: core/pages/rates/seur-country-state-process.php:103
    14721472msgid "EX : State"
    1473 msgstr "Ej: Estado"
     1473msgstr "Ej: Provincia"
    14741474
    14751475#: core/pages/rates/seur-country-state-process.php:69
    14761476msgid "Type State"
    1477 msgstr "Escribir estado"
     1477msgstr "Escribir Provincia"
    14781478
    14791479#: core/pages/rates/seur-country-state-process.php:62
     
    14811481#: core/pages/rates/seur-edit-form.php:128
    14821482msgid "All States"
    1483 msgstr "Todos los estados"
     1483msgstr "Todas las provincias"
    14841484
    14851485#: core/pages/rates/seur-country-state-process.php:61
     
    14891489#: core/pages/rates/seur-edit-form.php:127
    14901490msgid "Select State"
    1491 msgstr "Selecciona un Estado"
     1491msgstr "Selecciona una Provincia"
    14921492
    14931493#: core/pages/rates/seur-country-state-process.php:39
     
    15581558#: core/pages/rates/seur-edit-form.php:145
    15591559msgid "State"
    1560 msgstr "Estado"
     1560msgstr "Provincia"
    15611561
    15621562#: core/pages/rates/seur-add-form.php:67
     
    17441744#: core/menu/menu.php:69
    17451745msgid "Process Country State"
    1746 msgstr "Procesar pays estado"
     1746msgstr "Procesar País Provincia"
    17471747
    17481748#: core/menu/menu.php:68
  • seur/trunk/loader.php

    r3254005 r3261412  
    44 * Plugin URI: http://www.seur.com/
    55 * Description: Add SEUR shipping method to WooCommerce. The SEUR plugin for WooCommerce allows you to manage your order dispatches in a fast and easy way
    6  * Version: 2.2.21
     6 * Version: 2.2.22
    77 * Author: SEUR Oficial
    88 * Author URI: http://www.seur.com/
     
    2020use Automattic\WooCommerce\Utilities\FeaturesUtil;
    2121
    22 define( 'SEUR_OFFICIAL_VERSION', '2.2.21' );
    23 define( 'SEUR_DB_VERSION', '1.0.4' );
     22define( 'SEUR_OFFICIAL_VERSION', '2.2.22' );
     23define( 'SEUR_DB_VERSION', '1.0.5' );
    2424define( 'SEUR_TABLE_VERSION', '1.0.5' );
    2525
  • seur/trunk/readme.txt

    r3254005 r3261412  
    44Requires at least: 4.0
    55Tested up to: 6.6.2
    6 Stable tag: 2.2.21
     6Stable tag: 2.2.22
    77WC requires at least: 3.0
    88WC tested up to: 9.1.4
     
    9393
    9494== Changelog ==
     95
     96== 2.2.22 ==
     97
     98* ADDED: Regenerate seur uploads dir option in settings
     99* ADDED: Add zip ranges feature
     100* FIXED: Fix no hpos orders to is_seur_order
     101* FIXED: Fix hpos labels weight
     102* FIXED: Fix bulk create label post legacy
    95103
    96104== 2.2.21 ==
Note: See TracChangeset for help on using the changeset viewer.