Changeset 2915384
- Timestamp:
- 05/21/2023 12:04:27 PM (3 years ago)
- Location:
- shipping-nova-poshta-for-woocommerce/trunk
- Files:
-
- 8 edited
-
readme.txt (modified) (2 diffs)
-
shipping-nova-poshta-for-woocommerce.php (modified) (2 diffs)
-
src/Admin/SettingsPage.php (modified) (2 diffs)
-
src/Api/Api.php (modified) (2 diffs)
-
src/Api/Connection.php (modified) (3 diffs)
-
src/DB.php (modified) (2 diffs)
-
src/License/License.php (modified) (1 diff)
-
src/WooCommerce/Shipping/Methods/NovaPoshta/NovaPoshta.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shipping-nova-poshta-for-woocommerce/trunk/readme.txt
r2885659 r2915384 4 4 Requires at least: 5.8 5 5 Tested up to: 6.2 6 Stable tag: 1.5. 4.56 Stable tag: 1.5.5 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 85 85 == Changelog == 86 86 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 87 93 = 1.5.4.6 = 88 * Added compatibility with WooCommerce Checkout Manager plugin .94 * Added compatibility with WooCommerce Checkout Manager plugin 89 95 90 96 = 1.5.4.5 = -
shipping-nova-poshta-for-woocommerce/trunk/shipping-nova-poshta-for-woocommerce.php
r2885659 r2915384 6 6 * Plugin URI: http://wp-unit.com/ 7 7 * 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.68 * Version: 1.5.5 9 9 * Author: WP Unit 10 10 * Author URI: http://wp-unit.com/ … … 18 18 * Requires PHP: 7.0 19 19 * WC requires at least: 4.6 20 * WC tested up to: 7. 520 * WC tested up to: 7.7 21 21 */ 22 22 -
shipping-nova-poshta-for-woocommerce/trunk/src/Admin/SettingsPage.php
r2874649 r2915384 84 84 add_action( 'shipping_nova_poshta_for_woocommerce_settings_page_sender_tab', [ $this, 'sender_tab' ] ); 85 85 add_action( 'shipping_nova_poshta_for_woocommerce_print_notice', [ $this, 'notices' ] ); 86 add_action( 'shipping_nova_poshta_for_woocommerce_upgraded', [ $this, 'load_cities' ] ); 86 87 } 87 88 … … 190 191 191 192 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'] ); 194 194 } 195 195 } 196 196 197 197 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(); 198 212 } 199 213 -
shipping-nova-poshta-for-woocommerce/trunk/src/Api/Api.php
r2884804 r2915384 104 104 105 105 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 ); 107 107 } 108 108 … … 212 212 213 213 $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 ); 215 215 $cache = $this->factory_cache->object(); 216 216 $costs = $cache->get( $key ); -
shipping-nova-poshta-for-woocommerce/trunk/src/Api/Connection.php
r2679493 r2915384 21 21 use NovaPoshta\Api\V2\Entities\Sender; 22 22 use NovaPoshta\Api\V2\Entities\Recipient; 23 use NovaPoshta\Api\V2\CalculateShippingCost;24 23 25 24 /** … … 161 160 private function get_current_date(): string { 162 161 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' ); 166 163 } 167 164 … … 236 233 'FirstName' => $this->validator->validate_name( $first_name ), 237 234 'LastName' => $this->validator->validate_name( $last_name ), 238 'MiddleName' => 'Отчество', // phpcs:ignore Squiz.PHP.CommentedOutCode.Found239 235 'Phone' => $this->validator->validate_phone( $phone ), 240 236 'RecipientsPhone' => $this->validator->validate_phone( $phone ), -
shipping-nova-poshta-for-woocommerce/trunk/src/DB.php
r2470822 r2915384 120 120 $field_name = 'description_' . $this->language->get_current_language(); 121 121 $sql = 'SELECT * FROM ' . $this->cities_table; 122 $search = str_replace( [ '`', 'ʼ', '"' ], '\'', $search ); 123 122 124 if ( $search ) { 123 125 //phpcs:disable WordPress.DB.PreparedSQL.NotPrepared … … 131 133 //phpcs:enable WordPress.DB.PreparedSQL.NotPrepared 132 134 } 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 ); 134 154 if ( $limit ) { 135 155 $sql .= $wpdb->prepare( ' LIMIT %d', $limit ); -
shipping-nova-poshta-for-woocommerce/trunk/src/License/License.php
r2874649 r2915384 169 169 ); 170 170 171 do_action( 'shipping_nova_poshta_for_woocommerce_upgraded' ); 172 171 173 return; 172 174 } -
shipping-nova-poshta-for-woocommerce/trunk/src/WooCommerce/Shipping/Methods/NovaPoshta/NovaPoshta.php
r2471834 r2915384 13 13 namespace NovaPoshta\WooCommerce\Shipping\Methods\NovaPoshta; 14 14 15 use WC_Eval_Math; 15 16 use WC_Shipping_Method; 16 17 … … 114 115 'default' => esc_html__( 'Nova Poshta delivery', 'shipping-nova-poshta-for-woocommerce' ), 115 116 ], 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 ], 116 126 'enable_free_shipping' => [ 117 127 'title' => esc_html__( 'Enable free shipping', 'shipping-nova-poshta-for-woocommerce' ), … … 144 154 public function calculate_shipping( $package = [] ) { 145 155 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( 148 266 [ 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' 154 273 ); 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; 155 290 } 156 291
Note: See TracChangeset
for help on using the changeset viewer.