Plugin Directory

Changeset 2915384


Ignore:
Timestamp:
05/21/2023 12:04:27 PM (3 years ago)
Author:
wppunk
Message:

Release 1.5.5

Location:
shipping-nova-poshta-for-woocommerce/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • shipping-nova-poshta-for-woocommerce/trunk/readme.txt

    r2885659 r2915384  
    44Requires at least: 5.8
    55Tested up to: 6.2
    6 Stable tag: 1.5.4.5
     6Stable tag: 1.5.5
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    8585== Changelog ==
    8686
     87= 1.5.5 =
     88* Improved search by cities
     89* Added flat cost for the shipping method
     90* Added compatibility with WooCommerce 7.7
     91* Added compabitility with WordPress 6.2
     92
    8793= 1.5.4.6 =
    88 * Added compatibility with WooCommerce Checkout Manager plugin.
     94* Added compatibility with WooCommerce Checkout Manager plugin
    8995
    9096= 1.5.4.5 =
  • shipping-nova-poshta-for-woocommerce/trunk/shipping-nova-poshta-for-woocommerce.php

    r2885659 r2915384  
    66 * Plugin URI:  http://wp-unit.com/
    77 * Description: Select a branch on the checkout page, the creation of electronic invoices, calculating shipping costs, COD payment, and much more ...
    8  * Version: 1.5.4.6
     8 * Version: 1.5.5
    99 * Author: WP Unit
    1010 * Author URI: http://wp-unit.com/
     
    1818 * Requires PHP: 7.0
    1919 * WC requires at least: 4.6
    20  * WC tested up to: 7.5
     20 * WC tested up to: 7.7
    2121 */
    2222
  • shipping-nova-poshta-for-woocommerce/trunk/src/Admin/SettingsPage.php

    r2874649 r2915384  
    8484        add_action( 'shipping_nova_poshta_for_woocommerce_settings_page_sender_tab', [ $this, 'sender_tab' ] );
    8585        add_action( 'shipping_nova_poshta_for_woocommerce_print_notice', [ $this, 'notices' ] );
     86        add_action( 'shipping_nova_poshta_for_woocommerce_upgraded', [ $this, 'load_cities' ] );
    8687    }
    8788
     
    190191
    191192            if ( ! $this->api->validate( $value['api_key'] ) ) {
    192                 unset( $value['api_key'] );
    193                 unset( $old_value['api_key'] );
     193                unset( $value['api_key'], $old_value['api_key'] );
    194194            }
    195195        }
    196196
    197197        return array_replace( $old_value, $value );
     198    }
     199
     200    /**
     201     * Load cities on plugin upgraded.
     202     */
     203    public function load_cities() {
     204
     205        $object_cache    = $this->factory_cache->object();
     206        $transient_cache = $this->factory_cache->transient();
     207
     208        $object_cache->flush();
     209        $transient_cache->flush();
     210
     211        $this->api->cities();
    198212    }
    199213
  • shipping-nova-poshta-for-woocommerce/trunk/src/Api/Api.php

    r2884804 r2915384  
    104104
    105105        if ( empty( $limit ) ) {
    106             $limit = (int) apply_filters( 'shipping_nova_poshta_for_woocommerce_api_cities_limit', 10 );
     106            $limit = (int) apply_filters( 'shipping_nova_poshta_for_woocommerce_api_cities_limit', 20 );
    107107        }
    108108
     
    212212
    213213        $city_id = $this->settings->city_id();
    214         $key     = 'shipping_cost-from-' . $city_id . '-to-' . $recipient_city_id . '-' . $weight . '-' . $volume;
     214        $key     = 'shipping_cost-from-' . $city_id . '-to-' . $recipient_city_id . '-' . $weight . '-' . implode( '-', $volume );
    215215        $cache   = $this->factory_cache->object();
    216216        $costs   = $cache->get( $key );
  • shipping-nova-poshta-for-woocommerce/trunk/src/Api/Connection.php

    r2679493 r2915384  
    2121use NovaPoshta\Api\V2\Entities\Sender;
    2222use NovaPoshta\Api\V2\Entities\Recipient;
    23 use NovaPoshta\Api\V2\CalculateShippingCost;
    2423
    2524/**
     
    161160    private function get_current_date(): string {
    162161
    163         $date = new DateTime( '', new DateTimeZone( 'Europe/Kiev' ) );
    164 
    165         return $date->format( 'd.m.Y' );
     162        return ( new DateTime( '', new DateTimeZone( 'Europe/Kiev' ) ) )->format( 'd.m.Y' );
    166163    }
    167164
     
    236233                    'FirstName'            => $this->validator->validate_name( $first_name ),
    237234                    'LastName'             => $this->validator->validate_name( $last_name ),
    238                     'MiddleName'           => 'Отчество', // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
    239235                    'Phone'                => $this->validator->validate_phone( $phone ),
    240236                    'RecipientsPhone'      => $this->validator->validate_phone( $phone ),
  • shipping-nova-poshta-for-woocommerce/trunk/src/DB.php

    r2470822 r2915384  
    120120        $field_name = 'description_' . $this->language->get_current_language();
    121121        $sql        = 'SELECT * FROM ' . $this->cities_table;
     122        $search     = str_replace( [ '`', 'ʼ', '"' ], '\'', $search );
     123
    122124        if ( $search ) {
    123125            //phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
     
    131133            //phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
    132134        }
    133         $sql .= ' ORDER BY LENGTH(`' . $field_name . '`), `' . $field_name . '`';
     135        $sql .= $wpdb->remove_placeholder_escape(
     136            $wpdb->prepare(
     137                ' ORDER BY CASE
     138                    WHEN description_ua LIKE %s THEN 1
     139                    WHEN description_ru LIKE %s THEN 1
     140                    WHEN description_ua LIKE %s THEN 2
     141                    WHEN description_ru LIKE %s THEN 2
     142                    WHEN description_ua LIKE %s THEN 4
     143                    WHEN description_ru LIKE %s THEN 4
     144                    ELSE 3
     145                END',
     146                $wpdb->esc_like( $search ),
     147                $wpdb->esc_like( $search ),
     148                $wpdb->esc_like( $search ) . '%',
     149                $wpdb->esc_like( $search ) . '%',
     150                '%' . $wpdb->esc_like( $search ),
     151                '%' . $wpdb->esc_like( $search )
     152            )
     153        );
    134154        if ( $limit ) {
    135155            $sql .= $wpdb->prepare( ' LIMIT %d', $limit );
  • shipping-nova-poshta-for-woocommerce/trunk/src/License/License.php

    r2874649 r2915384  
    169169            );
    170170
     171            do_action( 'shipping_nova_poshta_for_woocommerce_upgraded' );
     172
    171173            return;
    172174        }
  • shipping-nova-poshta-for-woocommerce/trunk/src/WooCommerce/Shipping/Methods/NovaPoshta/NovaPoshta.php

    r2471834 r2915384  
    1313namespace NovaPoshta\WooCommerce\Shipping\Methods\NovaPoshta;
    1414
     15use WC_Eval_Math;
    1516use WC_Shipping_Method;
    1617
     
    114115                'default' => esc_html__( 'Nova Poshta delivery', 'shipping-nova-poshta-for-woocommerce' ),
    115116            ],
     117            'cost'                 => [
     118                'title'             => esc_html__( 'Cost', 'shipping-nova-poshta-for-woocommerce' ),
     119                'type'              => 'text',
     120                'placeholder'       => '',
     121                'description'       => __( 'Enter a cost (excl. tax) or sum, e.g. <code>10.00 * [qty]</code>.', 'woocommerce' ) . '<br/><br/>' . __( 'Use <code>[qty]</code> for the number of items, <br/><code>[cost]</code> for the total cost of items, and <code>[fee percent="10" min_fee="20" max_fee=""]</code> for percentage based fees.', 'woocommerce' ),
     122                'default'           => '0',
     123                'desc_tip'          => true,
     124                'sanitize_callback' => [ $this, 'sanitize_cost' ],
     125            ],
    116126            'enable_free_shipping' => [
    117127                'title'    => esc_html__( 'Enable free shipping', 'shipping-nova-poshta-for-woocommerce' ),
     
    144154    public function calculate_shipping( $package = [] ) {
    145155
    146         // Register the rate.
    147         $this->add_rate(
     156        $args = [
     157            'id'       => $this->id,
     158            'label'    => $this->title,
     159            'calc_tax' => 'per_item',
     160            'cost'     => 0,
     161        ];
     162
     163        $cost = $this->get_option( 'cost' );
     164
     165        if ( '' !== $cost ) {
     166            $args['cost'] = $this->evaluate_cost(
     167                $cost,
     168                [
     169                    'qty'  => $this->get_package_item_qty( $package ),
     170                    'cost' => $package['contents_cost'],
     171                ]
     172            );
     173        }
     174
     175        $this->add_rate( $args );
     176    }
     177
     178    /**
     179     * Evaluate a cost from a sum/string.
     180     *
     181     * @param  string $sum Sum of shipping.
     182     * @param  array  $args Args, must contain `cost` and `qty` keys. Having `array()` as default is for back compat reasons.
     183     * @return string
     184     */
     185    private function evaluate_cost( $sum, $args = [] ) {
     186
     187        // Add warning for subclasses.
     188        if ( ! is_array( $args ) || ! array_key_exists( 'qty', $args ) || ! array_key_exists( 'cost', $args ) ) {
     189            wc_doing_it_wrong( __FUNCTION__, '$args must contain `cost` and `qty` keys.', '4.0.1' );
     190        }
     191
     192        include_once WC()->plugin_path() . '/includes/libraries/class-wc-eval-math.php';
     193
     194        // Allow 3rd parties to process shipping cost arguments.
     195        $args           = (array) apply_filters( 'woocommerce_evaluate_shipping_cost_args', $args, $sum, $this );
     196        $locale         = localeconv();
     197        $decimals       = [
     198            wc_get_price_decimal_separator(),
     199            $locale['decimal_point'],
     200            $locale['mon_decimal_point'],
     201            ',',
     202        ];
     203        $this->fee_cost = $args['cost'];
     204
     205        // Expand shortcodes.
     206        add_shortcode( 'fee', [ $this, 'fee' ] );
     207
     208        $sum = do_shortcode(
     209            str_replace(
     210                [
     211                    '[qty]',
     212                    '[cost]',
     213                ],
     214                [
     215                    $args['qty'],
     216                    $args['cost'],
     217                ],
     218                $sum
     219            )
     220        );
     221
     222        remove_shortcode( 'fee', [ $this, 'fee' ] );
     223
     224        // Remove whitespace from string.
     225        $sum = preg_replace( '/\s+/', '', $sum );
     226
     227        // Remove locale from string.
     228        $sum = str_replace( $decimals, '.', $sum );
     229
     230        // Trim invalid start/end characters.
     231        $sum = rtrim( ltrim( $sum, "\t\n\r\0\x0B+*/" ), "\t\n\r\0\x0B+-*/" );
     232
     233        // Do the math.
     234        return $sum ? WC_Eval_Math::evaluate( $sum ) : 0;
     235    }
     236
     237    /**
     238     * Get items in package.
     239     *
     240     * @param array $package Package of items from cart.
     241     *
     242     * @return int
     243     */
     244    private function get_package_item_qty( array $package ): int {
     245
     246        $total_quantity = 0;
     247        foreach ( $package['contents'] as $item_id => $values ) {
     248            if ( $values['quantity'] > 0 && $values['data']->needs_shipping() ) {
     249                $total_quantity += $values['quantity'];
     250            }
     251        }
     252
     253        return $total_quantity;
     254    }
     255
     256    /**
     257     * Work out fee (shortcode).
     258     *
     259     * @param array $atts Attributes.
     260     *
     261     * @return string
     262     */
     263    public function fee( $atts ) {
     264
     265        $atts = shortcode_atts(
    148266            [
    149                 'id'       => $this->id,
    150                 'label'    => $this->title,
    151                 'calc_tax' => 'per_item',
    152                 'cost'     => 0,
    153             ]
     267                'percent' => '',
     268                'min_fee' => '',
     269                'max_fee' => '',
     270            ],
     271            $atts,
     272            'fee'
    154273        );
     274
     275        $calculated_fee = 0;
     276
     277        if ( $atts['percent'] ) {
     278            $calculated_fee = $this->fee_cost * ( floatval( $atts['percent'] ) / 100 );
     279        }
     280
     281        if ( $atts['min_fee'] && $calculated_fee < $atts['min_fee'] ) {
     282            $calculated_fee = $atts['min_fee'];
     283        }
     284
     285        if ( $atts['max_fee'] && $calculated_fee > $atts['max_fee'] ) {
     286            $calculated_fee = $atts['max_fee'];
     287        }
     288
     289        return $calculated_fee;
    155290    }
    156291
Note: See TracChangeset for help on using the changeset viewer.