Changeset 3030134
- Timestamp:
- 02/01/2024 02:04:46 PM (2 years ago)
- Location:
- woo-parcel-pro
- Files:
-
- 16 edited
- 1 copied
-
tags/1.7.0 (copied) (copied from woo-parcel-pro/trunk)
-
tags/1.7.0/admin/class-parcelpro-shipping.php (modified) (11 diffs)
-
tags/1.7.0/admin/data/parcelpro-shipping-settings-fields.php (modified) (1 diff)
-
tags/1.7.0/admin/data/parcelpro-shipping-settings-services.php (modified) (1 diff)
-
tags/1.7.0/admin/partials/parcelpro-shipping-settings-tables.php (modified) (1 diff)
-
tags/1.7.0/changelog.md (modified) (1 diff)
-
tags/1.7.0/composer.json (modified) (1 diff)
-
tags/1.7.0/includes/class-parcelpro-api.php (modified) (2 diffs)
-
tags/1.7.0/woocommerce-parcelpro.php (modified) (2 diffs)
-
trunk/admin/class-parcelpro-shipping.php (modified) (11 diffs)
-
trunk/admin/data/parcelpro-shipping-settings-fields.php (modified) (1 diff)
-
trunk/admin/data/parcelpro-shipping-settings-services.php (modified) (1 diff)
-
trunk/admin/partials/parcelpro-shipping-settings-tables.php (modified) (1 diff)
-
trunk/changelog.md (modified) (1 diff)
-
trunk/composer.json (modified) (1 diff)
-
trunk/includes/class-parcelpro-api.php (modified) (2 diffs)
-
trunk/woocommerce-parcelpro.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-parcel-pro/tags/1.7.0/admin/class-parcelpro-shipping.php
r3011954 r3030134 27 27 private $custom_services; 28 28 29 /** @var ParcelPro_API $api */ 29 30 private $api; 30 31 public $id; … … 107 108 108 109 include(plugin_dir_path(__FILE__) . 'partials/parcelpro-shipping-settings-tables.php'); 109 110 110 return ob_get_clean(); 111 111 } … … 122 122 { 123 123 $services = array(); 124 $posted_services = array_key_exists('parcelpro_shipping_settings', $_POST) ? $_POST[ 'parcelpro_shipping_settings' ] :null;124 $posted_services = $_POST['parcelpro_shipping_settings'] ?? null; 125 125 $posted_services_order = array_key_exists('service_order', $_POST) ? $_POST[ 'service_order' ] : array(); 126 126 $order_fix = count($posted_services_order) + 1; … … 131 131 $order = (in_array($id, $posted_services_order)) ? array_search($id, $posted_services_order) + 1 : $order_fix++; 132 132 133 $rule[ 'min-weight' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'min-weight' ]);134 $rule[ 'type-id' ] = isset($rule[ 'type-id' ]) ? WC_Settings_API::validate_decimal_field(null, $rule[ 'type-id' ]) : null;135 $rule[ 'max-weight' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'max-weight' ]);136 $rule[ 'min-total' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'min-total' ]);137 $rule[ 'max-total' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'max-total' ]);138 $rule[ 'price' ] = WC_Settings_API::validate_price_field(null, $rule[ 'price' ]);139 $rule[ 'servicepunt' ] = isset($rule[ 'servicepunt' ]) ? $rule['servicepunt'] :null;133 $rule[ 'min-weight' ] = $this->validate_decimal_field(null, $rule[ 'min-weight' ]); 134 $rule[ 'type-id' ] = isset($rule[ 'type-id' ]) ? $this->validate_decimal_field(null, $rule[ 'type-id' ]) : null; 135 $rule[ 'max-weight' ] = $this->validate_decimal_field(null, $rule[ 'max-weight' ]); 136 $rule[ 'min-total' ] = $this->validate_decimal_field(null, $rule[ 'min-total' ]); 137 $rule[ 'max-total' ] = $this->validate_decimal_field(null, $rule[ 'max-total' ]); 138 $rule[ 'price' ] = $this->validate_price_field(null, $rule[ 'price' ]); 139 $rule[ 'servicepunt' ] = $rule['servicepunt'] ?? null; 140 140 141 141 $services[ $id ]['id'] = $id; … … 151 151 152 152 $services[ $id ][ $nr ] = array( 153 'country' => ( isset($rule['country']) ) ? $rule['country'] :'NL',154 'method-title' => ( isset($rule['method-title']) ) ? $rule['method-title'] :null,155 'type-id' => ( isset($rule['type-id']) ) ? $rule['type-id'] :0,156 'min-weight' => ( isset($rule['min-weight']) ) ? $rule['min-weight'] :null,157 'max-weight' => ( isset($rule['max-weight']) ) ? $rule['max-weight'] :null,158 'min-total' => ( isset($rule['min-total']) ) ? $rule['min-total'] :null,159 'max-total' => ( isset($rule['max-total']) ) ? $rule['max-total'] :null,160 'price' => ( isset($rule['price']) ) ? $rule['price'] :null,161 'servicepunt' => ( isset($rule['servicepunt']) && $rule[ 'servicepunt' ] !== null) ? 'on' : null,162 'order' => ( isset($order) ) ? $order :null153 'country' => $rule['country'] ?? 'NL', 154 'method-title' => $rule['method-title'] ?? null, 155 'type-id' => $rule['type-id'] ?? 0, 156 'min-weight' => $rule['min-weight'] ?? null, 157 'max-weight' => $rule['max-weight'] ?? null, 158 'min-total' => $rule['min-total'] ?? null, 159 'max-total' => $rule['max-total'] ?? null, 160 'price' => $rule['price'] ?? null, 161 'servicepunt' => ( isset($rule['servicepunt']) ) ? 'on' : null, 162 'order' => $order ?? null 163 163 ); 164 164 } … … 177 177 * @param $price 178 178 */ 179 private function prepare_service($service, $service_title, $price, $order, $type_id, $servicepunt) 179 private function prepare_service($service, $service_title, $price, $order, $type_id, $servicepunt): void 180 180 { 181 181 $this->found_services[ $service ][ 'id' ] = 'parcelpro_' . $service; … … 193 193 * @param $package 194 194 */ 195 public function calculate_shipping($package = array()) 195 public function calculate_shipping($package = array()): void 196 196 { 197 197 $this->found_services = array(); … … 217 217 218 218 foreach ($this->services as $carrier_name => $carrier) { 219 $lowercaseCarrier = strtolower($carrier_name); 220 $shipping_time = new DateTimeImmutable(); 221 $rawCutoffTime = $this->get_option($lowercaseCarrier . '_last_shipping_time'); 222 $isBeforeCutoffTime = $this->isBeforeLastShippingTime($rawCutoffTime); 223 224 if (!$isBeforeCutoffTime) { 225 $shipping_time = $shipping_time->add(new DateInterval('P1D')); 226 } 227 // Fetch expected delivery day 228 $is_enabled = $this->get_option( 229 $lowercaseCarrier . '_show_delivery_date' 230 ); 231 $formattedDeliveryDate = ''; 232 if ($is_enabled === 'yes') { 233 $delivery_expected = $this->api->getDeliveryDate( 234 $carrier_name, 235 $shipping_time, 236 $package['destination']['postcode'] 237 ); 238 239 if ($delivery_expected) { 240 $formattedDeliveryDate = ' (' . $this->formatDeliveryDate($delivery_expected) . ')'; 241 } 242 } 243 219 244 foreach ($carrier as $key => $value) { 220 245 if (array_key_exists($key, $this->custom_services) && is_array($this->custom_services[ $key ])) { … … 232 257 } 233 258 234 $this->prepare_service($key . $maatwerk_type, $rule[ 'method-title' ], $rule[ 'price' ], $this->custom_services[ $key ][ 'order' ], key_exists('type-id', $rule) ? $rule[ 'type-id' ] : null, isset($rule[ 'servicepunt' ]) ? $rule[ 'servicepunt' ] : null); 259 $this->prepare_service( 260 $key . $maatwerk_type, 261 $rule[ 'method-title' ] . $formattedDeliveryDate, 262 $rule[ 'price' ], 263 $this->custom_services[ $key ][ 'order' ], 264 array_key_exists('type-id', $rule) ? $rule[ 'type-id' ] : null, 265 isset($rule[ 'servicepunt' ]) ? $rule[ 'servicepunt' ] : null 266 ); 235 267 } 236 268 } … … 248 280 } 249 281 282 private function isBeforeLastShippingTime($rawLastTime): bool 283 { 284 if (!$rawLastTime) { 285 return true; 286 } 287 288 try { 289 $parsed = new DateTime($rawLastTime); 290 } catch (\Exception $e) { 291 $logger = wc_get_logger(); 292 if ($logger) { 293 $logger->error(sprintf( 294 'Failed to parse last shipping time (%s): %s', 295 $rawLastTime, 296 $e->getMessage() 297 )); 298 } 299 return true; 300 } 301 302 $now = new DateTime(); 303 return $now < $parsed; 304 } 250 305 251 306 /** 252 307 * Sorts the found services on the given preferences. 253 308 * 254 * @since 1.2.1255 309 * @param $records 256 310 * @param $field 257 311 * @param bool $reverse 312 * 258 313 * @return array 314 *@since 1.2.1 259 315 */ 260 316 public function service_sort($records, $field, $reverse = false) … … 276 332 return $records; 277 333 } 334 335 private function formatDeliveryDate(\DateTimeInterface $date): string 336 { 337 $locale = get_locale(); 338 return \IntlDateFormatter::formatObject($date, 'd MMMM', $locale); 339 } 278 340 } -
woo-parcel-pro/tags/1.7.0/admin/data/parcelpro-shipping-settings-fields.php
r3011954 r3030134 126 126 'desc_tip' => true 127 127 ), 128 'postnl_show_delivery_date' => array( 129 'type' => 'checkbox', 130 'title' => 'Verwachte levertijd voor PostNL', 131 'label' => 'Toon verwachte levertijd voor PostNL', 132 'desc_tip' => true, 133 'default' => 'no', 134 'description' => 'Toon bij de checkout de geschatte tijd waarop het pakket geleverd zal worden', 135 ), 136 'postnl_last_shipping_time' => array( 137 'type' => 'text', 138 'title' => 'Uiterlijke besteltijd voor verzending met PostNL.', 139 'default' => '17:00 Europe/Amsterdam', 140 'placeholder' => '17:00 Europe/Amsterdam', 141 'desc_tip' => true, 142 'description' => 'Stel hier de tijd in waarop de bestelling geplaatst moet zijn om nog dezelfde dag verzonden te worden. Bijvoorbeeld: \'17:00 Europe/Amsterdam\'.', 143 ), 144 'dhl_show_delivery_date' => array( 145 'type' => 'checkbox', 146 'title' => 'Verwachte levertijd voor DHL', 147 'label' => 'Toon verwachte levertijd voor DHL', 148 'desc_tip' => true, 149 'default' => 'no', 150 'description' => 'Toon bij de checkout de geschatte tijd waarop het pakket geleverd zal worden', 151 ), 152 'dhl_last_shipping_time' => array( 153 'type' => 'text', 154 'title' => 'Uiterlijke besteltijd voor verzending met DHL.', 155 'default' => '17:00 Europe/Amsterdam', 156 'placeholder' => '17:00 Europe/Amsterdam', 157 'desc_tip' => true, 158 'description' => 'Stel hier de tijd in waarop de bestelling geplaatst moet zijn om nog dezelfde dag verzonden te worden. Bijvoorbeeld: \'17:00 Europe/Amsterdam\'.', 159 ), 128 160 'services' => array( 129 161 'type' => 'services', -
woo-parcel-pro/tags/1.7.0/admin/data/parcelpro-shipping-settings-services.php
r2981554 r3030134 154 154 155 155 $type_id = ''; 156 // if(array_key_exists('type-id',$v)){157 // $type_id = '_' . $v['type-id'];158 // }159 156 if (!array_key_exists(ucfirst($parts[0]), $services)) { 160 157 $services[ucfirst($parts[0])] = array(); -
woo-parcel-pro/tags/1.7.0/admin/partials/parcelpro-shipping-settings-tables.php
r2981554 r3030134 152 152 <?php } ?> 153 153 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][method-title]" value="<?php ( array_key_exists(('method-title'), $rule) ) ? ( $rule[ 'method-title' ] ) ? print( $rule[ 'method-title' ] ) : print( $carrier_name . ' ' . $type ) : print( $carrier_name . ' ' . $type ); ?>"/></td> 154 <!-- <td><input type="text" name="parcelpro_shipping_settings[--><?php //echo $id; ?><!--][--><?php //echo $rule_nr ?><!--][type-id]" value="--><?php //( $rule[ 'type-id' ] ) ? print( $rule[ 'type-id' ] ) : print( 0 ); ?><!--"/></td>-->155 154 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][min-weight]" value="<?php ( $rule[ 'min-weight' ] ) ? print( $rule[ 'min-weight' ] ) : print( 0 ); ?>"/></td> 156 155 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][max-weight]" value="<?php ( $rule[ 'max-weight' ] ) ? print( $rule[ 'max-weight' ] ) : print( 0 ); ?>"/></td> -
woo-parcel-pro/tags/1.7.0/changelog.md
r3019282 r3030134 1 1 # Changelog 2 3 ## 1.7.0 - 2024-02-01 4 * Added optional delivery time expectations for DHL and PostNL 5 2 6 ## 1.6.21 - 2024-01-09 3 7 * Fix custom shipping types -
woo-parcel-pro/tags/1.7.0/composer.json
r3019282 r3030134 3 3 "description": "Verzendmodule om gemakkelijk orders in te laden in het verzendsysteem van Parcel Pro.", 4 4 "type": "wordpress-plugin", 5 "version": "1. 6.21",5 "version": "1.7.0", 6 6 "require": { 7 "php": ">=7.1" 7 "php": ">=7.1", 8 "ext-curl": "*", 9 "ext-json": "*", 10 "ext-intl": "*" 8 11 }, 9 12 "license": [ -
woo-parcel-pro/tags/1.7.0/includes/class-parcelpro-api.php
r3019282 r3030134 278 278 279 279 /** 280 * Loads a list of available types that a user can add to their woocommerce enviro ment. Based on their active contracts.280 * Loads a list of available types that a user can add to their woocommerce environment. Based on their active contracts. 281 281 * through the api types. 282 282 * … … 306 306 return(($result_records)); 307 307 } 308 309 /** 310 * @param string $carrier The carrier name. 311 * @param DateTimeInterface $dateTime The date on which the package will be handed over to the carrier. 312 * @param $postcode string The postal code of the package destination. 313 * 314 * @return DateTimeImmutable|false 315 */ 316 public function getDeliveryDate(string $carrier, \DateTimeInterface $dateTime, string $postcode) 317 { 318 if (!$postcode) { 319 return $postcode; 320 } 321 $postcode = str_replace(' ', '', $postcode); 322 323 $date = $dateTime->format('Y-m-d'); 324 325 $query = http_build_query([ 326 'Startdatum' => $date, 327 'Postcode' => $postcode, 328 'GebruikerId' => $this->login_id, 329 'Map' => true, 330 ]); 331 332 $curlHandle = curl_init(); 333 curl_setopt_array($curlHandle, [ 334 CURLOPT_URL => $this->api_url . '/api/v3/timeframes.php?' . $query, 335 CURLOPT_HTTPHEADER => [ 336 'Content-Type: application/json', 337 'Digest: ' . hash_hmac( 338 "sha256", 339 sprintf('GebruikerId=%sPostcode=%sStartdatum=%s', $this->login_id, $postcode, $date), 340 $this->api_id 341 ), 342 ], 343 CURLOPT_CUSTOMREQUEST => "GET", 344 CURLOPT_HEADER => false, 345 CURLOPT_RETURNTRANSFER => true, 346 ]); 347 348 $responseBody = curl_exec($curlHandle); 349 $responseCode = curl_getinfo($curlHandle, CURLINFO_RESPONSE_CODE); 350 351 curl_close($curlHandle); 352 353 if ($responseCode !== 200) { 354 $logger = wc_get_logger(); 355 if ($logger) { 356 $logger->error(sprintf( 357 'Failed to get expected delivery date, response code %s, body:\n%s', 358 $responseCode, 359 $responseBody 360 )); 361 } 362 return "200"; 363 } 364 365 $responseJson = json_decode($responseBody, true); 366 $rawDate = false; 367 368 // Lookup the expected date in a case-insensitive way, since a carrier may be "Postnl" or PostNL". 369 foreach ($responseJson as $api_carrier => $carrier_times) { 370 if (strtolower($api_carrier) === strtolower($carrier)) { 371 $rawDate = $carrier_times['Date']; 372 } 373 } 374 375 if (!$rawDate) { 376 $logger = wc_get_logger(); 377 if ($logger) { 378 $logger->error(sprintf( 379 'Failed to get expected delivery date, body:\n%s', 380 $responseBody 381 )); 382 } 383 return $carrier; 384 } 385 386 return \DateTimeImmutable::createFromFormat('Y-m-d', $rawDate); 387 } 308 388 } -
woo-parcel-pro/tags/1.7.0/woocommerce-parcelpro.php
r3019282 r3030134 17 17 * Plugin URI: https://www.parcelpro.nl/koppelingen/woocommerce/ 18 18 * Description: Geef klanten de mogelijkheid om hun pakket af te halen bij een afhaalpunt in de buurt. Daarnaast exporteert de plug-in uw zendingen direct in het verzendsysteem van Parcel Pro. 19 * Version: 1. 6.2119 * Version: 1.7.0 20 20 * Author: Parcel Pro 21 21 * Author URI: https://parcelpro.nl/ … … 31 31 32 32 define('PARCELPRO_NAME', 'WooCommerce Parcel Pro'); 33 define('PARCELPRO_VERSION', '1. 6.21');33 define('PARCELPRO_VERSION', '1.7.0'); 34 34 define('PARCELPRO_REQUIRED_PHP_VERSION', '5.3'); 35 35 define('PARCELPRO_REQUIRED_WP_VERSION', '3.1'); -
woo-parcel-pro/trunk/admin/class-parcelpro-shipping.php
r3011954 r3030134 27 27 private $custom_services; 28 28 29 /** @var ParcelPro_API $api */ 29 30 private $api; 30 31 public $id; … … 107 108 108 109 include(plugin_dir_path(__FILE__) . 'partials/parcelpro-shipping-settings-tables.php'); 109 110 110 return ob_get_clean(); 111 111 } … … 122 122 { 123 123 $services = array(); 124 $posted_services = array_key_exists('parcelpro_shipping_settings', $_POST) ? $_POST[ 'parcelpro_shipping_settings' ] :null;124 $posted_services = $_POST['parcelpro_shipping_settings'] ?? null; 125 125 $posted_services_order = array_key_exists('service_order', $_POST) ? $_POST[ 'service_order' ] : array(); 126 126 $order_fix = count($posted_services_order) + 1; … … 131 131 $order = (in_array($id, $posted_services_order)) ? array_search($id, $posted_services_order) + 1 : $order_fix++; 132 132 133 $rule[ 'min-weight' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'min-weight' ]);134 $rule[ 'type-id' ] = isset($rule[ 'type-id' ]) ? WC_Settings_API::validate_decimal_field(null, $rule[ 'type-id' ]) : null;135 $rule[ 'max-weight' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'max-weight' ]);136 $rule[ 'min-total' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'min-total' ]);137 $rule[ 'max-total' ] = WC_Settings_API::validate_decimal_field(null, $rule[ 'max-total' ]);138 $rule[ 'price' ] = WC_Settings_API::validate_price_field(null, $rule[ 'price' ]);139 $rule[ 'servicepunt' ] = isset($rule[ 'servicepunt' ]) ? $rule['servicepunt'] :null;133 $rule[ 'min-weight' ] = $this->validate_decimal_field(null, $rule[ 'min-weight' ]); 134 $rule[ 'type-id' ] = isset($rule[ 'type-id' ]) ? $this->validate_decimal_field(null, $rule[ 'type-id' ]) : null; 135 $rule[ 'max-weight' ] = $this->validate_decimal_field(null, $rule[ 'max-weight' ]); 136 $rule[ 'min-total' ] = $this->validate_decimal_field(null, $rule[ 'min-total' ]); 137 $rule[ 'max-total' ] = $this->validate_decimal_field(null, $rule[ 'max-total' ]); 138 $rule[ 'price' ] = $this->validate_price_field(null, $rule[ 'price' ]); 139 $rule[ 'servicepunt' ] = $rule['servicepunt'] ?? null; 140 140 141 141 $services[ $id ]['id'] = $id; … … 151 151 152 152 $services[ $id ][ $nr ] = array( 153 'country' => ( isset($rule['country']) ) ? $rule['country'] :'NL',154 'method-title' => ( isset($rule['method-title']) ) ? $rule['method-title'] :null,155 'type-id' => ( isset($rule['type-id']) ) ? $rule['type-id'] :0,156 'min-weight' => ( isset($rule['min-weight']) ) ? $rule['min-weight'] :null,157 'max-weight' => ( isset($rule['max-weight']) ) ? $rule['max-weight'] :null,158 'min-total' => ( isset($rule['min-total']) ) ? $rule['min-total'] :null,159 'max-total' => ( isset($rule['max-total']) ) ? $rule['max-total'] :null,160 'price' => ( isset($rule['price']) ) ? $rule['price'] :null,161 'servicepunt' => ( isset($rule['servicepunt']) && $rule[ 'servicepunt' ] !== null) ? 'on' : null,162 'order' => ( isset($order) ) ? $order :null153 'country' => $rule['country'] ?? 'NL', 154 'method-title' => $rule['method-title'] ?? null, 155 'type-id' => $rule['type-id'] ?? 0, 156 'min-weight' => $rule['min-weight'] ?? null, 157 'max-weight' => $rule['max-weight'] ?? null, 158 'min-total' => $rule['min-total'] ?? null, 159 'max-total' => $rule['max-total'] ?? null, 160 'price' => $rule['price'] ?? null, 161 'servicepunt' => ( isset($rule['servicepunt']) ) ? 'on' : null, 162 'order' => $order ?? null 163 163 ); 164 164 } … … 177 177 * @param $price 178 178 */ 179 private function prepare_service($service, $service_title, $price, $order, $type_id, $servicepunt) 179 private function prepare_service($service, $service_title, $price, $order, $type_id, $servicepunt): void 180 180 { 181 181 $this->found_services[ $service ][ 'id' ] = 'parcelpro_' . $service; … … 193 193 * @param $package 194 194 */ 195 public function calculate_shipping($package = array()) 195 public function calculate_shipping($package = array()): void 196 196 { 197 197 $this->found_services = array(); … … 217 217 218 218 foreach ($this->services as $carrier_name => $carrier) { 219 $lowercaseCarrier = strtolower($carrier_name); 220 $shipping_time = new DateTimeImmutable(); 221 $rawCutoffTime = $this->get_option($lowercaseCarrier . '_last_shipping_time'); 222 $isBeforeCutoffTime = $this->isBeforeLastShippingTime($rawCutoffTime); 223 224 if (!$isBeforeCutoffTime) { 225 $shipping_time = $shipping_time->add(new DateInterval('P1D')); 226 } 227 // Fetch expected delivery day 228 $is_enabled = $this->get_option( 229 $lowercaseCarrier . '_show_delivery_date' 230 ); 231 $formattedDeliveryDate = ''; 232 if ($is_enabled === 'yes') { 233 $delivery_expected = $this->api->getDeliveryDate( 234 $carrier_name, 235 $shipping_time, 236 $package['destination']['postcode'] 237 ); 238 239 if ($delivery_expected) { 240 $formattedDeliveryDate = ' (' . $this->formatDeliveryDate($delivery_expected) . ')'; 241 } 242 } 243 219 244 foreach ($carrier as $key => $value) { 220 245 if (array_key_exists($key, $this->custom_services) && is_array($this->custom_services[ $key ])) { … … 232 257 } 233 258 234 $this->prepare_service($key . $maatwerk_type, $rule[ 'method-title' ], $rule[ 'price' ], $this->custom_services[ $key ][ 'order' ], key_exists('type-id', $rule) ? $rule[ 'type-id' ] : null, isset($rule[ 'servicepunt' ]) ? $rule[ 'servicepunt' ] : null); 259 $this->prepare_service( 260 $key . $maatwerk_type, 261 $rule[ 'method-title' ] . $formattedDeliveryDate, 262 $rule[ 'price' ], 263 $this->custom_services[ $key ][ 'order' ], 264 array_key_exists('type-id', $rule) ? $rule[ 'type-id' ] : null, 265 isset($rule[ 'servicepunt' ]) ? $rule[ 'servicepunt' ] : null 266 ); 235 267 } 236 268 } … … 248 280 } 249 281 282 private function isBeforeLastShippingTime($rawLastTime): bool 283 { 284 if (!$rawLastTime) { 285 return true; 286 } 287 288 try { 289 $parsed = new DateTime($rawLastTime); 290 } catch (\Exception $e) { 291 $logger = wc_get_logger(); 292 if ($logger) { 293 $logger->error(sprintf( 294 'Failed to parse last shipping time (%s): %s', 295 $rawLastTime, 296 $e->getMessage() 297 )); 298 } 299 return true; 300 } 301 302 $now = new DateTime(); 303 return $now < $parsed; 304 } 250 305 251 306 /** 252 307 * Sorts the found services on the given preferences. 253 308 * 254 * @since 1.2.1255 309 * @param $records 256 310 * @param $field 257 311 * @param bool $reverse 312 * 258 313 * @return array 314 *@since 1.2.1 259 315 */ 260 316 public function service_sort($records, $field, $reverse = false) … … 276 332 return $records; 277 333 } 334 335 private function formatDeliveryDate(\DateTimeInterface $date): string 336 { 337 $locale = get_locale(); 338 return \IntlDateFormatter::formatObject($date, 'd MMMM', $locale); 339 } 278 340 } -
woo-parcel-pro/trunk/admin/data/parcelpro-shipping-settings-fields.php
r3011954 r3030134 126 126 'desc_tip' => true 127 127 ), 128 'postnl_show_delivery_date' => array( 129 'type' => 'checkbox', 130 'title' => 'Verwachte levertijd voor PostNL', 131 'label' => 'Toon verwachte levertijd voor PostNL', 132 'desc_tip' => true, 133 'default' => 'no', 134 'description' => 'Toon bij de checkout de geschatte tijd waarop het pakket geleverd zal worden', 135 ), 136 'postnl_last_shipping_time' => array( 137 'type' => 'text', 138 'title' => 'Uiterlijke besteltijd voor verzending met PostNL.', 139 'default' => '17:00 Europe/Amsterdam', 140 'placeholder' => '17:00 Europe/Amsterdam', 141 'desc_tip' => true, 142 'description' => 'Stel hier de tijd in waarop de bestelling geplaatst moet zijn om nog dezelfde dag verzonden te worden. Bijvoorbeeld: \'17:00 Europe/Amsterdam\'.', 143 ), 144 'dhl_show_delivery_date' => array( 145 'type' => 'checkbox', 146 'title' => 'Verwachte levertijd voor DHL', 147 'label' => 'Toon verwachte levertijd voor DHL', 148 'desc_tip' => true, 149 'default' => 'no', 150 'description' => 'Toon bij de checkout de geschatte tijd waarop het pakket geleverd zal worden', 151 ), 152 'dhl_last_shipping_time' => array( 153 'type' => 'text', 154 'title' => 'Uiterlijke besteltijd voor verzending met DHL.', 155 'default' => '17:00 Europe/Amsterdam', 156 'placeholder' => '17:00 Europe/Amsterdam', 157 'desc_tip' => true, 158 'description' => 'Stel hier de tijd in waarop de bestelling geplaatst moet zijn om nog dezelfde dag verzonden te worden. Bijvoorbeeld: \'17:00 Europe/Amsterdam\'.', 159 ), 128 160 'services' => array( 129 161 'type' => 'services', -
woo-parcel-pro/trunk/admin/data/parcelpro-shipping-settings-services.php
r2981554 r3030134 154 154 155 155 $type_id = ''; 156 // if(array_key_exists('type-id',$v)){157 // $type_id = '_' . $v['type-id'];158 // }159 156 if (!array_key_exists(ucfirst($parts[0]), $services)) { 160 157 $services[ucfirst($parts[0])] = array(); -
woo-parcel-pro/trunk/admin/partials/parcelpro-shipping-settings-tables.php
r2981554 r3030134 152 152 <?php } ?> 153 153 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][method-title]" value="<?php ( array_key_exists(('method-title'), $rule) ) ? ( $rule[ 'method-title' ] ) ? print( $rule[ 'method-title' ] ) : print( $carrier_name . ' ' . $type ) : print( $carrier_name . ' ' . $type ); ?>"/></td> 154 <!-- <td><input type="text" name="parcelpro_shipping_settings[--><?php //echo $id; ?><!--][--><?php //echo $rule_nr ?><!--][type-id]" value="--><?php //( $rule[ 'type-id' ] ) ? print( $rule[ 'type-id' ] ) : print( 0 ); ?><!--"/></td>-->155 154 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][min-weight]" value="<?php ( $rule[ 'min-weight' ] ) ? print( $rule[ 'min-weight' ] ) : print( 0 ); ?>"/></td> 156 155 <td><input type="text" name="parcelpro_shipping_settings[<?php echo $id; ?>][<?php echo $rule_nr ?>][max-weight]" value="<?php ( $rule[ 'max-weight' ] ) ? print( $rule[ 'max-weight' ] ) : print( 0 ); ?>"/></td> -
woo-parcel-pro/trunk/changelog.md
r3019282 r3030134 1 1 # Changelog 2 3 ## 1.7.0 - 2024-02-01 4 * Added optional delivery time expectations for DHL and PostNL 5 2 6 ## 1.6.21 - 2024-01-09 3 7 * Fix custom shipping types -
woo-parcel-pro/trunk/composer.json
r3019282 r3030134 3 3 "description": "Verzendmodule om gemakkelijk orders in te laden in het verzendsysteem van Parcel Pro.", 4 4 "type": "wordpress-plugin", 5 "version": "1. 6.21",5 "version": "1.7.0", 6 6 "require": { 7 "php": ">=7.1" 7 "php": ">=7.1", 8 "ext-curl": "*", 9 "ext-json": "*", 10 "ext-intl": "*" 8 11 }, 9 12 "license": [ -
woo-parcel-pro/trunk/includes/class-parcelpro-api.php
r3019282 r3030134 278 278 279 279 /** 280 * Loads a list of available types that a user can add to their woocommerce enviro ment. Based on their active contracts.280 * Loads a list of available types that a user can add to their woocommerce environment. Based on their active contracts. 281 281 * through the api types. 282 282 * … … 306 306 return(($result_records)); 307 307 } 308 309 /** 310 * @param string $carrier The carrier name. 311 * @param DateTimeInterface $dateTime The date on which the package will be handed over to the carrier. 312 * @param $postcode string The postal code of the package destination. 313 * 314 * @return DateTimeImmutable|false 315 */ 316 public function getDeliveryDate(string $carrier, \DateTimeInterface $dateTime, string $postcode) 317 { 318 if (!$postcode) { 319 return $postcode; 320 } 321 $postcode = str_replace(' ', '', $postcode); 322 323 $date = $dateTime->format('Y-m-d'); 324 325 $query = http_build_query([ 326 'Startdatum' => $date, 327 'Postcode' => $postcode, 328 'GebruikerId' => $this->login_id, 329 'Map' => true, 330 ]); 331 332 $curlHandle = curl_init(); 333 curl_setopt_array($curlHandle, [ 334 CURLOPT_URL => $this->api_url . '/api/v3/timeframes.php?' . $query, 335 CURLOPT_HTTPHEADER => [ 336 'Content-Type: application/json', 337 'Digest: ' . hash_hmac( 338 "sha256", 339 sprintf('GebruikerId=%sPostcode=%sStartdatum=%s', $this->login_id, $postcode, $date), 340 $this->api_id 341 ), 342 ], 343 CURLOPT_CUSTOMREQUEST => "GET", 344 CURLOPT_HEADER => false, 345 CURLOPT_RETURNTRANSFER => true, 346 ]); 347 348 $responseBody = curl_exec($curlHandle); 349 $responseCode = curl_getinfo($curlHandle, CURLINFO_RESPONSE_CODE); 350 351 curl_close($curlHandle); 352 353 if ($responseCode !== 200) { 354 $logger = wc_get_logger(); 355 if ($logger) { 356 $logger->error(sprintf( 357 'Failed to get expected delivery date, response code %s, body:\n%s', 358 $responseCode, 359 $responseBody 360 )); 361 } 362 return "200"; 363 } 364 365 $responseJson = json_decode($responseBody, true); 366 $rawDate = false; 367 368 // Lookup the expected date in a case-insensitive way, since a carrier may be "Postnl" or PostNL". 369 foreach ($responseJson as $api_carrier => $carrier_times) { 370 if (strtolower($api_carrier) === strtolower($carrier)) { 371 $rawDate = $carrier_times['Date']; 372 } 373 } 374 375 if (!$rawDate) { 376 $logger = wc_get_logger(); 377 if ($logger) { 378 $logger->error(sprintf( 379 'Failed to get expected delivery date, body:\n%s', 380 $responseBody 381 )); 382 } 383 return $carrier; 384 } 385 386 return \DateTimeImmutable::createFromFormat('Y-m-d', $rawDate); 387 } 308 388 } -
woo-parcel-pro/trunk/woocommerce-parcelpro.php
r3019282 r3030134 17 17 * Plugin URI: https://www.parcelpro.nl/koppelingen/woocommerce/ 18 18 * Description: Geef klanten de mogelijkheid om hun pakket af te halen bij een afhaalpunt in de buurt. Daarnaast exporteert de plug-in uw zendingen direct in het verzendsysteem van Parcel Pro. 19 * Version: 1. 6.2119 * Version: 1.7.0 20 20 * Author: Parcel Pro 21 21 * Author URI: https://parcelpro.nl/ … … 31 31 32 32 define('PARCELPRO_NAME', 'WooCommerce Parcel Pro'); 33 define('PARCELPRO_VERSION', '1. 6.21');33 define('PARCELPRO_VERSION', '1.7.0'); 34 34 define('PARCELPRO_REQUIRED_PHP_VERSION', '5.3'); 35 35 define('PARCELPRO_REQUIRED_WP_VERSION', '3.1');
Note: See TracChangeset
for help on using the changeset viewer.