Plugin Directory

Changeset 3237693


Ignore:
Timestamp:
02/10/2025 07:49:29 AM (20 months ago)
Author:
enituretechnology
Message:

4.5.17

  • Update: Added a new "Review Plugin" button for improved user feedback and engagement.
  • Update: Override Rates Shipping Rule: added Negative & Percentage Service Rate.
  • Update: Restrict To Location Rule: Introduced filters support.
  • Update: Minimum Shipping Charge Rule: Implemented a new rule to set a minimum charge for shipping.
  • Update: Free Shipping Rule: Added functionality to allow free shipping conditions based on configured rules.
  • Fix: Export Products Functionality: Fixed issues with old nested material attributes of products to ensure accurate exports.
  • Fix:Security Enhancements: Resolved vulnerability issues for improved plugin security and compliance.
  • Fix:Request Parameters Sanitization: Improved sanitization in shipping rules to enhance data integrity

Tickets# 18045571351, 19164805467

Location:
small-package-quotes-ups-edition
Files:
93 added
1 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • small-package-quotes-ups-edition/trunk/css/ups-small-style.css

    r3136464 r3237693  
    422422/*estimated delivery options css*/
    423423tr.all_shipment_days_ups_small_tr {
    424     display: inline-block;
     424    display: inline-table;
    425425}
    426426
    … …  
    640640    padding: 0 !important;
    641641}
     642#en-woo-review-plugin {
     643    display: flex;
     644    justify-content: end;
     645}
     646#en-woo-review-plugin a {
     647    width: initial !important;
     648    height: auto !important;
     649    text-transform: initial !important;
     650    font-size: unset !important;
     651}
  • small-package-quotes-ups-edition/trunk/fdo/freightdesk-online-section.php

    r3159756 r3237693  
    4848    }
    4949}
    50 $message = wp_sprintf('<div class="user_guide_fdo">
     50$message = wp_sprintf('<div class="user_guide_fdo ups_small_wrapper">
    5151    <h2>Connect to FreightDesk Online.</h2>
    5252    <p>
  • small-package-quotes-ups-edition/trunk/fdo/validate-addresses-section.php

    r3159756 r3237693  
    1212$link_freight = '<a href="https://validate-addresses.com/" target="_blank">Learn more</a>';
    1313$link_register = '<a href="https://validate-addresses.com/register" target="_blank">click here</a>';
    14 $message = wp_sprintf('<div class="user_guide_fdo">
     14$message = wp_sprintf('<div class="user_guide_fdo ups_small_wrapper">
    1515    <h2>Connect to Validate Addresses.</h2>
    1616    <p>
  • small-package-quotes-ups-edition/trunk/js/en-ups-small.js

    r3159756 r3237693  
    7070    jQuery('input[name=ups_small_delivery_estimates]').on('change', toggle_ups_delivery_estimate_label_fields);
    7171
     72    // Review plugin button
     73    if (jQuery('.ups_small_plan_notice').length > 0 || jQuery('.ups_small_wrapper').length > 0) {
     74        const review_plugin_html = '<div id="en-woo-review-plugin"><a href="https://wordpress.org/support/plugin/small-package-quotes-ups-edition/reviews/#new-post" target="_blank" class="button button-primary is-primary">Review this plugin</a></div>';
     75
     76        if (jQuery('ul.subsubsub').length > 0) {
     77            jQuery('.subsubsub').after(review_plugin_html);
     78        } else {
     79            jQuery('li a:contains("Connection Settings")').closest('ul').after(review_plugin_html);
     80        }
     81    }
     82
    7283    var upsSmallCurrentTime = eniture_ups_small_admin_script.ups_small_order_cutoff_time;
    7384    if (upsSmallCurrentTime != '') {
    … …  
    156167            type: "POST",
    157168            url: ajaxurl,
    158             data: {action: 'eniture_ups_small_activate_hit_to_update_plan'},
     169            data: { action: 'eniture_ups_small_activate_hit_to_update_plan', wp_nonce: eniture_ups_small_admin_script.nonce },
    159170            success: function (data_response) {}
    160171        });
    … …  
    393404            'ups_small_license': jQuery('#ups_small_licence_key').val(),
    394405            'api_end_point': api_endpoint,
     406            'wp_nonce': eniture_ups_small_admin_script.nonce
    395407        };
    396408
    … …  
    435447            'action': 'ups_s_fd',
    436448            'company_id': jQuery('#freightdesk_online_id').val(),
    437             'disconnect': jQuery('#fd_online_id_ups_s').attr("data")
     449            'disconnect': jQuery('#fd_online_id_ups_s').attr("data"),
     450            'wp_nonce': eniture_ups_small_admin_script.nonce
    438451        }
    439452        var id_lenght = jQuery('#freightdesk_online_id').val();
    … …  
    10391052            type: "POST",
    10401053            url: ajaxurl,
    1041             data: {action: action},
     1054            data: { action: action, wp_nonce: eniture_ups_small_admin_script.nonce },
    10421055            success: function (data_response) {
    10431056                window.location.reload(true);
  • small-package-quotes-ups-edition/trunk/logs/en-logs.php

    r3219695 r3237693  
    6868            $logs = (!empty($logs) && is_string($logs) && strlen($logs) > 0) ? json_decode($logs, true) : [];
    6969
    70             echo '<table class="en_logs">';
     70            // Eniture debug mode
     71            do_action('eniture_debug_mode', 'UPS Small Logs', $logs);
     72
     73            echo '<table class="en_logs ups_small_wrapper">';
    7174
    7275            if (isset($logs['severity'], $logs['data']) && $logs['severity'] == 'SUCCESS') {
    … …  
    207210            }
    208211
    209             echo '<table>';
     212            echo '</table>';
    210213        }
    211214
  • small-package-quotes-ups-edition/trunk/order-details/en-order-widget.php

    r3159756 r3237693  
    3535                        case 'en_fdo_meta_data':
    3636                            $en_widget_details = json_decode($meta_data->value, true);
     37
     38                            // Eniture debug mode
     39                            do_action("eniture_debug_mood", "Order Widget Details (UPS Small)", $en_widget_details);
     40
    3741                            if (!empty($en_widget_details)) {
    3842                                $this->en_widget_details[] = $en_widget_details;
    … …  
    168172                'liftgate' => 'Lift gate delivery',
    169173                'hazmat' => 'Hazardous Material',
    170                 'holdatterminal' => 'Hold At Terminal'
     174                'holdatterminal' => 'Hold At Terminal',
     175                'limitedaccess' => 'Limited access delivery',
     176                'liftgate_pickup' => 'Lift gate pickup',
    171177            ];
    172178
  • small-package-quotes-ups-edition/trunk/readme.txt

    r3222153 r3237693  
    44Requires at least: 6.6
    55Tested up to: 6.7.1
    6 Stable tag: 4.5.16
     6Stable tag: 4.5.17
    77License:           GPL-2.0-or-later
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    143143== Changelog ==
    144144
     145= 4.5.17 =
     146* Update:  Added a new "Review Plugin" button for improved user feedback and engagement.
     147* Update:  Override Rates Shipping Rule: added Negative & Percentage Service Rate.
     148* Update:  Restrict To Location Rule: Introduced filters support.
     149* Update:  Minimum Shipping Charge Rule: Implemented a new rule to set a minimum charge for shipping.
     150* Update:  Free Shipping Rule: Added functionality to allow free shipping conditions based on configured rules.
     151* Fix: Export Products Functionality: Fixed issues with old nested material attributes of products to ensure accurate exports.
     152* Fix:Security Enhancements: Resolved vulnerability issues for improved plugin security and compliance.
     153* Fix:Request Parameters Sanitization: Improved sanitization in shipping rules to enhance data integrity
     154
     155
    145156= 4.5.16 =
    146157* Fix: Fixed order the shipping rule "Type" alphabetically.
  • small-package-quotes-ups-edition/trunk/shipping-rules/assets/css/shipping_rules.css

    r3219695 r3237693  
    1818.en_sr_form_control #en_ups_small_filter_by_state_label,
    1919.en_sr_form_control #en_ups_small_filter_by_origin_label,
    20 .en_sr_form_control #en_ups_small_filter_by_sevices_label {
     20.en_sr_form_control #en_ups_small_filter_by_sevices_label,
     21.en_sr_form_control #en_ups_small_msc_filter_by_sevices_label {
    2122        margin-bottom: -15px !important;
    2223}
    … …  
    4647
    4748label[for='en_sr_service_name']::after,
    48 label[for='en_sr_service_rate']::after,
     49label[for='en_ups_small_sr_service_rate']::after,
    4950label[for='en_ups_small_filter_by_state']::after,
    5051label[for='en_ups_small_filter_by_origin']::after,
    51 label[for='en_ups_small_filter_by_sevices']::after {
     52label[for='en_ups_small_filter_by_sevices']::after,
     53label[for='en_ups_small_msc_filter_by_sevices']::after,
     54label[for='en_sr_minimum_shipping_charge']::after {
    5255        content: ' *';
    5356        color: red;
  • small-package-quotes-ups-edition/trunk/shipping-rules/assets/js/shipping_rules.js

    r3219695 r3237693  
    99
    1010        const rule_types = {
     11                free_shipping: 'Free Shipping',
    1112                hide_methods: 'Hide Methods',
     13                hide_methods_by_origin_location: 'Hide Methods By Origin',
     14                large_cart_settings: 'Large Cart Settings',
     15                minimum_shipping_charge: 'Minimum Shipping Charge',
    1216                override_rates: 'Override Rates',
    1317                restrict_to_state: 'Restrict To State',
    14                 large_cart_settings: 'Large Cart Settings',
    15                 hide_methods_by_origin_location: 'Hide Methods By Origin',
    1618        };
    1719
    … …  
    2830                        'en_sr_product_tags_list',
    2931                        'en_sr_service_name',
    30                         'en_sr_service_rate',
     32                        'en_ups_small_sr_service_rate',
    3133                        'en_sr_max_items',
    3234                        'en_sr_max_weight_per_package'
    … …  
    4345                jQuery('.en_ups_small_sr_locations_list #en_sr_locations_list').val([]);
    4446                jQuery('.en_ups_small_sr_services_list #en_sr_services_list').val([]);
     47                // Override rates
     48                jQuery('#en_ups_small_or_sr_country').val('');
     49                jQuery('.en_ups_small_or_sr_us_states_list #en_or_sr_states_list').val([]);
     50                jQuery('.en_ups_small_or_sr_ca_states_list #en_or_sr_states_list').val([]);
     51                // Minimum shipping charge
     52                jQuery('.en_ups_small_msc_sr_services_list #en_msc_sr_services_list').val([]);
    4553
    4654                enUpsSmalltoggleRuleTypeFields();
     55               
     56                // Restrict to state
    4757                enUpsSmallToggleCountryStates();
    4858                enUpsSmallSetStatesValidation(false, true);
     59
     60                // Override rates shipping rule
     61                enUpsSmallORToggleCountryStates();
    4962        });
    5063
    … …  
    5265
    5366        jQuery(
    54                 '#en_sr_weight_from, #en_sr_weight_to, #en_sr_price_from, #en_sr_price_to, #en_sr_service_rate, #en_sr_max_items, #en_sr_max_weight_per_package'
     67                '#en_sr_weight_from, #en_sr_weight_to, #en_sr_price_from, #en_sr_price_to, #en_sr_max_items, #en_sr_max_weight_per_package, #en_sr_minimum_shipping_charge'
    5568        ).keypress(function (e) {
    5669                if (!String.fromCharCode(e.keyCode).match(/^[0-9.]+$/)) return false;
    … …  
    5972                if (!String.fromCharCode(e.keyCode).match(/^[0-9]+$/)) return false;
    6073        });
    61 
     74        jQuery('#en_ups_small_sr_service_rate').keypress(function (e) {
     75                if (!String.fromCharCode(e.keyCode).match(/^[0-9.%+-]+$/)) return false;
     76        });
     77
     78        // Restrict to state
    6279        enUpsSmallToggleCountryStates();
    6380        jQuery('#en_ups_small_sr_country').on('change load', function() {
    … …  
    6683        });
    6784
     85        // Override rates shipping rule
     86        enUpsSmallORToggleCountryStates();
     87        jQuery('#en_ups_small_or_sr_country').on('change load', enUpsSmallORToggleCountryStates);
     88        jQuery('#filter_by_country_or').on('change', function () {
     89                !this.checked && jQuery('#filter_by_state_or').prop('checked', false);
     90        });
     91        jQuery('#filter_by_state_or').on('change', function () {
     92                this.checked && jQuery('#filter_by_country_or').prop('checked', true);
     93        });
     94
    6895        jQuery('#en_ups_small_filter_by_country').on('change load', function () {
    6996                // if country is unchecked, then uncheck state also
    7097                if (!this.checked) jQuery('#en_ups_small_filter_by_state').prop('checked', false);
    7198        });
    72 
    7399        jQuery('#en_ups_small_filter_by_state').on('change', function () {
    74100                this.checked && jQuery('#en_ups_small_filter_by_country').prop('checked', this.checked);
    … …  
    222248        function enUpsSmallSaveShippingRule(e) {
    223249                e.preventDefault();
     250                jQuery('.en_ups_small_sr_form .en_sr_err').html('');
    224251
    225252                let is_valid = enUpsSmallSRValidateInput('#add_shipping_rule');
    … …  
    234261                }
    235262
     263                // apply required field validations for override rates rule
     264                if (rule_type === rule_types.override_rates) {
     265                        const validate = enUpsSmallORValidations();
     266                        is_valid = is_valid && validate;
     267                }
     268
    236269                // apply required field validations for hide methods by origin location rule
    237270                if (rule_type === rule_types.hide_methods_by_origin_location) {
    … …  
    240273                }
    241274
     275                // apply required field validations for minimum shipping charge rule
     276                if (rule_type === rule_types.minimum_shipping_charge) {
     277                        const validate = enUpsSmallMSCValidations();
     278                        is_valid = is_valid && validate;
     279                }
     280
    242281                if (!is_valid) {
    243282                        jQuery('.content').delay(200).animate({ scrollTop: 0 }, 300);
    … …  
    251290                const origins_value = hide_methods_by_origin_rule ? jQuery('.en_ups_small_sr_locations_list #en_sr_locations_list').val() : [];
    252291                const services_value = hide_methods_by_origin_rule ? jQuery('.en_ups_small_sr_services_list #en_sr_services_list').val() : [];
     292                // Override rates rule
     293                const or_rule = rule_type === rule_types.override_rates;
     294                let or_states_values = [];
     295                or_states_values = jQuery('#en_ups_small_or_sr_country').val() === 'US' ? jQuery('.en_ups_small_or_sr_us_states_list #en_or_sr_states_list').val(): or_states_values;
     296                or_states_values = jQuery('#en_ups_small_or_sr_country').val() === 'CA' ? jQuery('.en_ups_small_or_sr_ca_states_list #en_or_sr_states_list').val(): or_states_values;
     297                // Minimum shipping charge rule
     298                const msc_rule = rule_type === rule_types.minimum_shipping_charge;
    253299
    254300                // Submit the form to save settings
    255301                const postData = {
    256302                        action: 'en_save_shipping_rule',
     303                        wp_nonce: sr_script.nonce,
    257304                        rule_id: jQuery('#edit_sr_form_id').val(),
    258305                        name: jQuery('#en_sr_rule_name').val(),
    … …  
    260307                        is_active: Number(jQuery('#en_sr_avialable').prop('checked')),
    261308                        settings: {
    262                                 filter_name: [rule_types.hide_methods, rule_types.override_rates].includes(rule_type) ? jQuery('#en_sr_filter_name').val() : '',
     309                                filter_name: '',
    263310                                apply_to: jQuery('input[name="apply_to"]:checked').val(),
    264311                                // Filter by country
    … …  
    284331                                filter_by_product_tag_value: jQuery('#en_sr_product_tags_list').val(),
    285332                                // Service info
    286                                 service: jQuery('#en_sr_service_name').val(),
    287                                 service_rate: jQuery('#en_sr_service_rate').val(),
     333                                service: or_rule ? jQuery('#en_sr_service_name').val() : '',
     334                                service_rate: or_rule ? jQuery('#en_ups_small_sr_service_rate').val() : '',
    288335                                // Large cart settings
    289336                                max_items: jQuery('#en_sr_max_items').val(),
    … …  
    294341                                filter_by_service: hide_methods_by_origin_rule,
    295342                                filter_by_service_value: hide_methods_by_origin_rule ? services_value : [],
     343                                // Override rates country and state filters
     344                                filter_by_country_or: or_rule ? jQuery('#filter_by_country_or').prop('checked') : false,
     345                                filter_by_country_value_or: or_rule ? jQuery('#en_ups_small_or_sr_country').val() : '',
     346                                filter_by_state_or: or_rule ? jQuery('#filter_by_state_or').prop('checked') : false,
     347                                filter_by_state_value_or: or_rule ? or_states_values : [],
     348                                // Minimum shipping charge
     349                                minimum_shipping_charge: msc_rule ? jQuery('#en_sr_minimum_shipping_charge').val() : '',
     350                                minimum_shipping_charge_services: msc_rule ? jQuery('#en_msc_sr_services_list').val() : [],
    296351                        },
    297352                };
    … …  
    359414                jQuery('.en_ups_small_sr_locations_list #en_sr_locations_list').val([]);
    360415                jQuery('.en_ups_small_sr_services_list #en_sr_services_list').val([]);
     416                jQuery('.en_ups_small_msc_sr_services_list #en_msc_sr_services_list').val([]);
    361417
    362418                const postForm = {
    363419                        action: 'en_edit_shipping_rule',
    364420                        edit_id: rule_id,
     421                        wp_nonce: sr_script.nonce,
    365422                };
    366423
    … …  
    374431                                jQuery(elem).css(
    375432                                        'background',
    376                                         `rgba(255, 255, 255, 1) url("${script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
     433                                        `rgba(255, 255, 255, 1) url("${sr_script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
    377434                                );
    378435                        },
    … …  
    382439
    383440                                if (data) {
    384                                         jQuery('#edit_sr_form_id').val(data?.rule_data.id);
    385                                         jQuery('#en_sr_rule_name').val(data?.rule_data?.name);
    386                                         jQuery('#en_ups_small_rule_type').val(data?.rule_data?.type);
    387                                         jQuery('#en_sr_avialable').prop(
    388                                                 'checked',
    389                                                 Number(data?.rule_data?.is_active)
    390                                         );
    391 
    392                                         enUpsSmalltoggleRuleTypeFields();
    393 
    394                                         const settings = JSON.parse(data?.rule_data?.settings) ?? {};
    395                                        
    396                                         jQuery('input[name="apply_to"]').val([settings?.apply_to]);
    397                                         jQuery('#en_sr_filter_name').val(settings?.filter_name);
    398                                         // Override rates
    399                                         jQuery('#en_sr_service_name').val(settings?.service);
    400                                         jQuery('#en_sr_service_rate').val(settings?.service_rate);
    401                                         // Large cart settings
    402                                         jQuery('#en_sr_max_items').val(settings?.max_items);
    403                                         jQuery('#en_sr_max_weight_per_package').val(
    404                                                 settings?.max_weight_per_package
    405                                         );
    406 
    407                                         // Restrict to state
    408                                         if (jQuery('#en_ups_small_rule_type').val() === rule_types.restrict_to_state) {
    409                                                 jQuery('#en_ups_small_filter_by_country').prop('checked', settings?.filter_by_country === 'true');
    410                                                 jQuery('#en_ups_small_sr_country').val(settings?.filter_by_country_value || 'US');
    411                                                 jQuery('#en_ups_small_filter_by_state').prop('checked', settings?.filter_by_state === 'true');
    412                                                 enUpsSmallSetStatesValidation(true, false);
    413                                                
    414                                                 if (data?.country_states_markup) {
    415                                                         const countryId = settings?.filter_by_country_value;
    416                                                         jQuery(countryId === 'US' ? '.en_ups_small_sr_us_states_list #en_sr_states_list' : '.en_ups_small_sr_ca_states_list #en_sr_states_list').html(data?.country_states_markup).trigger('change');
    417                                                 }
    418                                                
    419                                                 enUpsSmallToggleCountryStates();
    420                                         }
    421 
    422                                         // Hide methods by origin location
    423                                         if (jQuery('#en_ups_small_rule_type').val() === rule_types.hide_methods_by_origin_location) {
    424                                                 jQuery('#filter_by_origin').prop('checked', settings?.filter_by_origin === 'true');
    425                                                 jQuery('.en_ups_small_sr_locations_list #en_sr_locations_list').html(data?.origins_markup).trigger('change');
    426 
    427                                                 jQuery("#filter_by_service").prop('checked', settings?.filter_by_service === 'true');
    428                                                 jQuery('.en_ups_small_sr_services_list #en_sr_services_list').html(data?.services_markup).trigger('change');
    429                                         }
    430 
    431                                         // Common filters settings
    432                                         jQuery('#filter_by_weight').prop(
    433                                                 'checked',
    434                                                 settings?.filter_by_weight === 'true'
    435                                         );
    436                                         settings?.filter_by_weight === 'true' &&
    437                                                 removeDataAttribute('en_sr_weight_from');
    438                                         jQuery('#en_sr_weight_from').val(settings?.filter_by_weight_from);
    439                                         jQuery('#en_sr_weight_to').val(settings?.filter_by_weight_to);
    440                                         jQuery('#en_sr_filter_price').prop(
    441                                                 'checked',
    442                                                 settings?.filter_by_price === 'true'
    443                                         );
    444                                         settings?.filter_by_price === 'true' &&
    445                                                 removeDataAttribute('en_sr_price_from');
    446                                         jQuery('#en_sr_price_from').val(settings?.filter_by_price_from);
    447                                         jQuery('#en_sr_price_to').val(settings?.filter_by_price_to);
    448                                         jQuery('#filter_by_quantity').prop(
    449                                                 'checked',
    450                                                 settings?.filter_by_quantity === 'true'
    451                                         );
    452                                         settings?.filter_by_quantity === 'true' &&
    453                                                 removeDataAttribute('en_sr_quantity_from');
    454                                         jQuery('#en_sr_quantity_from').val(settings?.filter_by_quantity_from);
    455                                         jQuery('#en_sr_quantity_to').val(settings?.filter_by_quantity_to);
    456                                         jQuery('#filter_by_product_tag').prop(
    457                                                 'checked',
    458                                                 settings?.filter_by_product_tag === 'true'
    459                                         );
    460                                         settings?.filter_by_product_tag === 'true' &&
    461                                                 removeDataAttribute('en_sr_product_tags_list');
    462                                         jQuery('#en_sr_product_tags_list')
    463                                                 .html(data?.product_tags_markup)
    464                                                 .trigger('change');
     441                                        enUpsSmallSRPopulateData(data);
    465442                                        jQuery('.content').animate({ scrollTop: 0 }, 0);
    466443
    … …  
    493470                        action: 'en_delete_shipping_rule',
    494471                        delete_id: id,
     472                        wp_nonce: sr_script.nonce,
    495473                };
    496474
    … …  
    504482                                jQuery(elem).css(
    505483                                        'background',
    506                                         `rgba(255, 255, 255, 1) url("${script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
     484                                        `rgba(255, 255, 255, 1) url("${sr_script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
    507485                                );
    508486                        },
    … …  
    535513                        rule_id,
    536514                        is_active: Number(!Number(is_active)),
     515                        wp_nonce: sr_script.nonce,
    537516                };
    538517
    … …  
    546525                                jQuery(elem).css(
    547526                                        'background',
    548                                         `rgba(255, 255, 255, 1) url("${script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
     527                                        `rgba(255, 255, 255, 1) url("${sr_script.pluginsUrl}/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/processing.gif") no-repeat scroll 50% 50%`
    549528                                );
    550529                        },
    … …  
    573552                                <td class="en_wd_warehouse_list_data">${rule?.name}</td>
    574553                                <td class="en_wd_warehouse_list_data">${rule?.type}</td>
    575                                 <td class="en_wd_warehouse_list_data">${rule?.settings?.filter_name}</td>
    576554                                <td class="en_wd_warehouse_list_data"><a href="#" class='en_ups_sr_status_link' data-id='${
    577555                                        rule?.id
    … …  
    581559                                        <a href="#" class="en_ups_sr_edit_link" data-id="${rule?.id}">
    582560                                                <img src="${
    583                                                         script.pluginsUrl
     561                                                        sr_script.pluginsUrl
    584562                                                }/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png" title="Edit">
    585563                                        </a>
    … …  
    587565                                        <a href="#" class="en_ups_sr_delete_link" data-id="${rule?.id}">
    588566                                                <img src="${
    589                                                         script.pluginsUrl
     567                                                        sr_script.pluginsUrl
    590568                                                }/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png" title="Delete">
    591569                                        </a>
    … …  
    601579                jQuery('#en_ups_small_sr_content').css('height', '80vh');
    602580                enUpsSmallSetStatesValidation(false, true);
     581                jQuery('.en_sr_hide_methods_by_origin_location, .en_ups_small_sr_large_cart_settings, .en_sr_min_shipping_charge, .en_sr_override_rates, .en_sr_restrict_to_state, #en_sr_apply_to_product').hide();
    603582
    604583                if (type === rule_types.override_rates) {
    605                         jQuery('.en_sr_override_rates, .en_ups_small_sr_apply_to, #en_sr_apply_to_shipment, .en_ups_small_sr_filters_section').show();
    606                         jQuery('#en_sr_apply_to_cart, .en_sr_restrict_to_state, .en_ups_small_sr_large_cart_settings, .en_sr_hide_methods_by_origin_location').hide();
     584                        jQuery('.en_sr_override_rates, .en_ups_small_sr_apply_to, #en_sr_apply_to_shipment, .en_ups_small_sr_filters_section, .en_or_sr_filters').show();
     585                        jQuery('#en_sr_apply_to_cart').hide();
    607586                        jQuery('input[name="apply_to"]').val(['shipment']);
    608587                       
    609588                        setDataAttribute('en_sr_max_items', 'en_sr_max_weight_per_package');
    610                         removeDataAttribute('en_sr_service_name', 'en_sr_service_rate');
     589                        removeDataAttribute('en_sr_service_name', 'en_ups_small_sr_service_rate');
    611590                } else if (type === rule_types.restrict_to_state) {
    612                         jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_cart, .en_sr_restrict_to_state').show();
     591                        jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_cart, .en_sr_restrict_to_state, .en_ups_small_sr_filters_section').show();
    613592                        jQuery('input[name="apply_to"]').val(['cart']);
    614                         jQuery('.en_sr_override_rates, #en_sr_apply_to_shipment, .en_ups_small_sr_large_cart_settings, .en_sr_hide_methods_by_origin_location, .en_ups_small_sr_filters_section').hide();
    615 
    616                         setDataAttribute('en_sr_service', 'en_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
     593                        jQuery('#en_sr_apply_to_shipment, .en_or_sr_filters').hide();
     594
     595                        setDataAttribute('en_sr_service', 'en_ups_small_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
    617596                        enUpsSmallSetStatesValidation();
    618597                } else if (type === rule_types.large_cart_settings) {
    619                         jQuery('.en_sr_override_rates, .en_ups_small_sr_apply_to, .en_sr_restrict_to_state, .en_sr_hide_methods_by_origin_location, .en_ups_small_sr_filters_section').hide();
     598                        jQuery('.en_ups_small_sr_apply_to, .en_ups_small_sr_filters_section, .en_or_sr_filters').hide();
    620599                        jQuery('.en_ups_small_sr_large_cart_settings').show();
    621600                        jQuery('input[name="apply_to"]').val(['cart']);
    622601
    623                         setDataAttribute('en_sr_service_name', 'en_sr_service_rate');
     602                        setDataAttribute('en_sr_service_name', 'en_ups_small_sr_service_rate');
    624603                        removeDataAttribute('en_sr_max_items', 'en_sr_max_weight_per_package');
    625604                } else if (type === rule_types.hide_methods_by_origin_location) {
    626605                        jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_shipment, .en_sr_hide_methods_by_origin_location').show();
    627                         jQuery('.en_sr_override_rates, #en_sr_apply_to_cart, .en_sr_restrict_to_state, .en_ups_small_sr_large_cart_settings, .en_ups_small_sr_filters_section').hide();
     606                        jQuery('#en_sr_apply_to_cart, .en_ups_small_sr_filters_section, .en_or_sr_filters').hide();
    628607                        jQuery('input[name="apply_to"]').val(['shipment']);
    629608                       
    630                         setDataAttribute('en_sr_service_name', 'en_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
     609                        setDataAttribute('en_sr_service_name', 'en_ups_small_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
    631610                        removeDataAttribute('en_sr_locations_list, en_sr_services_list');
     611                } else if (type === rule_types.minimum_shipping_charge) {
     612                        jQuery('.en_or_sr_filters').hide();
     613                        jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_cart, #en_sr_apply_to_shipment, .en_sr_min_shipping_charge, .en_ups_small_sr_filters_section').show();
     614                        jQuery('input[name="apply_to"]').val(['shipment']);
     615
     616                        setDataAttribute('en_sr_service_name', 'en_ups_small_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
     617                        removeDataAttribute('en_sr_minimum_shipping_charge', 'en_msc_sr_services_list');
    632618                } else {
    633                         jQuery('.en_sr_override_rates, .en_sr_restrict_to_state, .en_ups_small_sr_large_cart_settings, .en_sr_hide_methods_by_origin_location').hide();
    634                         jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_cart, #en_sr_apply_to_shipment, .en_ups_small_sr_filters_section').show();
    635                         jQuery('input[name="apply_to"]').val(['cart']);
    636                        
    637                         setDataAttribute('en_sr_service_name', 'en_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package');
     619                        jQuery('.en_or_sr_filters').hide();
     620
     621                        if (type === rule_types.free_shipping) {
     622                                jQuery('#en_sr_apply_to_cart, #en_sr_apply_to_shipment').hide();
     623                                jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_product, .en_ups_small_sr_filters_section').show();
     624                                jQuery('input[name="apply_to"]').val(['product']);
     625                        } else {
     626                                jQuery('#en_sr_apply_to_product').hide();
     627                                jQuery('.en_ups_small_sr_apply_to, #en_sr_apply_to_cart, #en_sr_apply_to_shipment, .en_ups_small_sr_filters_section').show();
     628                                jQuery('input[name="apply_to"]').val(['cart']);
     629                        }
     630
     631                        setDataAttribute('en_sr_service_name', 'en_ups_small_sr_service_rate', 'en_sr_max_items', 'en_sr_max_weight_per_package', 'en_sr_locations_list', 'en_sr_services_list', 'en_sr_minimum_shipping_charge', 'en_msc_sr_services_list');
    638632                }
    639633        }
    … …  
    657651        }
    658652
    659         // #region Toggle country states
     653        // #region Toggle country states (Restrict to State rule)
    660654        function enUpsSmallToggleCountryStates() {
    661655                const selectedCountry = jQuery('#en_ups_small_sr_country').val();
    … …  
    664658        }
    665659
     660        // #region Toggle country states (Override rates rule)
     661        function enUpsSmallORToggleCountryStates() {
     662                const selectedCountry = jQuery('#en_ups_small_or_sr_country').val();
     663
     664                if (!selectedCountry) {
     665                        jQuery('.en_ups_small_or_sr_us_states_list #en_or_sr_states_list').val([]);
     666                        jQuery('.en_ups_small_or_sr_ca_states_list #en_or_sr_states_list').val([]);
     667                }
     668
     669                jQuery('.en_ups_small_or_empty_sr_states_list').css('display', !selectedCountry ? '' : 'none');
     670                jQuery('.en_ups_small_or_sr_us_states_list').css('display', selectedCountry === 'US' ? '' : 'none');
     671                jQuery('.en_ups_small_or_sr_ca_states_list').css('display', selectedCountry === 'CA' ? '' : 'none');
     672        }
     673
     674        // #region: Hide Methods by Origin Location Validations
    666675        function enUpsSmallHMBLValidations() {
    667676                const ids = ['#en_sr_locations_list', '#en_sr_services_list'];
    … …  
    679688                return is_valid;
    680689        }
     690
     691        // #region: Override Rates Validations
     692        function enUpsSmallORValidations() {
     693                let is_valid = true;
     694
     695                // Filter by country
     696                if (jQuery('#filter_by_country_or').prop('checked') && !jQuery('#en_ups_small_or_sr_country').val()) {
     697                        jQuery('#en_ups_small_or_sr_country').parent().find('.en_sr_err').html('Country is required.');
     698                        is_valid = false;
     699                }
     700
     701                // Filter by state
     702                if (jQuery('#filter_by_state_or').prop('checked')) {
     703                        const selectedCountry = jQuery('#en_ups_small_or_sr_country').val(),
     704                                                us_states_value = jQuery('.en_ups_small_or_sr_us_states_list #en_or_sr_states_list').val(),
     705                                                ca_states_value = jQuery('.en_ups_small_or_sr_ca_states_list #en_or_sr_states_list').val(),
     706                                                parent_elem = '.en_ups_small_or_empty_sr_states_list, .en_ups_small_or_sr_us_states_list, .en_ups_small_or_sr_ca_states_list';
     707
     708                        if (!selectedCountry || (selectedCountry === 'US' && !us_states_value?.length) ||
     709                                        (selectedCountry === 'CA' && !ca_states_value?.length)) {
     710                                jQuery(parent_elem).find('.en_sr_err').html('State is required.');
     711                                is_valid = false;
     712                        }
     713                }
     714
     715                return is_valid;
     716        }
     717
     718        // #region: Populate Shipping Rule Data
     719        function enUpsSmallSRPopulateData(data) {
     720                jQuery('#edit_sr_form_id').val(data?.rule_data.id);
     721                jQuery('#en_sr_rule_name').val(data?.rule_data?.name);
     722                jQuery('#en_ups_small_rule_type').val(data?.rule_data?.type);
     723                jQuery('#en_sr_avialable').prop(
     724                        'checked',
     725                        Number(data?.rule_data?.is_active)
     726                );
     727
     728                enUpsSmalltoggleRuleTypeFields();
     729
     730                const settings = JSON.parse(data?.rule_data?.settings) ?? {};
     731               
     732                jQuery('input[name="apply_to"]').val([settings?.apply_to]);
     733                // Override rates
     734                jQuery('#en_sr_service_name').val(settings?.service);
     735                jQuery('#en_ups_small_sr_service_rate').val(settings?.service_rate);
     736                // Large cart settings
     737                jQuery('#en_sr_max_items').val(settings?.max_items);
     738                jQuery('#en_sr_max_weight_per_package').val(
     739                        settings?.max_weight_per_package
     740                );
     741
     742                const rule_type = jQuery('#en_ups_small_rule_type').val();
     743
     744                // Hide methods by origin location
     745                if (rule_type === rule_types.hide_methods_by_origin_location) {
     746                        jQuery('#filter_by_origin').prop('checked', settings?.filter_by_origin === 'true');
     747                        jQuery('.en_ups_small_sr_locations_list #en_sr_locations_list').html(data?.origins_markup).trigger('change');
     748
     749                        jQuery("#filter_by_service").prop('checked', settings?.filter_by_service === 'true');
     750                        jQuery('.en_ups_small_sr_services_list #en_sr_services_list').html(data?.services_markup).trigger('change');
     751                }
     752
     753                // Minimum shipping charge
     754                if (rule_type === rule_types.minimum_shipping_charge) {
     755                        jQuery('#en_sr_minimum_shipping_charge').val(settings?.minimum_shipping_charge);
     756                        jQuery('.en_ups_small_msc_sr_services_list #en_msc_sr_services_list').html(data?.services_markup).trigger('change');
     757                }
     758
     759                // Override rates
     760                if (rule_type === rule_types.override_rates) {
     761                        jQuery('#filter_by_country_or').prop('checked', settings?.filter_by_country_or === 'true');
     762                        jQuery('#en_ups_small_or_sr_country').val(settings?.filter_by_country_value_or);
     763                        jQuery('#filter_by_state_or').prop('checked', settings?.filter_by_state_or === 'true');
     764
     765                        if (data?.or_country_states_markup) {
     766                                const country = settings?.filter_by_country_value_or;
     767                                jQuery(!country && '.en_ups_small_or_empty_sr_states_list #en_or_empty_sr_states_list').html('').trigger('change');
     768                                jQuery(country === 'US' && '.en_ups_small_or_sr_us_states_list #en_or_sr_states_list').html(data?.or_country_states_markup).trigger('change');
     769                                jQuery(country === 'CA' && '.en_ups_small_or_sr_ca_states_list #en_or_sr_states_list').html(data?.or_country_states_markup).trigger('change');
     770                        }
     771
     772                        enUpsSmallORToggleCountryStates();
     773                }
     774
     775                // Restrict to state
     776                if (rule_type === rule_types.restrict_to_state) {
     777                        jQuery('#en_ups_small_filter_by_country').prop('checked', settings?.filter_by_country === 'true');
     778                        jQuery('#en_ups_small_sr_country').val(settings?.filter_by_country_value || 'US');
     779                        jQuery('#en_ups_small_filter_by_state').prop('checked', settings?.filter_by_state === 'true');
     780                        enUpsSmallSetStatesValidation(true, false);
     781                       
     782                        if (data?.country_states_markup) {
     783                                const countryId = settings?.filter_by_country_value;
     784                                jQuery(countryId === 'US' ? '.en_ups_small_sr_us_states_list #en_sr_states_list' : '.en_ups_small_sr_ca_states_list #en_sr_states_list').html(data?.country_states_markup).trigger('change');
     785                        }
     786                       
     787                        enUpsSmallToggleCountryStates();
     788                }
     789
     790                // Common filters settings
     791                // Weight
     792                jQuery('#filter_by_weight').prop('checked', settings?.filter_by_weight === 'true');
     793                settings?.filter_by_weight === 'true' && removeDataAttribute('en_sr_weight_from');
     794                jQuery('#en_sr_weight_from').val(settings?.filter_by_weight_from);
     795                jQuery('#en_sr_weight_to').val(settings?.filter_by_weight_to);
     796                // Price
     797                jQuery('#en_sr_filter_price').prop('checked', settings?.filter_by_price === 'true');
     798                settings?.filter_by_price === 'true' && removeDataAttribute('en_sr_price_from');
     799                jQuery('#en_sr_price_from').val(settings?.filter_by_price_from);
     800                jQuery('#en_sr_price_to').val(settings?.filter_by_price_to);
     801                // Quantity
     802                jQuery('#filter_by_quantity').prop('checked', settings?.filter_by_quantity === 'true');
     803                settings?.filter_by_quantity === 'true' && removeDataAttribute('en_sr_quantity_from');
     804                jQuery('#en_sr_quantity_from').val(settings?.filter_by_quantity_from);
     805                jQuery('#en_sr_quantity_to').val(settings?.filter_by_quantity_to);
     806                // Product tags
     807                jQuery('#filter_by_product_tag').prop('checked', settings?.filter_by_product_tag === 'true');
     808                settings?.filter_by_product_tag === 'true' && removeDataAttribute('en_sr_product_tags_list');
     809                jQuery('#en_sr_product_tags_list').html(data?.product_tags_markup).trigger('change');
     810        }
     811
     812        // #region: Minimum Shipping Charge Validations
     813        function enUpsSmallMSCValidations() {
     814                let is_valid = true;
     815
     816                if (!jQuery('.en_ups_small_msc_sr_services_list #en_msc_sr_services_list').val()?.length) {
     817                        jQuery('.en_ups_small_msc_sr_services_list').find('.en_sr_err').html('Services is required.');
     818                        is_valid = false;
     819                }
     820
     821                return is_valid;
     822        }
    681823});
  • small-package-quotes-ups-edition/trunk/shipping-rules/shipping-rules-save.php

    r3219695 r3237693  
    3737        function save_shipping_rule_ajax()
    3838        {
     39            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_sr_nonce')) {
     40                echo wp_json_encode([]);
     41                return;
     42            }
     43
    3944            global $wpdb;
    4045
    … …  
    4247            $error = false;
    4348            $data = $_POST;
    44             $get_shipping_rule_id = (isset($data['rule_id']) && intval($data['rule_id'])) ? $data['rule_id'] : "";
     49            $data = $this->sanitize_request_data($data);
     50            $get_shipping_rule_id = (isset($data['rule_id']) && intval($data['rule_id'])) ? intval($data['rule_id']) : "";
    4551            $last_id = $get_shipping_rule_id;
    4652            $get_shipping_rule = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "eniture_ups_small_shipping_rules WHERE name = %s", $data['name']));
    4753            unset($data['action']);
    4854            unset($data['rule_id']);
    49            
     55            unset($data['wp_nonce']);
     56
    5057            if (!empty($get_shipping_rule_id)) {
    5158                $data['settings'] = wp_json_encode($data['settings']);
    … …  
    7885        function edit_shipping_rule_ajax()
    7986        {
    80             global $wpdb;
    81             $get_shipping_rule_id = (isset($_POST['edit_id']) && intval($_POST['edit_id'])) ? sanitize_text_field(wp_unslash($_POST['edit_id'])) : "";
     87            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_sr_nonce')) {
     88                echo wp_json_encode([]);
     89                return;
     90            }
     91
     92            global $wpdb;
     93            $get_shipping_rule_id = (isset($_POST['edit_id']) && intval($_POST['edit_id'])) ? intval($_POST['edit_id']) : "";
    8294            $shipping_rules_list = $wpdb->get_results(
    8395                "SELECT * FROM " . $wpdb->prefix . "eniture_ups_small_shipping_rules WHERE id=$get_shipping_rule_id"
    8496            );
     97            $shipping_rules_type = isset(reset($shipping_rules_list)->type) ? reset($shipping_rules_list)->type : '';
     98
    8599            $product_tags_markup = $this->get_product_tags_markup($shipping_rules_list);
    86100            $states_markup = $this->get_country_states_markup($shipping_rules_list);
    87101            $origins_markup = $this->get_origins_markup($shipping_rules_list);
    88             $services_markup = $this->get_services_markup($shipping_rules_list);
    89 
    90             $data = ['rule_data' => reset($shipping_rules_list), 'product_tags_markup' => $product_tags_markup, 'country_states_markup' => $states_markup, 'origins_markup' => $origins_markup, 'services_markup' => $services_markup];
     102            $services_markup = $this->get_services_markup($shipping_rules_list, $shipping_rules_type);
     103            // override rates rule
     104            $or_states_markup = $shipping_rules_type == 'Override Rates' ? $this->get_country_states_markup($shipping_rules_list, true) : '';
     105
     106            $data = ['rule_data' => reset($shipping_rules_list), 'product_tags_markup' => $product_tags_markup, 'country_states_markup' => $states_markup, 'origins_markup' => $origins_markup, 'services_markup' => $services_markup, 'or_country_states_markup' => $or_states_markup,];
    91107
    92108            echo wp_json_encode($data);
    … …  
    101117        function delete_shipping_rule_ajax()
    102118        {
    103             global $wpdb;
    104             $get_shipping_rule_id = (isset($_POST['delete_id']) && intval($_POST['delete_id'])) ? sanitize_text_field(wp_unslash($_POST['delete_id'])) : "";
     119            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_sr_nonce')) {
     120                echo wp_json_encode([]);
     121                return;
     122            }
     123
     124            global $wpdb;
     125            $get_shipping_rule_id = (isset($_POST['delete_id']) && intval($_POST['delete_id'])) ? intval($_POST['delete_id']) : "";
    105126            $qry = $wpdb->delete($wpdb->prefix . 'eniture_ups_small_shipping_rules', array('id' => $get_shipping_rule_id));
    106127
    … …  
    116137        function update_shipping_rule_status_ajax()
    117138        {
    118             global $wpdb;
    119             $get_shipping_rule_id = (isset($_POST['rule_id']) && intval($_POST['rule_id'])) ? sanitize_text_field(wp_unslash($_POST['rule_id'])) : "";
     139            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_sr_nonce')) {
     140                echo wp_json_encode([]);
     141                return;
     142            }
     143
     144            global $wpdb;
     145            $get_shipping_rule_id = (isset($_POST['rule_id']) && intval($_POST['rule_id'])) ? intval($_POST['rule_id']) : "";
    120146            $is_active = isset($_POST['is_active']) ? sanitize_text_field(wp_unslash($_POST['is_active'])) : "";
    121147            $data = ['is_active' => $is_active];
    122            
     148
    123149            $update_qry = $wpdb->update(
    124150                $wpdb->prefix . 'eniture_ups_small_shipping_rules', $data, array('id' => $get_shipping_rule_id)
    … …  
    199225         * @global $wpdb
    200226         */
    201         function get_country_states_markup($shipping_rules_list)
     227        function get_country_states_markup($shipping_rules_list, $override_rates_rule = false)
    202228        {
    203229            $states_options = '';
    204230            $shipping_rules_list = reset($shipping_rules_list);
    205231            $settings = isset($shipping_rules_list->settings) ? json_decode($shipping_rules_list->settings, true) : [];
    206             $selected_states_detials = $this->get_selected_states_details($settings);
     232            $filter_by_state_val = $override_rates_rule ? 'filter_by_state_value_or' : 'filter_by_state_value';
     233            $filter_by_country_val = $override_rates_rule ? 'filter_by_country_value_or' : 'filter_by_country_value';
     234            $selected_states_detials = $this->get_selected_states_details($settings, $filter_by_state_val, $filter_by_country_val);
    207235
    208236            if (!empty($selected_states_detials) && is_array($selected_states_detials)) {
    … …  
    212240            }
    213241
    214             if (empty($settings['filter_by_state_value']) || !is_array($settings['filter_by_state_value'])) {
    215                 $settings['filter_by_state_value'] = [];
     242            if (empty($settings[$filter_by_state_val]) || !is_array($settings[$filter_by_state_val])) {
     243                $settings[$filter_by_state_val] = [];
    216244            }
    217245
    218246            $countries_obj = new WC_Countries();
    219             $selected_country = isset($settings['filter_by_country_value']) ? $settings['filter_by_country_value'] : '';
     247            $selected_country = isset($settings[$filter_by_country_val]) ? $settings[$filter_by_country_val] : '';
    220248            $en_woo_states = $countries_obj->get_states($selected_country);
    221249
    222             if (!empty($en_woo_states) && is_array($settings['filter_by_state_value'])) {
     250            if (!empty($en_woo_states) && is_array($settings[$filter_by_state_val])) {
    223251                foreach ($en_woo_states as $s_code => $s_label) {
    224                     if (!in_array($s_code, $settings['filter_by_state_value'])) {
     252                    if (!in_array($s_code, $settings[$filter_by_state_val])) {
    225253                        $states_options .= "<option value='" . esc_attr($s_code) . "'>" . esc_html($s_label) . "</option>";
    226254                    }
    … …  
    236264         * @global $wpdb
    237265         */
    238         function get_selected_states_details($settings)
    239         {
    240             $states_arr = isset($settings['filter_by_state_value']) ? $settings['filter_by_state_value'] : [];
     266        function get_selected_states_details($settings, $filter_by_state_val, $filter_by_country_val)
     267        {
     268            $states_arr = isset($settings[$filter_by_state_val]) ? $settings[$filter_by_state_val] : [];
    241269            if (empty($states_arr) || !is_array($states_arr)) {
    242270                return [];
    … …  
    244272
    245273            $countries_obj = new WC_Countries();
    246             $selected_country = isset($settings['filter_by_country_value']) ? $settings['filter_by_country_value'] : '';
     274            $selected_country = isset($settings[$filter_by_country_val]) ? $settings[$filter_by_country_val] : '';
    247275            $en_woo_states = $countries_obj->get_states($selected_country);
    248276            $states_detail = [];
    … …  
    306334        }
    307335
    308         function get_services_markup($shipping_rules_list)
     336        function get_services_markup($shipping_rules_list, $type)
    309337        {
    310338            $services_options = '';
    … …  
    312340            $settings = isset($shipping_rules_list->settings) ? json_decode($shipping_rules_list->settings, true) : [];
    313341            $services = $this->get_all_services();
    314             $selected_services_detials = $this->get_selected_services_details($settings, $services);
     342            $selected_services_detials = $this->get_selected_services_details($settings, $services, $type);
    315343
    316344            if (!empty($selected_services_detials) && is_array($selected_services_detials)) {
    … …  
    320348            }
    321349
    322             if (empty($settings['filter_by_service_value']) || !is_array($settings['filter_by_service_value'])) {
    323                 $settings['filter_by_service_value'] = [];
     350            $filter_by_service = $type == 'Hide Methods By Origin' ? 'filter_by_service_value' : 'minimum_shipping_charge_services';
     351            if (empty($settings[$filter_by_service]) || !is_array($settings[$filter_by_service])) {
     352                $settings[$filter_by_service] = [];
    324353            }
    325354
    326355            foreach ($services as $key => $service) {
    327                 if (in_array($key, $settings['filter_by_service_value'])) continue;
     356                if (in_array($key, $settings[$filter_by_service])) continue;
    328357                $services_options .= "<option value='" . esc_attr($key) . "'>" . esc_html($service) . "</option>";
    329358            }
    … …  
    332361        }
    333362
    334         function get_selected_services_details($settings, $services)
    335         {
    336             $services_arr = isset($settings['filter_by_service_value']) ? $settings['filter_by_service_value'] : [];
     363        function get_selected_services_details($settings, $services, $type)
     364        {
     365            $filter_by_service = $type == 'Hide Methods By Origin' ? 'filter_by_service_value' : 'minimum_shipping_charge_services';
     366            $services_arr = isset($settings[$filter_by_service]) ? $settings[$filter_by_service] : [];
    337367            if (empty($services_arr) || !is_array($services_arr)) return [];
    338368
    … …  
    380410            return $response;
    381411        }
     412
     413        function ups_small_get_service_rate($net_rate, $settings, $min_ship_charge)
     414        {
     415            $service_rate = $settings['service_rate'];
     416            if ($min_ship_charge) {
     417                $min_shipping_rate = isset($settings['minimum_shipping_charge']) ? $settings['minimum_shipping_charge'] : 0;
     418
     419                return $net_rate < $min_shipping_rate ? $min_shipping_rate : $net_rate;
     420            }
     421
     422            if (strpos($service_rate, '%') === false) return $service_rate;
     423
     424            // Calculate the percentage of service rate based on net rate and add it to net rate
     425            $service_rate = str_replace('%', '', $service_rate) / 100;
     426            $service_rate = floatval($net_rate) * floatval($service_rate);
     427            $net_rate = floatval($net_rate) + floatval($service_rate);
     428
     429            return $net_rate;
     430        }
     431
     432        function apply_free_shipping_rule($ups_small_package)
     433        {
     434            if (empty($ups_small_package)) return [];
     435
     436            global $wpdb;
     437            $rules = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "eniture_ups_small_shipping_rules"), ARRAY_A);
     438            if (empty($rules)) return [];
     439
     440            $filtered_products_ids = [];
     441
     442            // check if free shipping rule exists
     443            foreach ($rules as $rule) {
     444                if (!$rule['is_active'] || $rule['type'] != 'Free Shipping') continue;
     445
     446                // Eniture debug mode
     447                do_action("eniture_debug_mood", "UPS Small Free Shipping Rule", $rule);
     448
     449                $products = [];
     450                $product_tags = [];
     451                foreach ($ups_small_package as $package) {
     452                    if (!isset($package['items']) || empty($package['items'])) continue;
     453
     454                    $products = array_merge($products, $package['items']);
     455                    $product_tags = isset($package['product_tags']) && !empty($package['product_tags']) ? array_merge($product_tags, $package['product_tags']) : $product_tags;
     456                }
     457
     458                if (empty($products)) return [];
     459
     460                $settings = isset($rule['settings']) ? json_decode($rule['settings'], true) : [];
     461                $filters_checks = ['filter_by_weight', 'filter_by_price', 'filter_by_quantity', 'filter_by_product_tag'];
     462                $any_filter_checked = false;
     463
     464                foreach ($filters_checks as $check) {
     465                    if (isset($settings[$check]) && filter_var($settings[$check], FILTER_VALIDATE_BOOLEAN)) {
     466                        $any_filter_checked = true;
     467                        break;
     468                    }
     469                }
     470
     471                if (!$any_filter_checked) {
     472                    $rates = array(
     473                        'id' => 'ups_small:' . 'free',
     474                        'label' => 'Free Shipping',
     475                        'cost' => 0,
     476                        'plugin_name' => 'upsSmall',
     477                        'plugin_type' => 'small',
     478                        'owned_by' => 'eniture'
     479                    );
     480
     481                    return $rates;
     482                }
     483
     484                $is_filter_applied = false;
     485                $filters = ['weight', 'price', 'quantity', 'product_tag'];
     486                $count = 0;
     487
     488                foreach ($products as $product) {
     489                    $is_filter_applied = false;
     490                    $qty = isset($product['productQty']) ? $product['productQty'] : 1;
     491
     492                    $product['quantity'] = $qty;
     493                    $product['weight'] = isset($product['productWeight']) ? $product['productWeight'] * $qty : 1;
     494                    $product['price'] = isset($product['productPrice']) ? $product['productPrice'] * $qty : 1;
     495
     496                    foreach ($filters as $filter) {
     497                        if (isset($settings['filter_by_' . $filter]) && filter_var($settings['filter_by_' . $filter], FILTER_VALIDATE_BOOLEAN)) {
     498                            if ($filter == 'product_tag') {
     499                                $product_id = isset($product['variantId']) && $product['variantId'] > 0 ? $product['variantId'] : $product['productId'];
     500                                $parent_id = wp_get_post_parent_id($product_id);
     501                                $product_tags = get_the_terms($product_id, 'product_tag');
     502                                $product_tags = empty($product_tags) ? get_the_terms($parent_id, 'product_tag') : $product_tags;
     503                                $product_tag_ids = empty($product_tags) || !is_array($product_tags) ? [] : array_map(function($tag) { return $tag->term_id; }, $product_tags);
     504
     505                                if (isset($settings['filter_by_product_tag']) && filter_var($settings['filter_by_product_tag'], FILTER_VALIDATE_BOOLEAN)) {
     506                                    $rule_tags = $settings['filter_by_product_tag_value'];
     507                                    $tags_check = array_filter($rule_tags, function ($tag) use ($product_tag_ids) {
     508                                        return in_array($tag, $product_tag_ids);
     509                                    });
     510                                    $is_filter_applied = count($tags_check) > 0;
     511                                }
     512                            } else {
     513                                $is_filter_applied = $product[$filter] >= $settings['filter_by_' . $filter . '_from'];
     514                                if ($is_filter_applied && !empty($settings['filter_by_' . $filter . '_to'])) {
     515                                    $is_filter_applied = $product[$filter] < $settings['filter_by_' . $filter . '_to'];
     516                                }
     517                            }
     518                        }
     519
     520                        if ($is_filter_applied) break;
     521                    }
     522
     523                    if ($is_filter_applied) {
     524                        $count++;
     525                        $filtered_products_ids[] = $product['productId'];
     526                    }
     527                }
     528
     529                // If all products match the filter, return free shipping
     530                if ($is_filter_applied && $count == count($products)) {
     531                    $rates = array(
     532                        'id' => 'ups_small:' . 'free',
     533                        'label' => 'Free Shipping',
     534                        'cost' => 0,
     535                        'plugin_name' => 'upsSmall',
     536                        'plugin_type' => 'small',
     537                        'owned_by' => 'eniture'
     538                    );
     539
     540                    return [
     541                        'rates' => $rates,
     542                        'package' => $ups_small_package
     543                    ];
     544                }
     545            }
     546
     547            if (!empty($filtered_products_ids)) {
     548                foreach ($ups_small_package as $key => $package) {
     549                    foreach ($package['items'] as $ik => $item) {
     550                        if (in_array($item['productId'], $filtered_products_ids)) {
     551                            unset($ups_small_package[$key]['items'][$ik]);
     552                        }
     553                    }
     554                }
     555            }
     556
     557            return [
     558                'rates' => [],
     559                'package' => $ups_small_package
     560            ];
     561        }
     562
     563        function sanitize_request_data($data)
     564        {
     565            if (empty($data)) return $data;
     566
     567            if (is_array($data)) {
     568                foreach ($data as $key => $value) {
     569                    if (is_array($value)) {
     570                        $data[$key] = $this->sanitize_request_data($value);
     571                    } else {
     572                        $data[$key] =  isset($value) ? esc_attr(sanitize_text_field( wp_unslash($value) )) : '';
     573                    }
     574                }
     575            } else {
     576                $data = isset($data) ? esc_attr(sanitize_text_field( wp_unslash($data) )) : '';
     577            }
     578
     579            return $data;
     580        }
    382581    }
    383582}
  • small-package-quotes-ups-edition/trunk/shipping-rules/shipping-rules-template.php

    r3222153 r3237693  
    1616          "SELECT * FROM " . $wpdb->prefix . "eniture_ups_small_shipping_rules"
    1717      );
     18
     19      // Eniture debug mode
     20      do_action("eniture_debug_mood", "UPS Small Shipping Rules", $shipping_rules_list);
    1821
    1922      ?>
    … …  
    3033                      </th>
    3134                      <th class="en_wd_warehouse_list_heading">
    32                           Filters
    33                       </th>
    34                       <th class="en_wd_warehouse_list_heading">
    3535                          Available
    3636                      </th>
    … …  
    4848                  foreach ($shipping_rules_list as $rule) {
    4949                    $rule->settings = !empty($rule->settings) ? json_decode($rule->settings) : [];
    50                     $filter_name = in_array($rule->type, ['Hide Methods', 'Override Rates']) && isset($rule->settings->filter_name) ? $rule->settings->filter_name : '';
     50                    $rule_type = isset($rule->type) ? $rule->type : '';
     51                    $rule_type = $rule_type == 'Hide Methods By Origin' ? 'Hide Methods By Origin Location' : $rule_type;
    5152
    5253                    ?>
    5354                      <tr id="sr_row_<?php echo (isset($rule->id)) ? esc_attr($rule->id) : ''; ?>" class="en_ups_sr_row">
    5455                        <td class="en_wd_warehouse_list_data"><?php echo esc_attr($rule->name); ?></td>
    55                         <td class="en_wd_warehouse_list_data"><?php echo esc_attr($rule->type); ?></td>
    56                         <td class="en_wd_warehouse_list_data"><?php echo esc_attr($filter_name); ?></td>
     56                        <td class="en_wd_warehouse_list_data"><?php echo esc_attr($rule_type); ?></td>
    5757                        <td class="en_wd_warehouse_list_data">
    5858                          <a href="#" class="en_ups_sr_status_link" data-id="<?php echo (isset($rule->id)) ? esc_attr($rule->id) : ''; ?>" data-status="<?php echo esc_attr($rule->is_active); ?>"><?php echo esc_attr($rule->is_active) ? 'Yes' : 'No'; ?></a>
    … …  
    106106
    107107<!-- Shipping rules html markup -->
    108 <div class="en_shipping_rules_setting_section">
     108<div class="en_shipping_rules_setting_section ups_small_wrapper">
    109109    <br />
    110110    <!-- Add rule button -->
    … …  
    128128
    129129    <!-- Add popup for new rule -->
    130     <div id="en_wd_add_warehouse_btn" class="en_wd_warehouse_overlay">
     130    <div id="en_wd_add_warehouse_btn" class="en_wd_warehouse_overlay en_ups_small_sr_popup">
    131131        <div class="en_wd_add_warehouse_popup">
    132132            <h2 class="warehouse_heading">Add Rule</h2>
    … …  
    141141
    142142                <!-- Add shipping rule form -->
    143                 <form id="add_shipping_rule" role="form">
     143                <form id="add_shipping_rule" class="en_ups_small_sr_form" role="form">
    144144                    <input type="hidden" name="edit_sr_form_id" value="" id="edit_sr_form_id">
    145145                    <!-- Rule name -->
    … …  
    154154                        <label for="en_ups_small_rule_type">Type</label>
    155155                        <select name="en_ups_small_rule_type" id="en_ups_small_rule_type" title="Type">
     156                          <option value="Free Shipping">Free Shipping</option>
    156157                          <option value="Hide Methods">Hide Methods</option>
    157158                          <option value="Hide Methods By Origin">Hide Methods By Origin Location</option>
    158159                          <option value="Large Cart Settings">Large Cart Settings</option>
     160                          <option value="Minimum Shipping Charge">Minimum Shipping Charge</option>
    159161                          <option value="Override Rates">Override Rates</option>
    160162                          <option value="Restrict To State">Restrict To State</option>
    … …  
    174176                          <input type="radio" name="apply_to" value="shipment" title="Shipment"> <span>Shipment</span>
    175177                        </div>
    176                         <span class="en_sr_err"></span>
    177                     </div>
    178                    
     178                        <div id="en_sr_apply_to_product">
     179                          <div><p></p></div>
     180                          <input type="radio" name="apply_to" value="product" title="Product"> <span>Product</span>
     181                        </div>
     182                        <span class="en_sr_err"></span>
     183                    </div>
     184
     185                    <!-- Hide methods by origin location section -->
     186                    <div class="en_sr_hide_methods_by_origin_location">
     187                      <!-- Filter by Origins -->
     188                      <div class="en_sr_form_control">
     189                        <label for="en_ups_small_filter_by_origin" id="en_ups_small_filter_by_origin_label">
     190                            Origins
     191                        </label>
     192                      </div>
     193
     194                      <!-- Origins list -->
     195                      <div class="en_sr_form_control en_ups_small_sr_locations_list">
     196                        <select name="en_sr_locations_list" id="en_sr_locations_list" multiple="multiple" data-attribute="en_location_list_value" data-optional="1" class="chosen_select en_location_list_value" style="width: 100% !important;" title="Origins">
     197                          <?php
     198                            global $wpdb;
     199                            $warehouse_table = $wpdb->prefix . "warehouse";
     200                            $locations = $wpdb->get_results("SELECT * FROM $warehouse_table", ARRAY_A);
     201
     202                            if (isset($locations) && !empty($locations)) {
     203                              foreach ($locations as $key => $value) {
     204                                  $location = $value['city'] . ' ' . $value['state'] . ' ' . $value['zip'] . ', ' . $value['country'];
     205                                  echo "<option value='" . esc_attr($value['zip']) . "'>" . esc_html($location) . "</option>";
     206                              }
     207                            }
     208                          ?>
     209                        </select>
     210                        <span class="en_sr_err"></span>
     211                        <span class="descrption">
     212                          Shipping methods for the services listed below will be hidden for customers from these origins.
     213                        </span>
     214                      </div>
     215
     216                      <!-- Filter by Services -->
     217                      <div class="en_sr_form_control">
     218                        <label for="en_ups_small_filter_by_sevices" id="en_ups_small_filter_by_sevices_label">
     219                            Services
     220                        </label>
     221                      </div>
     222
     223                      <!-- Services list -->
     224                      <div class="en_sr_form_control en_ups_small_sr_services_list">
     225                        <select name="en_sr_services_list" id="en_sr_services_list" multiple="multiple" data-attribute="en_service_list_value" data-optional="1" class="chosen_select en_service_list_value" style="width: 100% !important;" title="Services">
     226                          <?php
     227                            $services = eniture_shipping_rules_get_services_list();
     228                            foreach ($services as $key => $value) {
     229                              echo "<option value='" . esc_attr($key) . "'>" . esc_html('UPS ' . $value) . "</option>";
     230                            }
     231                          ?>
     232                        </select>
     233                        <span class="en_sr_err"></span>
     234                      </div>
     235                    </div>
     236
     237                    <!-- Large cart settings section -->
     238                    <div class="en_ups_small_sr_large_cart_settings">
     239                      <div class="en_sr_form_control">
     240                        <p>
     241                          The packaging algorithm identifies the ideal packaging solution via an iterative process. If the Cart contains a large number of items, the time the packaging algorithm requires to identify the ideal packaging solution can exceed the window of time WordPress allows for shipping quotes to be returned. In these cases, the packaging algorithm needs to be bypassed. Use the settings below to specify your preferences for when the packaging algorithm is to be bypassed. Test the results to make sure results (shipping quotes) are returned when a large number of items is in the Cart. The number of boxes you define and the diversity of the items in your product catalog will influence the time the packaging algorithm requires. Therefore, your settings will differ from those of other merchants.
     242                        </p>
     243                      </div>
     244
     245                      <div class="en_sr_form_control">
     246                        <label for="en_sr_max_items">Max items <span style="color: red;">*</span></label>
     247                        <input type="text" title="Max items" name="en_sr_max_items" id="en_sr_max_items" data-optional="1" maxlength="10">
     248                        <span class="en_sr_err"></span>
     249                        <p class="description">When the Cart contains more than this number of items, the packaging algorithm will be bypassed and rates will be calculated exclusively on the basis of weight.</p>
     250                      </div>
     251
     252                      <div class="en_sr_form_control">
     253                        <label for="en_sr_max_weight_per_package">Max weight per package <span style="color: red;">*</span></label>
     254                        <input type="text" title="Max weight per package" name="en_sr_max_weight_per_package" id="en_sr_max_weight_per_package" data-optional="1" maxlength="10">
     255                        <span class="en_sr_err"></span>
     256                        <p class="description">Specify the maximum weight allowed per package when the packaging algorithm is bypassed. The maximum permitted value is 150 LB.</p>
     257                      </div>
     258                    </div>
     259
     260                    <!-- Minimum shipping charge section -->
     261                     <div class="en_sr_min_shipping_charge">
     262                      <!-- Minimum shipping charge -->
     263                      <div class="en_sr_form_control">
     264                          <label for="en_sr_minimum_shipping_charge">Minimum Shipping Rate</label>
     265                          <input type="text" title="Minimum shipping charge" name="en_sr_minimum_shipping_charge" id="en_sr_minimum_shipping_charge" data-optional="1" maxlength="7">
     266
     267                          <span class="en_sr_err"></span>
     268                          <span class="descrption">
     269                            Enter the min. shipping rate to show on checkout.
     270                        </span>
     271                      </div>
     272
     273                      <div class="en_sr_form_control">
     274                        <label for="en_ups_small_msc_filter_by_sevices" id="en_ups_small_msc_filter_by_sevices_label">
     275                            Services
     276                        </label>
     277                      </div>
     278
     279                      <!-- Services list -->
     280                      <div class="en_sr_form_control en_ups_small_msc_sr_services_list">
     281                        <select name="en_msc_sr_services_list" id="en_msc_sr_services_list" multiple="multiple" data-attribute="en_service_list_value" data-optional="1" class="chosen_select en_service_list_value" style="width: 100% !important;" title="Services">
     282                          <?php
     283                            $services = eniture_shipping_rules_get_services_list();
     284                            foreach ($services as $key => $value) {
     285                              echo "<option value='" . esc_attr($key) . "'>" . esc_html('UPS ' . $value) . "</option>";
     286                            }
     287                          ?>
     288                        </select>
     289                        <span class="en_sr_err"></span>
     290                      </div>
     291                     </div>
     292
    179293                    <!-- Override rates section -->
    180294                    <div class="en_sr_override_rates">
    … …  
    197311                      <!-- Service rate -->
    198312                      <div class="en_sr_form_control">
    199                           <label for="en_sr_service_rate">Service rate (e.g. 5.25)</label>
    200                           <input type="text" title="Service rate" name="en_sr_service_rate" id="en_sr_service_rate" data-optional="1" maxlength="10" data-optional="1">
     313                          <label for="en_ups_small_sr_service_rate">Service rate</label>
     314                          <input type="text" title="Service rate" name="en_ups_small_sr_service_rate" id="en_ups_small_sr_service_rate" data-optional="1" maxlength="10" data-optional="1" placeholder="Enter amount or percentage (e.g. 10, -5, 20%)">
    201315                          <span class="en_sr_err"></span>
    202316                      </div>
    … …  
    265379                    </div>
    266380
    267                     <!-- Large cart settings section -->
    268                     <div class="en_ups_small_sr_large_cart_settings">
    269                       <div class="en_sr_form_control">
    270                         <p>
    271                           The packaging algorithm identifies the ideal packaging solution via an iterative process. If the Cart contains a large number of items, the time the packaging algorithm requires to identify the ideal packaging solution can exceed the window of time WordPress allows for shipping quotes to be returned. In these cases, the packaging algorithm needs to be bypassed. Use the settings below to specify your preferences for when the packaging algorithm is to be bypassed. Test the results to make sure results (shipping quotes) are returned when a large number of items is in the Cart. The number of boxes you define and the diversity of the items in your product catalog will influence the time the packaging algorithm requires. Therefore, your settings will differ from those of other merchants.
    272                         </p>
    273                       </div>
    274 
    275                       <div class="en_sr_form_control">
    276                         <label for="en_sr_max_items">Max items <span style="color: red;">*</span></label>
    277                         <input type="text" title="Max items" name="en_sr_max_items" id="en_sr_max_items" data-optional="1" maxlength="10">
    278                         <span class="en_sr_err"></span>
    279                         <p class="description">When the Cart contains more than this number of items, the packaging algorithm will be bypassed and rates will be calculated exclusively on the basis of weight.</p>
    280                       </div>
    281 
    282                       <div class="en_sr_form_control">
    283                         <label for="en_sr_max_weight_per_package">Max weight per package <span style="color: red;">*</span></label>
    284                         <input type="text" title="Max weight per package" name="en_sr_max_weight_per_package" id="en_sr_max_weight_per_package" data-optional="1" maxlength="10">
    285                         <span class="en_sr_err"></span>
    286                         <p class="description">Specify the maximum weight allowed per package when the packaging algorithm is bypassed. The maximum permitted value is 150 LB.</p>
    287                       </div>
    288                     </div>
    289 
    290                     <!-- Hide methods by origin location section -->
    291                      <div class="en_sr_hide_methods_by_origin_location">
    292                       <!-- Filter by Origins -->
    293                       <div class="en_sr_form_control">
    294                         <label for="en_ups_small_filter_by_origin" id="en_ups_small_filter_by_origin_label">
    295                            Origins
    296                         </label>
    297                       </div>
    298 
    299                       <!-- Origins list -->
    300                       <div class="en_sr_form_control en_ups_small_sr_locations_list">
    301                         <select name="en_sr_locations_list" id="en_sr_locations_list" multiple="multiple" data-attribute="en_location_list_value" data-optional="1" class="chosen_select en_location_list_value" style="width: 100% !important;" title="Origins">
    302                           <?php
    303                             global $wpdb;
    304                             $warehouse_table = $wpdb->prefix . "warehouse";
    305                             $locations = $wpdb->get_results("SELECT * FROM $warehouse_table", ARRAY_A);
    306 
    307                             if (isset($locations) && !empty($locations)) {
    308                               foreach ($locations as $key => $value) {
    309                                   $location = $value['city'] . ' ' . $value['state'] . ' ' . $value['zip'] . ', ' . $value['country'];
    310                                   echo "<option value='" . esc_attr($value['zip']) . "'>" . esc_html($location) . "</option>";
    311                               }
    312                             }
    313                           ?>
    314                         </select>
    315                         <span class="en_sr_err"></span>
    316                         <span class="descrption">
    317                           Shipping methods for the services listed below will be hidden for customers from these origins.
    318                         </span>
    319                       </div>
    320 
    321                       <!-- Filter by Services -->
    322                       <div class="en_sr_form_control">
    323                         <label for="en_ups_small_filter_by_sevices" id="en_ups_small_filter_by_sevices_label">
    324                            Services
    325                         </label>
    326                       </div>
    327 
    328                       <!-- Services list -->
    329                       <div class="en_sr_form_control en_ups_small_sr_services_list">
    330                         <select name="en_sr_services_list" id="en_sr_services_list" multiple="multiple" data-attribute="en_service_list_value" data-optional="1" class="chosen_select en_service_list_value" style="width: 100% !important;" title="Services">
    331                           <?php
    332                             $services = eniture_shipping_rules_get_services_list();
    333                             foreach ($services as $key => $value) {
    334                               echo "<option value='" . esc_attr($key) . "'>" . esc_html('UPS ' . $value) . "</option>";
    335                             }
    336                           ?>
    337                         </select>
    338                         <span class="en_sr_err"></span>
    339                       </div>
    340                      </div>
    341 
    342381                    <!-- Filters section -->
    343382                    <div class="en_ups_small_sr_filters_section">
    344                       <!-- Filter name -->
    345                       <div class="en_sr_form_control">
    346                           <label for="en_sr_filter_name">Filter Name</label>
    347                           <input type="text" title="Filter Name" name="en_sr_filter_name" id="en_sr_filter_name" data-optional="1" maxlength="50">
    348                           <span class="en_sr_err"></span>
    349                       </div>
    350 
    351383                      <!-- Filter by Weight -->
    352384                      <div class="en_sr_form_control">
    … …  
    446478                    </div>
    447479
     480                    <!-- Override Rates Filters -->
     481                    <div class="en_or_sr_filters">
     482                        <!-- Filter by Country -->
     483                        <section>
     484                          <div class="en_sr_form_control">
     485                            <div>
     486                              <label for="filter_by_country_or">
     487                                <input type="checkbox" title="Filter by country" name="filter_by_country_or" id="filter_by_country_or"> Filter by country
     488                              </label>
     489                            </div>
     490                          </div>
     491                          <!-- Country list -->
     492                          <div class="en_sr_form_control">
     493                            <select name="en_ups_small_or_sr_country" id="en_ups_small_or_sr_country" title="Countries">
     494                              <option value="">Select One</option>
     495                              <option value="US">US</option>
     496                              <option value="CA">CA</option>
     497                            </select>
     498
     499                            <span class="en_sr_err"></span>
     500                          </div>
     501                        </section>
     502
     503                        <!-- Filter by State -->
     504                        <section>
     505                          <div class="en_sr_form_control">
     506                            <div>
     507                              <label for="filter_by_state_or">
     508                                <input type="checkbox" title="Filter by state" name="filter_by_state_or" id="filter_by_state_or"> Filter by state
     509                              </label>
     510                            </div>
     511                            <span class="en_sr_err"></span>
     512                          </div>
     513
     514                          <!-- US States list -->
     515                          <div class="en_sr_form_control en_ups_small_or_sr_us_states_list">
     516                            <select name="en_or_sr_states_list" id="en_or_sr_states_list" multiple="multiple" data-attribute="en_state_list_value" data-optional="1" class="chosen_select en_state_list_value" style="width: 100% !important;" title="States/Provinces">
     517                              <?php
     518                                global $woocommerce;
     519                                $countries_obj = new WC_Countries();
     520                                $us_states = $countries_obj->get_states('US');
     521
     522                                if (isset($us_states) && !empty($us_states)) {
     523                                  foreach ($us_states as $key => $value) {
     524                                      echo "<option class='or_us_state' value='" . esc_attr($key) . "'>" . esc_html($value) . "</option>";
     525                                  }
     526                              }
     527                            ?>
     528                            </select>
     529
     530                            <span class="en_sr_err"></span>
     531                            <span class="descrption">
     532                              Only customers from these states/provinces will be presented with shipping rates for this provider.
     533                            </span>
     534                          </div>
     535
     536                          <!-- CA States list -->
     537                          <div class="en_sr_form_control en_ups_small_or_sr_ca_states_list">
     538                            <select name="en_or_sr_states_list" id="en_or_sr_states_list" multiple="multiple" data-attribute="en_state_list_value" data-optional="1" class="chosen_select en_state_list_value" style="width: 100% !important;" title="States/Provinces">
     539                              <?php
     540                                global $woocommerce;
     541                                $countries_obj = new WC_Countries();
     542                                $ca_states = $countries_obj->get_states('CA');
     543
     544                                if (isset($ca_states) && !empty($ca_states)) {
     545                                    foreach ($ca_states as $key => $value) {
     546                                        echo "<option class='or_ca_state' value='" . esc_attr($key) . "'>" . esc_html($value) . "</option>";
     547                                    }
     548                                }
     549                            ?>
     550                            </select>
     551
     552                            <span class="en_sr_err"></span>
     553                            <span class="descrption">
     554                              Only customers from these states/provinces will be presented with shipping rates for this provider.
     555                            </span>
     556                          </div>
     557
     558                          <!-- Empty states list -->
     559                          <div class="en_sr_form_control en_ups_small_or_empty_sr_states_list">
     560                            <select name="en_or_empty_sr_states_list" id="en_or_empty_sr_states_list" multiple="multiple" data-attribute="en_state_list_value" data-optional="1" class="chosen_select en_state_list_value" style="width: 100% !important;" title="States/Provinces">
     561                            </select>
     562
     563                            <span class="en_sr_err"></span>
     564                          </div>
     565                        </section>
     566                    </div>
     567
    448568                    <!-- Available checkbox -->
    449569                    <div class="en_sr_form_control">
  • small-package-quotes-ups-edition/trunk/small-package-quotes-ups-edition.php

    r3222153 r3237693  
    44 * Plugin URI:     https://eniture.com/products/
    55 * Description:    Dynamically retrieves your negotiated shipping rates from UPS and displays the results in the WooCommerce shopping cart.
    6  * Version:        4.5.16
     6 * Version:        4.5.17
    77 * Author:         Eniture Technology
    88 * Author URI:     http://eniture.com/
    … …  
    102102
    103103        // Shipping rules script and styles
    104         wp_enqueue_script('en_woo_sr_script', plugin_dir_url(__FILE__) . '/shipping-rules/assets/js/shipping_rules.js', array(), '1.0.5');
    105         wp_localize_script('en_woo_sr_script', 'script', array(
     104        wp_enqueue_script('en_woo_sr_script', plugin_dir_url(__FILE__) . '/shipping-rules/assets/js/shipping_rules.js', array(), '1.0.6');
     105        wp_localize_script('en_woo_sr_script', 'sr_script', array(
    106106            'pluginsUrl' => plugins_url(),
     107            'nonce' => wp_create_nonce('en_woo_sr_nonce')
    107108        ));
    108         wp_register_style('shipping_rules_section', plugin_dir_url(__FILE__) . '/shipping-rules/assets/css/shipping_rules.css', false, '1.0.2');
     109        wp_register_style('shipping_rules_section', plugin_dir_url(__FILE__) . '/shipping-rules/assets/css/shipping_rules.css', false, '1.0.3');
    109110        wp_enqueue_style('shipping_rules_section');
    110111    }
    … …  
    186187    {
    187188
    188         wp_register_style('eniture_ups_small_style', plugin_dir_url(__FILE__) . '/css/ups-small-style.css', false, '1.1.7');
     189        wp_register_style('eniture_ups_small_style', plugin_dir_url(__FILE__) . '/css/ups-small-style.css', false, '1.1.8');
    189190        wp_enqueue_style('eniture_ups_small_style');
    190191    }
    … …  
    223224    {
    224225        wp_enqueue_script('jquery');
    225         wp_enqueue_script('eniture_ups_small_script', plugin_dir_url(__FILE__) . 'js/en-ups-small.js', array(), '1.0.8');
     226        wp_enqueue_script('eniture_ups_small_script', plugin_dir_url(__FILE__) . 'js/en-ups-small.js', array(), '1.0.9');
    226227        wp_localize_script('eniture_ups_small_script', 'eniture_ups_small_admin_script', array(
    227228            'plugins_url' => plugins_url(),
    … …  
    229230            'prevent_proceed_checkout_eniture' => trim(get_option("prevent_proceed_checkout_eniture")),
    230231            'ups_small_order_cutoff_time' => get_option("ups_small_orderCutoffTime"),
    231             'ups_small_packaging_type' => get_option("ups_small_packaging_type")
     232            'ups_small_packaging_type' => get_option("ups_small_packaging_type"),
     233            'nonce' => wp_create_nonce('eniture_ups_small_nonce')
    232234        ));
    233235    }
    … …  
    490492function eniture_ups_s_fd_api()
    491493{
     494    if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'eniture_ups_small_nonce')) {
     495        echo wp_json_encode([]);
     496        return;
     497    }
     498
    492499    $store_name = eniture_ups_small_get_domain();
    493500    $company_id = isset($_POST['company_id']) ? sanitize_text_field(wp_unslash($_POST['company_id'])) : '';
    … …  
    499506    ];
    500507    if (is_array($data) && count($data) > 0) {
    501         if(isset($_POST['disconnect']) && sanitize_text_field(wp_unslash($_POST['disconnect'])) != 'disconnect') {
     508        if($_POST['disconnect'] != 'disconnect') {
    502509            $url =  'https://freightdesk.online/validate-company';
    503510        }else {
    … …  
    535542/**
    536543 * Update FDO coupon data
    537  * @param array $request
     544 * @param array|WP_REST_Request $request
    538545 * @return array|void
    539546 */
    540547function eniture_ups_s_fdo_data_status(WP_REST_Request $request)
    541548{
     549    $authenticated_user = fdo_update_status_authenticate($request);
     550    if (is_wp_error($authenticated_user)) {
     551        return $authenticated_user;
     552    }
     553
    542554    $status_data = $request->get_body();
    543555    $status_data_decoded = json_decode($status_data);
    … …  
    549561}
    550562
     563// fdo / va api calls authentication
     564if (!function_exists('fdo_update_status_authenticate')) {
     565    function fdo_update_status_authenticate($request) {
     566        if ( !empty( $_SERVER['HTTP_CONSUMER_KEY'] ) && !empty( $_SERVER['HTTP_CONSUMER_SECRET'] ) ) {
     567            $consumer_key    = $_SERVER['HTTP_CONSUMER_KEY'];
     568            $consumer_secret = $_SERVER['HTTP_CONSUMER_SECRET'];
     569        }else{
     570            return new WP_Error('rest_authentication_error', __('Invalid Authorization header format.'), array('status' => 401));
     571        }
     572   
     573        global $wpdb;
     574        $consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
     575        $user         = $wpdb->get_row(
     576            $wpdb->prepare(
     577                "
     578            SELECT user_id, permissions
     579            FROM {$wpdb->prefix}woocommerce_api_keys
     580            WHERE consumer_key = %s
     581        ",
     582                $consumer_key
     583            )
     584        );
     585   
     586        if (!$user) {
     587            return new WP_Error('invalid_keys', __('Invalid consumer key or secret.'), array('status' => 401));
     588        }
     589   
     590        if (empty($user->permissions) || $user->permissions != 'read_write') {
     591            return new WP_Error('rest_forbidden', __('User does not have write permissions.'), array('status' => 403));
     592        }
     593   
     594        return $user;
     595    }
     596}
     597
    551598/**
    552599 * Filter to check ground transit status
  • small-package-quotes-ups-edition/trunk/template/connection-settings.php

    r3147523 r3237693  
    2323        $default_api = empty(get_option('ups_small_username')) ? 'ups_new_api' : 'ups_old_api';
    2424       
    25         echo '<div class="ups_small_connection_section">';
     25        echo '<div class="ups_small_connection_section ups_small_wrapper">';
    2626        $settings = array(
    2727            'section_title_ups_small' => array(
  • small-package-quotes-ups-edition/trunk/template/csv-export.php

    r3147523 r3237693  
    55}
    66
    7 if (!class_exists('Eniture_CsvExport')) {
    8 
    9     class Eniture_CsvExport
     7if (!class_exists('EnCsvExport')) {
     8
     9    class EnCsvExport
    1010    {
    1111        public function __construct()
    … …  
    5050            if (isset($columns['meta:_ltl_freight_variation'])) {
    5151                unset($columns['meta:_ltl_freight_variation']);
     52            }
     53
     54            $nested_mat_cols = ['_nestedmaterials', '_nestedpercentage', '_nesteddimension', '_maxnesteditems', '_nestedstakingproperty'];
     55            foreach ($nested_mat_cols as $nested_mat_col) {
     56                if (isset($columns['meta:' . $nested_mat_col])) {
     57                    unset($columns['meta:' . $nested_mat_col]);
     58                }
     59
     60                if (isset($columns['Meta:' . $nested_mat_col])) {
     61                    unset($columns['Meta:' . $nested_mat_col]);
     62                }
    5263            }
    5364
    … …  
    261272    }
    262273
    263     new Eniture_CsvExport();
     274    new EnCsvExport();
    264275}
  • small-package-quotes-ups-edition/trunk/template/guide.php

    r1785132 r3237693  
    1414 */
    1515?>
    16 <div class="user_guide">
     16<div class="user_guide ups_small_wrapper">
    1717    <p>
    1818        The User Guide for this application is maintained on the publisher's website. To view it click
  • small-package-quotes-ups-edition/trunk/template/products-nested-options.php

    r3147523 r3237693  
    77    exit;
    88}
    9 if (!class_exists("Eniture_UpdateProductNestedOptions")) {
    10 
    11     class Eniture_UpdateProductNestedOptions
     9if (!class_exists("EnUpdateProductNestedOptions")) {
     10
     11    class EnUpdateProductNestedOptions
    1212    {
    1313
    … …  
    221221
    222222    /* Initialize object */
    223     new Eniture_UpdateProductNestedOptions('hooks');
     223    new EnUpdateProductNestedOptions('hooks');
    224224}
  • small-package-quotes-ups-edition/trunk/template/quote-settings.php

    r3159756 r3237693  
    8585        //**End: Cut Off Time & Ship Date Offset
    8686
    87         echo '<div class="ups_small_quote_section">';
     87        echo '<div class="ups_small_quote_section ups_small_wrapper">';
    8888
    8989        $settings = array(
  • small-package-quotes-ups-edition/trunk/update-plan.php

    r3147523 r3237693  
    1616function eniture_ups_small_activate_hit_to_update_plan($network_wide = null)
    1717{
     18    if (!current_user_can('manage_options')) {
     19        echo json_encode([]);
     20        return;
     21    }
     22
    1823    if ( is_multisite() && $network_wide ) {
    1924
    … …  
    244249
    245250                if (isset($plan_package['plan_number']) && $plan_package['plan_number'] == '0') {
    246                     echo '<div class="notice notice-success is-dismissible">
     251                    echo '<div class="notice notice-success is-dismissible ups_small_plan_notice">
    247252                    <p> You are currently on the ' . esc_attr( $plan_package['plan_name'] ) . '. Your plan will be expire on ' .  esc_attr( $plan_package['expiry_date'] ) . ' <a href="javascript:void(0)" data-action="eniture_ups_small_activate_hit_to_update_plan" onclick="en_update_plan(this);">Click here</a> to refresh the plan.</p>
    248253                    </div>';
    249254                } else if (isset($plan_package['plan_number']) && ($plan_package['plan_number'] == '1' || $plan_package['plan_number'] == '2' || $plan_package['plan_number'] == '3')) {
    250255
    251                     echo '<div class="notice notice-success is-dismissible">
     256                    echo '<div class="notice notice-success is-dismissible ups_small_plan_notice">
    252257                    <p> You are currently on the ' . esc_attr( $plan_package['plan_name'] ) . '. The plan renews on ' . esc_attr( $plan_package['expiry_date'] ) . ' <a href="javascript:void(0)" data-action="eniture_ups_small_activate_hit_to_update_plan" onclick="en_update_plan(this);">Click here</a> to refresh the plan.</p>
    253258                    </div>';
    254259                } else {
    255                     echo '<div class="notice notice-warning is-dismissible">
     260                    echo '<div class="notice notice-warning is-dismissible ups_small_plan_notice">
    256261                    <p>Your currently plan subscription is inactive. <a href="javascript:void(0)" data-action="eniture_ups_small_activate_hit_to_update_plan" onclick="en_update_plan(this);">Click here</a> to refresh the plan to check the subscription status. If the subscription status remains inactive, log into eniture.com and update your license.</p>
    257262                    </div>';
  • small-package-quotes-ups-edition/trunk/ups-small-admin-filter.php

    r3206249 r3237693  
    173173                        $metaValue[3] = $locations[3][$key];
    174174                        $metaValue[4] = $locations[4][$key];
    175                         $dsId[] = eniture_serialize_dropship($metaValue);
     175                        $dsId[] = en_serialize_dropship($metaValue);
    176176                    }
    177177                }
    178178            } else {
    179                 $dsId[] = eniture_serialize_dropship($_dropship_location);
     179                $dsId[] = en_serialize_dropship($_dropship_location);
    180180            }
    181181
    … …  
    199199 */
    200200
    201 if (!function_exists('eniture_serialize_dropship')) {
    202     function eniture_serialize_dropship($metaValue)
     201if (!function_exists('en_serialize_dropship')) {
     202    function en_serialize_dropship($metaValue)
    203203    {
    204204        global $wpdb;
    … …  
    215215
    216216        if (empty($dropship['id'])) {
    217             $data = eniture_csv_import_dropship_data($metaValue);
     217            $data = en_csv_import_dropship_data($metaValue);
    218218            $wpdb->insert(
    219219                $wpdb->prefix . 'warehouse', $data
    … …  
    234234 * @return array
    235235 */
    236 if (!function_exists('eniture_csv_import_dropship_data')) {
    237     function eniture_csv_import_dropship_data($metaValue)
     236if (!function_exists('en_csv_import_dropship_data')) {
     237    function en_csv_import_dropship_data($metaValue)
    238238    {
    239239        return array(
  • small-package-quotes-ups-edition/trunk/ups-small-carrier-service.php

    r3219695 r3237693  
    479479        $response_json = $ups_Small_distance_request->ups_small_address($warehous_list, $accessLevel, $this->destinationAddressUpsSmall());
    480480        $response_json = json_decode($response_json, TRUE);
     481
     482        // Eniture debug mood
     483        do_action("eniture_debug_mood", "Multi Warehouse Distance Response (UPS Small)", $response_json);
     484
    481485        return $response_json['origin_with_min_dist'];
    482486    }
  • small-package-quotes-ups-edition/trunk/ups-small-group-package.php

    r3219695 r3237693  
    2727    public $destination_Address_ups_small;
    2828    public $origin = [];
     29    public $shipping_rule_object;
    2930    // Images for FDO
    3031    public $en_fdo_image_urls = [];
    … …  
    156157                $width = (strlen($width) > 0) ? $width : "0";
    157158                $length = (strlen($length) > 0) ? $length : "0";
    158                
     159
    159160                $product_weight = apply_filters('en_filter_product_weight', wc_get_weight($_product->get_weight(), 'lbs'), $item_id);
    160161
    … …  
    174175                    }
    175176                }
    176                
     177
    177178                $product_level_markup = $this->ups_small_get_product_level_markup($_product, $values['variation_id'], $product_id, $values['quantity']);
    178179
    … …  
    468469        if ($freight_enable_class == 'ltl_freight' || $freight_enable_class == 'ltl-freight') {
    469470            $ptype = 'ltl';
    470         } else if ($exceedWeight == 'yes' 
     471        } else if ($exceedWeight == 'yes'
    471472        && ( ($weight > $weight_threshold && $en_multiple_package != 'yes') || (!empty($only_show_ltl_rates) && $only_show_ltl_rates == 'yes' && $shipment_weight_sum > $weight_threshold) )) {
    472473            $ptype = 'ltl';
    … …  
    475476        }
    476477
     478        // Eniture debug mode
     479        do_action("eniture_debug_mood", "Quotes Product Type (UPS Small)", $ptype);
     480
    477481        return $ptype;
    478482    }
    … …  
    481485     * Hazardous Material in Product Detail page
    482486     * @param array $values
    483      * @param array $_product
     487     * @param array|object $_product
    484488     * @return string
    485489     */
    … …  
    493497     *
    494498     * @param array $values
    495      * @param array $_product
     499     * @param array|object $_product
    496500     * @return string
    497501     */
    … …  
    520524                // Micro Warehouse
    521525                $this->warehouse_products[] = $post_id;
    522                 return array('error' => 'wwe small dp location not found!');
     526
     527                // Eniture debug mode
     528                do_action("eniture_debug_mood", "Quotes Dropship Location (UPS Small)", array('error' => 'UPS Small dropship location not found!'));
     529
     530                return array('error' => 'UPS Small dropship location not found!');
    523531            }
    524532
    … …  
    536544                    "SELECT * FROM " . $wpdb->prefix . "warehouse WHERE id IN ('" . $get_loc . "')"
    537545                );
     546            }
     547
     548            if (empty($locations_list)) {
     549                // Eniture debug mode
     550                do_action("eniture_debug_mood", "Quotes Dropship Location (UPS Small)", array('error' => 'UPS Small dropship location not found!'));
    538551            }
    539552
    … …  
    658671    {
    659672        $product_level_markup = 0;
    660            
     673
    661674            if ($_product->get_type() == 'variation') {
    662675                $product_level_markup = get_post_meta($variation_id, '_en_product_markup_variation', true);
    … …  
    667680                $product_level_markup = get_post_meta($_product->get_id(), '_en_product_markup', true);
    668681            }
    669            
     682
    670683            if (empty($product_level_markup)) {
    671684                $product_level_markup = get_post_meta($product_id, '_en_product_markup', true);
    672685            }
    673686
    674             if (!empty($product_level_markup) && strpos($product_level_markup, '%') === false 
     687            if (!empty($product_level_markup) && strpos($product_level_markup, '%') === false
    675688            && is_numeric($product_level_markup) && is_numeric($quantity))
    676689            {
    … …  
    682695                $percentage_value = $arr[0];
    683696                $product_price = $_product->get_price();
    684    
     697
    685698                if (!empty($product_price)) {
    686699                    $product_level_markup = $percentage_value / 100 * ($product_price * $quantity);
    … …  
    689702                }
    690703            }
    691    
     704
    692705            return $product_level_markup;
    693706    }
    … …  
    696709     * Check except transit time restriction
    697710     * @param array $values
    698      * @param array $_product
     711     * @param array|object $_product
    699712     * @return string
    700713     */
    … …  
    730743
    731744        if (empty($rules)) return $apply_on_rates ? $rates : false;
    732        
     745
    733746        $is_rule_applied = false;
    734         $rule_types = ['override_rates' => 'Override Rates', 'hide_methods' => 'Hide Methods', 'restrict_to_state' => 'Restrict To State', 'hide_methods_by_origin' => 'Hide Methods By Origin'];
     747        $rule_types = ['override_rates' => 'Override Rates', 'hide_methods' => 'Hide Methods', 'restrict_to_state' => 'Restrict To State', 'hide_methods_by_origin' => 'Hide Methods By Origin', 'minimum_shipping_charge' => 'Minimum Shipping Charge'];
    735748
    736749        foreach ($rules as $rule) {
    … …  
    741754
    742755            $rule_type = isset($rule['type']) ? $rule['type'] : '';
     756            $rule_name = isset($rule['name']) ? $rule['name'] : '';
    743757
    744758            if ($rule_type == $rule_types['override_rates'] && $apply_on_rates) {
    745                 $rates = $this->apply_override_rates_rule($ups_small_package, $settings, $rates);
     759                $rates = $this->apply_override_rates_rule($ups_small_package, $settings, $rates, $rule_name);
    746760            } else if ($rule_type == $rule_types['hide_methods']) {
    747761                $is_rule_applied = $this->apply_rule($settings, $ups_small_package);
    … …  
    749763            } else if ($rule_type == $rule_types['restrict_to_state'] && $apply_on_rates) {
    750764                $rates = $this->apply_restrict_to_state_rule($ups_small_package, $settings, $rates);
     765
     766                // Eniture debug mode
     767                do_action("eniture_debug_mood", "UPS Small Restrict To State Rule Updated Rates: {$rule_name}", wp_json_encode($rates));
    751768            } else if ($rule_type == $rule_types['hide_methods_by_origin'] && $apply_on_rates) {
    752769                $rates = $this->apply_hide_methods_by_origin_rule($settings, $rates);
     770            } else if ($rule_type == $rule_types['minimum_shipping_charge'] && $apply_on_rates) {
     771                $rates = $this->apply_minimum_shipping_charge_rule($ups_small_package, $settings, $rates, $rule_name);
    753772            }
    754773        }
    … …  
    777796        }
    778797
     798        // Eniture debug mode
     799        do_action("eniture_debug_mood", "UPS Small Hide Methods Rule Applied", $is_rule_applied ? 'Yes' : 'No');
     800
    779801        return $is_rule_applied;
    780802    }
    … …  
    794816    }
    795817
    796     function apply_rule_filters($settings, $formatted_values, $restict_service = false)
     818    function apply_rule_filters($settings, $formatted_values, $restict_service = false, $override_rates = false)
    797819    {
    798820        $is_filter_applied = false;
    799821        $filters = ['weight', 'price', 'quantity'];
    800822        // Add restrict service filters in case of restrict to state rule
    801         $filters = $restict_service ? array_merge(['country'], $filters) : $filters;
     823        $filters = ($restict_service || $override_rates) ? array_merge(['country'], $filters) : $filters;
    802824
    803825        // Check if any of the filter is checked
    804         $filters_checks = ['filter_by_weight', 'filter_by_price', 'filter_by_quantity', 'filter_by_product_tag', 'filter_by_country', 'filter_by_state'];
     826        $filters_checks = ['filter_by_weight', 'filter_by_price', 'filter_by_quantity', 'filter_by_product_tag', 'filter_by_country', 'filter_by_state', 'filter_by_country_or', 'filter_by_state_or'];
    805827        $any_filter_checked = false;
    806828        foreach ($filters_checks as $check) {
    … …  
    819841
    820842        foreach ($filters as $filter) {
    821             if (filter_var($settings['filter_by_' . $filter], FILTER_VALIDATE_BOOLEAN)) {
     843            $override_rate_filter = isset($settings['filter_by_' . $filter . '_or']) ? filter_var($settings['filter_by_' . $filter . '_or'], FILTER_VALIDATE_BOOLEAN) : false;
     844
     845            if (filter_var($settings['filter_by_' . $filter], FILTER_VALIDATE_BOOLEAN) || $override_rate_filter) {
    822846                if ($filter == 'country') {
    823847                    $destination_country = isset($destination_address['country']) ? $destination_address['country'] : '';
    824                     $this->is_dest_country_matched = $this->is_country_matched($settings['filter_by_country_value'],$destination_country);
     848                    $filter_by_country = $override_rate_filter ? 'filter_by_country_value_or' : 'filter_by_country_value';
     849                    $this->is_dest_country_matched = $this->is_country_matched($settings[$filter_by_country], $destination_country);
    825850                    $is_filter_applied = $this->is_dest_country_matched;
    826851                    $this->is_country_filter_applied = true;
    827852
    828                     if ($is_filter_applied && filter_var($settings['filter_by_state'], FILTER_VALIDATE_BOOLEAN)) {
     853                    $filter_by_state = $override_rate_filter ? 'filter_by_state_or' : 'filter_by_state';
     854                    $filter_by_state_value = $override_rate_filter ? 'filter_by_state_value_or' : 'filter_by_state_value';
     855
     856                    if ($is_filter_applied && filter_var($settings[$filter_by_state], FILTER_VALIDATE_BOOLEAN)) {
    829857                        $destination_state = isset($destination_address['state']) ? $destination_address['state'] : '';
    830                         $states = isset($settings['filter_by_state_value']) ? $settings['filter_by_state_value'] : [];
     858                        $states = isset($settings[$filter_by_state_value]) ? $settings[$filter_by_state_value] : [];
    831859                        $is_filter_applied = $this->is_dest_country_matched = in_array($destination_state, $states);
    832860                    }
    … …  
    853881    }
    854882
    855     function apply_override_rates_rule($ups_small_package, $settings, $rates)
     883    function apply_override_rates_rule($ups_small_package, $settings, $rates, $rule_name)
    856884    {
    857885        $updated_rates = $rates;
    … …  
    859887        foreach ($ups_small_package as $org_zip => $pkg) {
    860888            $is_rule_applied = false;
     889            $this->is_country_filter_applied = false;
     890            $this->is_dest_country_matched = false;
    861891            $shipments = [];
    862892            $org_zip = isset($pkg['zip']) ? $pkg['zip'] : $org_zip;
    … …  
    864894
    865895            $formatted_values = $this->get_formatted_values($shipments);
    866             $is_rule_applied = $this->apply_rule_filters($settings, $formatted_values);
     896            $is_rule_applied = $this->apply_rule_filters($settings, $formatted_values, false, true);
    867897
    868898            if ($is_rule_applied) {
    869                 $updated_rates = $this->get_updated_rates($updated_rates, $settings, false, $org_zip);
     899                $updated_rates = $this->get_updated_rates($updated_rates, $settings, false, $org_zip, false);
    870900            };
    871901        }
    872902
     903        // Eniture debug mode
     904        $data = ['rule_name' => $rule_name, 'settings' => $settings, 'rates' => json_encode($rates), 'updated_rates' => json_encode($updated_rates)];
     905        do_action("eniture_debug_mood", "UPS Small Override Rates Rule Applied: {$rule_name}", $data);
     906
    873907        return $updated_rates;
    874908    }
    875909
    876     function apply_restrict_to_state_rule($ups_small_package, $settings, $rates)
    877     {
     910    function apply_restrict_to_state_rule($ups_small_package, $settings, $rates)
     911    {
     912        $this->is_country_filter_applied = false;
     913        $this->is_dest_country_matched = false;
     914
    878915        $formatted_values = $this->get_formatted_values($ups_small_package);
    879916        $is_rule_applied = $this->apply_rule_filters($settings, $formatted_values, true);
    880917        $this->is_restrict_service_rule_applied = $is_rule_applied;
    881918
    882         return ($is_rule_applied || ($this->is_country_filter_applied && !$this->is_dest_country_matched)) ? $this->get_updated_rates($rates, $settings, true) : $rates;
    883     }
    884 
    885     function get_updated_rates($rates, $settings, $restict_service = false, $org_zip = '')
     919        // Eniture debug mode
     920        do_action("eniture_debug_mood", "UPS Small Restrict To State Rule Applied", $is_rule_applied ? 'Yes' : 'No');
     921
     922        return ($is_rule_applied || ($this->is_country_filter_applied && !$this->is_dest_country_matched)) ? $this->get_updated_rates($rates, $settings, true, '', false) : $rates;
     923    }
     924
     925    function get_updated_rates($rates, $settings, $restict_service = false, $org_zip = '', $min_shipping_charge = false)
    886926    {
    887927        if ($restict_service) {
    888928            if ($this->is_country_filter_applied && !$this->is_dest_country_matched) {
    889929                $rates_keys = ['q', 'ups_rate', 'GFP', 'q_92', 'q_93', 'q_94', 'q_95', 'usrg', 'usr2', 'usr1', 'usr3'];
    890                
     930
    891931                foreach ($rates as $key => $value) {
    892932                    foreach ($rates_keys as $rates_key) {
    … …  
    896936            }
    897937        } else {
     938            $this->shipping_rule_object = new Eniture_UpsSmallShippingRulesAjaxReq();
     939
    898940            foreach ($rates as $key => $result) {
    899                 if ($key != $org_zip) continue;
     941                if ($key != $org_zip && !empty($org_zip)) continue;
    900942
    901943                $ups_quotes = (isset($result->q) && !empty($result->q)) ? $result->q : [];
    … …  
    904946                $rates_key = isset($result->ups_rate) ? 'ups_rate' : $rates_key;
    905947                $simple_rate_services = ['usrg', 'usr2', 'usr1', 'usr3'];
    906    
     948
    907949                if (empty($ups_quotes)) continue;
    908    
     950
    909951                foreach ($ups_quotes as $service_key => $val) {
    910952                    $rate_arr = $this->get_rate_arr($val);
    911953                    $service_code = isset($settings['service']) ? $settings['service'] : '';
    912                    
     954
     955                    // minimum shipping charge settings
     956                    $msc_service_exists = false;
     957                    if ($min_shipping_charge) {
     958                        $services_codes = isset($settings['minimum_shipping_charge_services']) ? $settings['minimum_shipping_charge_services'] : [];
     959                        $msc_service_exists = in_array($rate_arr->Service->Code, $services_codes) || in_array($service_key, $services_codes);
     960                    }
     961
    913962                    // Replace service rate with new rate defined in the shipping rule
    914                     if (isset($rate_arr->Service->Code) && $rate_arr->Service->Code == $service_code && $rates_key != '') {
     963                    if (isset($rate_arr->Service->Code) && ($rate_arr->Service->Code == $service_code || $msc_service_exists) && $rates_key != '') {
    915964                        if ($service_key == 'GFP') {
    916965                            // Legacy API response
    917966                            if (isset($val->soapenvBody->rateRateResponse->rateRatedShipment->rateTotalCharges->rateMonetaryValue)) {
    918                                 $rates[$key]->$rates_key->$service_key->soapenvBody->rateRateResponse->rateRatedShipment->rateTotalCharges->rateMonetaryValue = $settings['service_rate'];
     967                                $net_rate = $val->soapenvBody->rateRateResponse->rateRatedShipment->rateTotalCharges->rateMonetaryValue;
     968                                $rates[$key]->$rates_key->$service_key->soapenvBody->rateRateResponse->rateRatedShipment->rateTotalCharges->rateMonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    919969                            }
    920        
     970
    921971                            // New API response
    922972                            if (isset($val->RateResponse->RatedShipment->TotalCharges->MonetaryValue)) {
    923                                 $rates[$key]->$rates_key->$service_key->RateResponse->RatedShipment->TotalCharges->MonetaryValue = $settings['service_rate'];
     973                                $net_rate = $val->RateResponse->RatedShipment->TotalCharges->MonetaryValue;
     974                                $rates[$key]->$rates_key->$service_key->RateResponse->RatedShipment->TotalCharges->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    924975                            }
    925    
     976
    926977                            $rates[$key]->$rates_key->$service_key->overrideRate = true;
    927978                        } else {
    928979                            if (isset($rate_arr->TotalCharges->MonetaryValue)) {
    929980                                if (isset($rates[$key]->$rates_key->$service_key->TotalCharges->MonetaryValue)) {
    930                                     $rates[$key]->$rates_key->$service_key->TotalCharges->MonetaryValue = $settings['service_rate'];
     981                                    $net_rate = $rates[$key]->$rates_key->$service_key->TotalCharges->MonetaryValue;
     982                                    $rates[$key]->$rates_key->$service_key->TotalCharges->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    931983                                }
    932    
     984
    933985                                if (isset($rates[$key]->$rates_key->$service_key->RatedShipment->TotalCharges->MonetaryValue)) {
    934                                     $rates[$key]->$rates_key->$service_key->RatedShipment->TotalCharges->MonetaryValue = $settings['service_rate'];
     986                                    $net_rate = $rates[$key]->$rates_key->$service_key->RatedShipment->TotalCharges->MonetaryValue;
     987                                    $rates[$key]->$rates_key->$service_key->RatedShipment->TotalCharges->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    935988                                }
    936989                            }
    937        
     990
    938991                            if (isset($rate_arr->NegotiatedRateCharges->TotalCharge->MonetaryValue)) {
    939992                                if (isset($rates[$key]->$rates_key->$service_key->NegotiatedRateCharges->TotalCharge->MonetaryValue)) {
    940                                     $rates[$key]->$rates_key->$service_key->NegotiatedRateCharges->TotalCharge->MonetaryValue = $settings['service_rate'];
     993                                    $net_rate = $rates[$key]->$rates_key->$service_key->NegotiatedRateCharges->TotalCharge->MonetaryValue;
     994                                    $rates[$key]->$rates_key->$service_key->NegotiatedRateCharges->TotalCharge->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    941995                                }
    942    
     996
    943997                                if (isset($rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRateCharges->TotalCharge->MonetaryValue)) {
    944                                     $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRateCharges->TotalCharge->MonetaryValue = $settings['service_rate'];
     998                                    $net_rate = $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRateCharges->TotalCharge->MonetaryValue;
     999                                    $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRateCharges->TotalCharge->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    9451000                                }
    9461001                            }
    947                            
     1002
    9481003                            if (isset($rate_arr->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue)) {
    9491004                                if (isset($rates[$key]->$rates_key->$service_key->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue)) {
    950                                     $rates[$key]->$rates_key->$service_key->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue = $settings['service_rate'];
     1005                                    $net_rate = $rates[$key]->$rates_key->$service_key->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
     1006                                    $rates[$key]->$rates_key->$service_key->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    9511007                                }
    952    
     1008
    9531009                                if (isset($rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue)) {
    954                                     $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue = $settings['service_rate'];
     1010                                    $net_rate = $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
     1011                                    $rates[$key]->$rates_key->$service_key->RatedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    9551012                                }
    9561013                            }
    957    
     1014
    9581015                            $rates[$key]->$rates_key->$service_key->overrideRate = true;
    9591016                        }
    9601017                    }
    961    
     1018
    9621019                    // UPS simple rate services
    963                     if (in_array($service_key, $simple_rate_services) && $service_key == $service_code && $rates_key != '' && isset($val->rate)) {
     1020                    if (in_array($service_key, $simple_rate_services) && ($service_key == $service_code || $msc_service_exists) && $rates_key != '' && isset($val->rate)) {
    9641021                        if ($rates[$key]->$rates_key->$service_key->rate) {
    965                             $rates[$key]->$rates_key->$service_key->rate = $settings['service_rate'];
     1022                            $net_rate = $rates[$key]->$rates_key->$service_key->rate;
     1023                            $rates[$key]->$rates_key->$service_key->rate = $this->shipping_rule_object->ups_small_get_service_rate($net_rate, $settings, $msc_service_exists);
    9661024                            $rates[$key]->$rates_key->$service_key->overrideRate = true;
    9671025                        }
    … …  
    9741032    }
    9751033
    976     function is_country_matched($selected_country, $destination_country) 
     1034    function is_country_matched($selected_country, $destination_country)
    9771035    {
    9781036        $is_matched = false;
    … …  
    10211079            }
    10221080        }
     1081
     1082        // Eniture debug mode
     1083        $data = ['settings' => $settings, 'rates' => json_encode($rates), 'updated_rates' => json_encode($updated_rates)];
     1084        do_action("eniture_debug_mood", "UPS Small Hide Methods By Origin Rule Applied", $data);
    10231085
    10241086        return $updated_rates;
    … …  
    10471109        return $rate_arr;
    10481110    }
     1111
     1112    function apply_minimum_shipping_charge_rule($ups_small_package, $settings, $rates, $rule_name)
     1113    {
     1114        $is_rule_applied = false;
     1115        $updated_rates = $rates;
     1116
     1117        if ($settings['apply_to'] == 'cart') {
     1118            $formatted_values = $this->get_formatted_values($ups_small_package);
     1119            $is_rule_applied = $this->apply_rule_filters($settings, $formatted_values);
     1120
     1121            if ($is_rule_applied) {
     1122                $updated_rates = $this->get_updated_rates($updated_rates, $settings, false, '', true);
     1123            }
     1124        } else {
     1125            foreach ($ups_small_package as $org_zip => $pkg) {
     1126                $is_rule_applied = false;
     1127                $shipments = [];
     1128                $org_zip = isset($pkg['zip']) ? $pkg['zip'] : $org_zip;
     1129                $shipments[$org_zip] = $pkg;
     1130
     1131                $formatted_values = $this->get_formatted_values($shipments);
     1132                $is_rule_applied = $this->apply_rule_filters($settings, $formatted_values);
     1133
     1134                if ($is_rule_applied) {
     1135                    $updated_rates = $this->get_updated_rates($updated_rates, $settings, false, $org_zip, true);
     1136                }
     1137            }
     1138        }
     1139
     1140        // Eniture debug mode
     1141        $data = ['rule_name' => $rule_name, 'settings' => $settings, 'rates' => json_encode($rates), 'updated_rates' => json_encode($updated_rates)];
     1142        do_action("eniture_debug_mood", "UPS Small Minimum Shipping Charge Rule Applied", $data);
     1143
     1144        return $updated_rates;
     1145    }
    10491146}
  • small-package-quotes-ups-edition/trunk/ups-small-shipping-class.php

    r3198871 r3237693  
    261261                    );
    262262                    $this->add_rate($rates);
    263                    
     263
     264                    // Eniture debug mode
     265                    do_action("eniture_debug_mood", "Free Shipping (-100% Handling Fee) Applied (UPS Small)", $rates);
     266
    264267                    return [];
    265268                }
    266269
    267270                $ups_small_package = $get_packg_obj->group_ups_small_shipment($package, $ups_small_res_inst, $freight_zipcode);
     271
     272                // Apply free shipping rule
     273                $free_shipping_rate = (new Eniture_UpsSmallShippingRulesAjaxReq())->apply_free_shipping_rule($ups_small_package);
     274                if (isset($free_shipping_rate['rates']) && !empty($free_shipping_rate['rates']) && is_array($free_shipping_rate['rates'])) {
     275                    $this->add_rate($free_shipping_rate['rates']);
     276                    return [];
     277                }
     278
     279                $ups_small_package = isset($free_shipping_rate['package']) ? $free_shipping_rate['package'] : $ups_small_package;
     280
    268281                // Apply hide methods shipping rules
    269282                $shipping_rules_applied = $get_packg_obj->apply_shipping_rules($ups_small_package);
    … …  
    290303                            $ups_small_package[$org_id]['is_shipment'] = 'ltl';
    291304                            $ups_small_package[$org_id]['origin']['ptype'] = 'ltl';
     305
     306                            // Eniture debug mode
     307                            do_action("eniture_debug_mood", "Suppressing UPS Small Package Rates (Weight Threshold)", $ups_small_package[$org_id]);
    292308                        }
    293309                    }
    … …  
    352368                $en_is_shipment = (count($quotes) > 1) || !empty($virtual_rate) ? 'en_multi_shipment' : 'en_single_shipment';
    353369
     370                // Eniture debug mode
     371                do_action("eniture_debug_mood", "Shipment Type (UPS Small)", $en_is_shipment);
     372
    354373                $this->quote_settings['shipment'] = $en_is_shipment;
    355374                $this->eniture_rates = [];
    … …  
    380399                    }
    381400                }
     401
    382402                if ($this->en_not_returned_the_quotes) {
     403                    // Eniture debug mode
     404                    do_action("eniture_debug_mood", "UPS Small Quotes not returned", $this->en_not_returned_the_quotes ? 'Yes' : 'No');
     405
    383406                    return [];
    384407                }
     408
    385409                if ($en_is_shipment == 'en_single_shipment') {
    386410                    // In-store pickup and local delivery
  • small-package-quotes-ups-edition/trunk/ups-small-test-connection.php

    r3147523 r3237693  
    1919function eniture_ups_test_submit()
    2020{
     21    if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'eniture_ups_small_nonce')) {
     22        echo json_encode([]);
     23        exit;
     24    }
     25
    2126    $iAcountNumber = (isset($_POST['ups_small_acc_number'])) ? sanitize_text_field(wp_unslash( $_POST['ups_small_acc_number'] )) : '';
    2227    $sLicenseKey = (isset($_POST['ups_small_license'])) ? sanitize_text_field(wp_unslash( $_POST['ups_small_license'] )) : '';
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/get-distance-request.php

    r3147523 r3237693  
    4141        );
    4242
     43        // Eniture debug mode
     44        do_action("eniture_debug_mood", "Multi Warehouse Distance Request (UPS Small)", $postData);
    4345
    4446        $Ups_Small_Curl_Request = new Eniture_UPS_Small_Curl_Request();
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/wild-delivery.php

    r3148641 r3237693  
    2020        ));
    2121
    22         wp_enqueue_script('en_woo_wd_script', plugin_dir_url(__FILE__) . '/wild/assets/js/warehouse_section.js', array(), '1.0.5');
     22        wp_enqueue_script('en_woo_wd_script', plugin_dir_url(__FILE__) . '/wild/assets/js/warehouse_section.js', array(), '1.0.6');
    2323        wp_localize_script('en_woo_wd_script', 'script', array(
    2424            'pluginsUrl' => plugins_url(),
    … …  
    2727        wp_register_style('warehouse_section', plugin_dir_url(__FILE__) . '/wild/assets/css/warehouse_section.css', false, '1.0.4');
    2828        wp_enqueue_style('warehouse_section');
     29        wp_localize_script('en_woo_wd_script', 'en_ups_small_wh_script', array(
     30            'pluginsUrl' => plugins_url(),
     31            'nonce' => wp_create_nonce("en_woo_wd_nonce"),
     32        ));
    2933    }
    3034
    … …  
    6973           class="en_wd_add_warehouse_btn <?php echo esc_attr($multi_warehouse_disabled);
    7074           ?>" name="avc">Add</a>
     75
     76           <?php
     77                echo "<br /> <br />";
     78                // Eniture debug mode
     79                do_action("eniture_debug_mood", "UPS Small Warehouse List", $warehous_list);
     80            ?>
    7181
    7282        <div class="wild_warehouse pakage_notify heading_right">
    … …  
    132142                        <td class="en_wd_warehouse_list_data">
    133143                            <a href="javascript(0)"
    134                                onclick="return eniture_wd_edit_warehouse(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
     144                               onclick="return en_ups_small_wd_edit_warehouse(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
    135145                                        src="<?php echo esc_url_raw(plugins_url()); ?>/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"
    136146                                        title="Edit"></a>
    137147                            <a href="javascript(0)"
    138                                onclick="return en_wd_delete_current_warehouse(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
     148                               onclick="return en_ups_small_wd_delete_current_warehouse(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
    139149                                        src="<?php echo esc_url_raw(plugins_url()); ?>/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"
    140150                                        title="Delete"></a>
    … …  
    196206           class="en_wd_add_dropship_btn hide_drop_val <?php echo esc_attr($multi_dropship_disabled); ?>">Add</a>
    197207
     208           <?php
     209                echo "<br /> <br />";
     210                // Eniture debug mode
     211                do_action("eniture_debug_mood", "UPS Small Dropship List", $dropship_list);
     212            ?>
     213
    198214        <div class="wild_warehouse pakage_notify heading_right">
    199215            <?php echo $multi_dropship_package_required; ?>
    … …  
    264280                        <td class="en_wd_dropship_list_data">
    265281                            <a href="javascript(0)"
    266                                onclick="return eniture_wd_edit_dropship(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
     282                               onclick="return en_ups_small_wd_edit_dropship(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
    267283                                        src="<?php echo esc_url_raw(plugins_url()); ?>/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"
    268284                                        title="Edit"></a>
    269285                            <a href="javascript(0)"
    270                                onclick="return en_wd_delete_current_dropship(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
     286                               onclick="return en_ups_small_wd_delete_current_dropship(<?php echo (isset($list->id)) ? esc_attr($list->id) : ''; ?>);"><img
    271287                                        src="<?php echo esc_url_raw(plugins_url()); ?>/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"
    272288                                        title="Delete"></a>
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/wild/assets/js/warehouse_section.js

    r3148641 r3237693  
    322322 * @returns {Boolean}
    323323 */
    324 if (typeof en_wd_save_warehouse != 'function')
    325 {
    326     function en_wd_save_warehouse()
     324if (typeof en_ups_small_wd_save_warehouse != 'function')
     325{
     326    function en_ups_small_wd_save_warehouse()
    327327    {
    328328        var validate = enWdValidateInput("#add_warehouses");
    … …  
    342342
    343343        var postForm = {
    344             'action': 'eniture_wd_save_warehouse',
     344            'action': 'en_ups_small_wd_save_warehouse',
    345345            'origin_id': jQuery('#edit_form_id').val(),
    346346            'origin_city': city,
    … …  
    355355            // preferred origin
    356356            'pref_loc_lfq': jQuery('#add_warehouses #pref_loc_lfq').val(),
    357             'pref_loc_spq': jQuery('#add_warehouses #pref_loc_spq').val()
     357            'pref_loc_spq': jQuery('#add_warehouses #pref_loc_spq').val(),
     358            'wp_nonce': en_ups_small_wh_script.nonce
    358359        };
    359360
    … …  
    389390                } else if (data.update_qry == 1) {
    390391
    391                     jQuery('tr[id=row_' + WarehpuseDataId + ']').html('<td class="en_wd_warehouse_list_data">' + data.origin_city + '</td><td class="en_wd_warehouse_list_data">' + data.origin_state + '</td><td class="en_wd_warehouse_list_data">' + data.origin_zip + '</td><td class="en_wd_warehouse_list_data">' + data.origin_country + '</td><td class="en_wd_warehouse_list_data"><a href="javascript(0)" title="Edit" onclick="return eniture_wd_edit_warehouse(' + WarehpuseDataId + ')"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"></a><a href="javascript(0)" title="Delete" onclick="return en_wd_delete_current_warehouse(' + WarehpuseDataId + ');"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"></a></td>');
     392                    jQuery('tr[id=row_' + WarehpuseDataId + ']').html('<td class="en_wd_warehouse_list_data">' + data.origin_city + '</td><td class="en_wd_warehouse_list_data">' + data.origin_state + '</td><td class="en_wd_warehouse_list_data">' + data.origin_zip + '</td><td class="en_wd_warehouse_list_data">' + data.origin_country + '</td><td class="en_wd_warehouse_list_data"><a href="javascript(0)" title="Edit" onclick="return en_ups_small_wd_edit_warehouse(' + WarehpuseDataId + ')"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"></a><a href="javascript(0)" title="Delete" onclick="return en_ups_small_wd_delete_current_warehouse(' + WarehpuseDataId + ');"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"></a></td>');
    392393                    jQuery('.warehouse_updated').show('slow').delay(5000).hide('slow');
    393394                    jQuery('.warehouse_deleted').css('display', 'none');
    … …  
    414415 * @returns {Boolean}
    415416 */
    416 if (typeof en_wd_delete_current_warehouse != 'function')
    417 {
    418     function en_wd_delete_current_warehouse(e)
     417if (typeof en_ups_small_wd_delete_current_warehouse != 'function')
     418{
     419    function en_ups_small_wd_delete_current_warehouse(e)
    419420    {
    420421        var tab = get_parameter_by_name('tab');
    421422        var postForm = {
    422             'action': 'eniture_wd_delete_warehouse',
     423            'action': 'en_ups_small_wd_delete_warehouse',
    423424            'delete_id': e,
    424425            'tab': tab,
     426            'wp_nonce': en_ups_small_wh_script.nonce
    425427        };
    426428
    … …  
    456458 * @returns {Boolean}
    457459 */
    458 if (typeof eniture_wd_edit_warehouse != 'function')
    459 {
    460     function eniture_wd_edit_warehouse(e)
    461     {
     460if (typeof en_ups_small_wd_edit_warehouse != 'function')
     461{
     462    function en_ups_small_wd_edit_warehouse(e)
     463    {
     464        console.log('en_ups_small_wd_edit_warehouse');
    462465        var postForm = {
    463             'action': 'eniture_wd_edit_warehouse',
     466            'action': 'en_ups_small_wd_edit_warehouse',
    464467            'edit_id': e,
     468            'wp_nonce': en_ups_small_wh_script.nonce
    465469        };
    466470        jQuery.ajax({
    … …  
    512516 * @returns {Boolean}
    513517 */
    514 if (typeof en_wd_save_dropship != 'function')
    515 {
    516     function en_wd_save_dropship()
     518if (typeof en_ups_small_wd_save_dropship != 'function')
     519{
     520    function en_ups_small_wd_save_dropship()
    517521    {
    518522
    … …  
    533537
    534538        var postForm = {
    535             'action': 'eniture_wd_save_dropship',
     539            'action': 'en_ups_small_wd_save_dropship',
    536540            'dropship_id': jQuery('#edit_dropship_form_id').val(),
    537541            'dropship_city': city,
    … …  
    547551            // preferred origin
    548552            'pref_loc_lfq': jQuery('#add_dropships #pref_loc_lfq').val(),
    549             'pref_loc_spq': jQuery('#add_dropships #pref_loc_spq').val()
     553            'pref_loc_spq': jQuery('#add_dropships #pref_loc_spq').val(),
     554            'wp_nonce': en_ups_small_wh_script.nonce
    550555        };
    551556
    … …  
    581586
    582587                } else if (data.update_qry == 1) {
    583                     jQuery('tr[id=row_' + WarehpuseDataId + ']').html('<td class="en_wd_dropship_list_data">' + data.nickname + '</td><td class="en_wd_dropship_list_data">' + data.origin_city + '</td><td class="en_wd_dropship_list_data">' + data.origin_state + '</td><td class="en_wd_dropship_list_data">' + data.origin_zip + '</td><td class="en_wd_dropship_list_data">' + data.origin_country + '</td><td class="en_wd_dropship_list_data"><a href="javascript(0)" title="Edit" onclick="return eniture_wd_edit_dropship(' + WarehpuseDataId + ')"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"></a><a href="javascript(0)" title="Delete" onclick="return en_wd_delete_current_dropship(' + WarehpuseDataId + ');"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"></a></td>');
     588                    jQuery('tr[id=row_' + WarehpuseDataId + ']').html('<td class="en_wd_dropship_list_data">' + data.nickname + '</td><td class="en_wd_dropship_list_data">' + data.origin_city + '</td><td class="en_wd_dropship_list_data">' + data.origin_state + '</td><td class="en_wd_dropship_list_data">' + data.origin_zip + '</td><td class="en_wd_dropship_list_data">' + data.origin_country + '</td><td class="en_wd_dropship_list_data"><a href="javascript(0)" title="Edit" onclick="return en_ups_small_wd_edit_dropship(' + WarehpuseDataId + ')"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/edit.png"></a><a href="javascript(0)" title="Delete" onclick="return en_ups_small_wd_delete_current_dropship(' + WarehpuseDataId + ');"><img src="' + script.pluginsUrl + '/small-package-quotes-ups-edition/warehouse-dropship/wild/assets/images/delete.png"></a></td>');
    584589                    jQuery('.dropship_updated').show('slow').delay(5000).hide('slow');
    585590                    jQuery('.dropship_created').css('display', 'none');
    … …  
    612617 * @returns {Boolean}
    613618 */
    614 if (typeof eniture_wd_edit_dropship != 'function')
    615 {
    616     function eniture_wd_edit_dropship(e)
     619if (typeof en_ups_small_wd_edit_dropship != 'function')
     620{
     621    function en_ups_small_wd_edit_dropship(e)
    617622    {
    618623        var postForm = {
    619             'action': 'eniture_wd_edit_dropship',
     624            'action': 'en_ups_small_wd_edit_dropship',
    620625            'dropship_edit_id': e,
     626            'wp_nonce': en_ups_small_wh_script.nonce
    621627        };
    622628        jQuery.ajax({
    … …  
    670676 * @returns {Boolean}
    671677 */
    672 if (typeof en_wd_delete_current_dropship != 'function')
    673 {
    674     function en_wd_delete_current_dropship(e)
     678if (typeof en_ups_small_wd_delete_current_dropship != 'function')
     679{
     680    function en_ups_small_wd_delete_current_dropship(e)
    675681    {
    676682        var id = e;
    … …  
    701707        var tab = get_parameter_by_name('tab');
    702708        var postForm = {
    703             'action': 'eniture_wd_delete_dropship',
     709            'action': 'en_ups_small_wd_delete_dropship',
    704710            'dropship_delete_id': e,
    705711            'tab': tab,
     712            'wp_nonce': en_ups_small_wh_script.nonce
    706713        };
    707714        jQuery.ajax({
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/wild/dropship/dropship_template.php

    r3148641 r3237693  
    170170</script>
    171171
    172 <div class="en_wd_setting_section">
     172<div class="en_wd_setting_section ups_small_wrapper">
    173173    <a href="#delete_dropship_btn" class="delete_dropship_btn hide_drop_val"></a>
    174174    <div id="delete_dropship_btn" class="en_wd_warehouse_overlay">
    … …  
    376376                    -->
    377377                    <div class="form-btns">
    378                         <input type="submit" name="en_wd_submit_dropship" value="Save" class="save_warehouse_form" onclick="return en_wd_save_dropship();">
     378                        <input type="submit" name="en_wd_submit_dropship" value="Save" class="save_warehouse_form" onclick="return en_ups_small_wd_save_dropship();">
    379379                    </div>
    380380                </form>
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/wild/includes/wild-delivery-save.php

    r3147523 r3237693  
    2525            add_action('wp_ajax_eniture_wd_get_address', array($this, 'eniture_get_address_api_ajax'));
    2626
    27             add_action('wp_ajax_nopriv_eniture_wd_delete_dropship', array($this, 'eniture_delete_dropship_ajax'));
    28             add_action('wp_ajax_eniture_wd_delete_dropship', array($this, 'eniture_delete_dropship_ajax'));
    29 
    30             add_action('wp_ajax_nopriv_eniture_wd_save_warehouse', array($this, 'eniture_save_warehouse_ajax'));
    31             add_action('wp_ajax_eniture_wd_save_warehouse', array($this, 'eniture_save_warehouse_ajax'));
    32 
    33             add_action('wp_ajax_nopriv_eniture_wd_save_dropship', array($this, 'eniture_save_dropship_ajax'));
    34             add_action('wp_ajax_eniture_wd_save_dropship', array($this, 'eniture_save_dropship_ajax'));
    35 
    36 
    37             add_action('wp_ajax_nopriv_eniture_wd_edit_dropship', array($this, 'eniture_edit_dropship_ajax'));
    38             add_action('wp_ajax_eniture_wd_edit_dropship', array($this, 'eniture_edit_dropship_ajax'));
    39 
    40             add_action('wp_ajax_nopriv_eniture_wd_delete_warehouse', array($this, 'eniture_delete_warehouse_ajax'));
    41             add_action('wp_ajax_eniture_wd_delete_warehouse', array($this, 'eniture_delete_warehouse_ajax'));
    42 
    43             add_action('wp_ajax_nopriv_eniture_wd_edit_warehouse', array($this, 'eniture_edit_warehouse_ajax'));
    44             add_action('wp_ajax_eniture_wd_edit_warehouse', array($this, 'eniture_edit_warehouse_ajax'));
     27            // Warehouse actions
     28            add_action('wp_ajax_nopriv_en_ups_small_wd_save_warehouse', array($this, 'eniture_save_warehouse_ajax'));
     29            add_action('wp_ajax_en_ups_small_wd_save_warehouse', array($this, 'eniture_save_warehouse_ajax'));
     30
     31            add_action('wp_ajax_nopriv_en_ups_small_wd_edit_warehouse', array($this, 'eniture_edit_warehouse_ajax'));
     32            add_action('wp_ajax_en_ups_small_wd_edit_warehouse', array($this, 'eniture_edit_warehouse_ajax'));
     33
     34            add_action('wp_ajax_nopriv_en_ups_small_wd_delete_warehouse', array($this, 'eniture_delete_warehouse_ajax'));
     35            add_action('wp_ajax_en_ups_small_wd_delete_warehouse', array($this, 'eniture_delete_warehouse_ajax'));
     36
     37            // Dropship actions
     38            add_action('wp_ajax_nopriv_en_ups_small_wd_save_dropship', array($this, 'eniture_save_dropship_ajax'));
     39            add_action('wp_ajax_en_ups_small_wd_save_dropship', array($this, 'eniture_save_dropship_ajax'));
     40
     41            add_action('wp_ajax_nopriv_en_ups_small_wd_edit_dropship', array($this, 'eniture_edit_dropship_ajax'));
     42            add_action('wp_ajax_en_ups_small_wd_edit_dropship', array($this, 'eniture_edit_dropship_ajax'));
     43
     44            add_action('wp_ajax_nopriv_en_ups_small_wd_delete_dropship', array($this, 'eniture_delete_dropship_ajax'));
     45            add_action('wp_ajax_en_ups_small_wd_delete_dropship', array($this, 'eniture_delete_dropship_ajax'));
    4546        }
    4647
    … …  
    168169        function eniture_save_warehouse_ajax()
    169170        {
     171            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     172                echo wp_json_encode([]);
     173                return;
     174            }
     175
    170176            global $wpdb;
    171177            $html = "";
    … …  
    220226               
    221227                if (isset($validateData["city"])) {
    222                     $get_warehouse_id = (isset($_POST['origin_id']) && intval($_POST['origin_id'])) ? sanitize_text_field(wp_unslash($_POST['origin_id'])) : "";
     228                    $get_warehouse_id = (isset($_POST['origin_id']) && intval($_POST['origin_id'])) ? intval($_POST['origin_id']) : "";
    223229                    if ($get_warehouse_id && (empty($get_warehouse) || (!empty($get_warehouse) && reset($get_warehouse)->id == $get_warehouse_id))) {
    224230                        $update_qry = $wpdb->update(
    … …  
    257263        function eniture_edit_warehouse_ajax()
    258264        {
     265            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     266                echo wp_json_encode([]);
     267                return;
     268            }
     269
    259270            // Terminal phone number
    260271            global $wpdb;
    261             $get_warehouse_id = (isset($_POST['edit_id']) && intval($_POST['edit_id'])) ? sanitize_text_field(wp_unslash($_POST['edit_id'])) : "";
     272            $get_warehouse_id = (isset($_POST['edit_id']) && intval($_POST['edit_id'])) ? intval($_POST['edit_id']) : "";
    262273            $warehous_list = $wpdb->get_results(
    263274                $wpdb->prepare(
    … …  
    278289        function eniture_delete_warehouse_ajax()
    279290        {
    280             global $wpdb;
    281             $get_warehouse_id = (isset($_POST['delete_id']) && intval($_POST['delete_id'])) ? sanitize_text_field(wp_unslash($_POST['delete_id'])) : "";
     291            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     292                echo wp_json_encode([]);
     293                return;
     294            }
     295
     296            global $wpdb;
     297            $get_warehouse_id = (isset($_POST['delete_id']) && intval($_POST['delete_id'])) ? intval($_POST['delete_id']) : "";
    282298            $qry = $wpdb->delete($wpdb->prefix . 'warehouse', array('id' => $get_warehouse_id, 'location' => 'warehouse'));
    283299
    … …  
    294310        function eniture_save_dropship_ajax()
    295311        {
     312            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     313                echo wp_json_encode([]);
     314                return;
     315            }
     316
    296317            global $wpdb;
    297318            $html = "";
    … …  
    348369
    349370                if (isset($validateData["city"])) {
    350                     $get_dropship_id = (isset($_POST['dropship_id']) && intval($_POST['dropship_id'])) ? sanitize_text_field(wp_unslash($_POST['dropship_id'])) : "";
     371                    $get_dropship_id = (isset($_POST['dropship_id']) && intval($_POST['dropship_id'])) ? intval($_POST['dropship_id']) : "";
    351372
    352373                    if ($get_dropship_id != '' && (empty($get_dropship) || (!empty($get_dropship) && reset($get_dropship)->id == $get_dropship_id))) {
    … …  
    386407        function eniture_edit_dropship_ajax()
    387408        {
     409            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     410                echo wp_json_encode([]);
     411                return;
     412            }
     413
    388414            // Terminal phone number
    389415            global $wpdb;
    390             $get_dropship_id = (isset($_POST['dropship_edit_id']) && intval($_POST['dropship_edit_id'])) ? sanitize_text_field(wp_unslash($_POST['dropship_edit_id'])) : "";
     416            $get_dropship_id = (isset($_POST['dropship_edit_id']) && intval($_POST['dropship_edit_id'])) ? intval($_POST['dropship_edit_id']) : "";
    391417            $warehous_list = $wpdb->get_results(
    392418                $wpdb->prepare(
    … …  
    406432        function eniture_delete_dropship_ajax()
    407433        {
    408 
    409             global $wpdb;
    410 
    411             $get_dropship_id = (isset($_POST['dropship_delete_id']) && intval($_POST['dropship_delete_id'])) ? sanitize_text_field(wp_unslash($_POST['dropship_delete_id'])) : "";
     434            if (!current_user_can('manage_options') || !wp_verify_nonce($_POST['wp_nonce'], 'en_woo_wd_nonce')) {
     435                echo wp_json_encode([]);
     436                return;
     437            }
     438
     439            global $wpdb;
     440
     441            $get_dropship_id = (isset($_POST['dropship_delete_id']) && intval($_POST['dropship_delete_id'])) ? intval($_POST['dropship_delete_id']) : "";
    412442            $dropship_id = isset($_POST['dropship_delete_id']) ? sanitize_text_field(wp_unslash($_POST['dropship_delete_id'])) : "";
    413443            $get_dropship_array = array($dropship_id);
  • small-package-quotes-ups-edition/trunk/warehouse-dropship/wild/warehouse/warehouse_template.php

    r3148641 r3237693  
    167167    });
    168168</script>
    169 <div class="en_wd_setting_section">
     169<div class="en_wd_setting_section ups_small_wrapper">
    170170    <h1>Warehouses</h1><br>
    171171
    … …  
    357357                    -->
    358358                    <div class="form-btns">
    359                         <input type="submit" name="en_wd_submit_warehouse" value="Save" class="save_warehouse_form" onclick="return en_wd_save_warehouse();">
     359                        <input type="submit" name="en_wd_submit_warehouse" value="Save" class="save_warehouse_form" onclick="return en_ups_small_wd_save_warehouse();">
    360360                    </div>
    361361                </form>
Note: See TracChangeset for help on using the changeset viewer.