Plugin Directory

Changeset 3030134


Ignore:
Timestamp:
02/01/2024 02:04:46 PM (2 years ago)
Author:
parcelpro
Message:

Update to version 1.7.0 from GitHub

Location:
woo-parcel-pro
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • woo-parcel-pro/tags/1.7.0/admin/class-parcelpro-shipping.php

    r3011954 r3030134  
    2727    private $custom_services;
    2828
     29    /** @var ParcelPro_API $api */
    2930    private $api;
    3031    public $id;
     
    107108
    108109        include(plugin_dir_path(__FILE__) . 'partials/parcelpro-shipping-settings-tables.php');
    109 
    110110        return ob_get_clean();
    111111    }
     
    122122    {
    123123        $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;
    125125        $posted_services_order = array_key_exists('service_order', $_POST) ? $_POST[ 'service_order' ] : array();
    126126        $order_fix = count($posted_services_order) + 1;
     
    131131                    $order = (in_array($id, $posted_services_order)) ? array_search($id, $posted_services_order) + 1 : $order_fix++;
    132132
    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;
    140140
    141141                    $services[ $id ]['id'] = $id;
     
    151151
    152152                    $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 : null
     153                        '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
    163163                    );
    164164                }
     
    177177     * @param $price
    178178     */
    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
    180180    {
    181181        $this->found_services[ $service ][ 'id' ] = 'parcelpro_' . $service;
     
    193193     * @param $package
    194194     */
    195     public function calculate_shipping($package = array())
     195    public function calculate_shipping($package = array()): void
    196196    {
    197197        $this->found_services = array();
     
    217217
    218218            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
    219244                foreach ($carrier as $key => $value) {
    220245                    if (array_key_exists($key, $this->custom_services) && is_array($this->custom_services[ $key ])) {
     
    232257                                }
    233258
    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                                );
    235267                            }
    236268                        }
     
    248280    }
    249281
     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    }
    250305
    251306    /**
    252307     * Sorts the found services on the given preferences.
    253308     *
    254      * @since    1.2.1
    255309     * @param $records
    256310     * @param $field
    257311     * @param bool $reverse
     312     *
    258313     * @return array
     314     *@since    1.2.1
    259315     */
    260316    public function service_sort($records, $field, $reverse = false)
     
    276332        return $records;
    277333    }
     334
     335    private function formatDeliveryDate(\DateTimeInterface $date): string
     336    {
     337        $locale = get_locale();
     338        return \IntlDateFormatter::formatObject($date, 'd MMMM', $locale);
     339    }
    278340}
  • woo-parcel-pro/tags/1.7.0/admin/data/parcelpro-shipping-settings-fields.php

    r3011954 r3030134  
    126126        'desc_tip'    => true
    127127    ),
     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    ),
    128160    'services'     => array(
    129161        'type' => 'services',
  • woo-parcel-pro/tags/1.7.0/admin/data/parcelpro-shipping-settings-services.php

    r2981554 r3030134  
    154154
    155155            $type_id = '';
    156 //            if(array_key_exists('type-id',$v)){
    157 //                $type_id = '_' . $v['type-id'];
    158 //            }
    159156            if (!array_key_exists(ucfirst($parts[0]), $services)) {
    160157                $services[ucfirst($parts[0])] = array();
  • woo-parcel-pro/tags/1.7.0/admin/partials/parcelpro-shipping-settings-tables.php

    r2981554 r3030134  
    152152                                <?php } ?>
    153153                                <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>-->
    155154                                <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>
    156155                                <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  
    11# Changelog
     2
     3## 1.7.0 - 2024-02-01
     4* Added optional delivery time expectations for DHL and PostNL
     5
    26## 1.6.21 - 2024-01-09
    37* Fix custom shipping types
  • woo-parcel-pro/tags/1.7.0/composer.json

    r3019282 r3030134  
    33  "description": "Verzendmodule om gemakkelijk orders in te laden in het verzendsysteem van Parcel Pro.",
    44  "type": "wordpress-plugin",
    5   "version": "1.6.21",
     5  "version": "1.7.0",
    66  "require": {
    7     "php": ">=7.1"
     7    "php": ">=7.1",
     8    "ext-curl": "*",
     9    "ext-json": "*",
     10    "ext-intl": "*"
    811  },
    912  "license": [
  • woo-parcel-pro/tags/1.7.0/includes/class-parcelpro-api.php

    r3019282 r3030134  
    278278
    279279    /**
    280      * Loads a list of available types that a user can add to their woocommerce enviroment. 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.
    281281     * through the api types.
    282282     *
     
    306306        return(($result_records));
    307307    }
     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    }
    308388}
  • woo-parcel-pro/tags/1.7.0/woocommerce-parcelpro.php

    r3019282 r3030134  
    1717 * Plugin URI:      https://www.parcelpro.nl/koppelingen/woocommerce/
    1818 * 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.21
     19 * Version:         1.7.0
    2020 * Author:          Parcel Pro
    2121 * Author URI:      https://parcelpro.nl/
     
    3131
    3232define('PARCELPRO_NAME', 'WooCommerce Parcel Pro');
    33 define('PARCELPRO_VERSION', '1.6.21');
     33define('PARCELPRO_VERSION', '1.7.0');
    3434define('PARCELPRO_REQUIRED_PHP_VERSION', '5.3');
    3535define('PARCELPRO_REQUIRED_WP_VERSION', '3.1');
  • woo-parcel-pro/trunk/admin/class-parcelpro-shipping.php

    r3011954 r3030134  
    2727    private $custom_services;
    2828
     29    /** @var ParcelPro_API $api */
    2930    private $api;
    3031    public $id;
     
    107108
    108109        include(plugin_dir_path(__FILE__) . 'partials/parcelpro-shipping-settings-tables.php');
    109 
    110110        return ob_get_clean();
    111111    }
     
    122122    {
    123123        $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;
    125125        $posted_services_order = array_key_exists('service_order', $_POST) ? $_POST[ 'service_order' ] : array();
    126126        $order_fix = count($posted_services_order) + 1;
     
    131131                    $order = (in_array($id, $posted_services_order)) ? array_search($id, $posted_services_order) + 1 : $order_fix++;
    132132
    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;
    140140
    141141                    $services[ $id ]['id'] = $id;
     
    151151
    152152                    $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 : null
     153                        '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
    163163                    );
    164164                }
     
    177177     * @param $price
    178178     */
    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
    180180    {
    181181        $this->found_services[ $service ][ 'id' ] = 'parcelpro_' . $service;
     
    193193     * @param $package
    194194     */
    195     public function calculate_shipping($package = array())
     195    public function calculate_shipping($package = array()): void
    196196    {
    197197        $this->found_services = array();
     
    217217
    218218            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
    219244                foreach ($carrier as $key => $value) {
    220245                    if (array_key_exists($key, $this->custom_services) && is_array($this->custom_services[ $key ])) {
     
    232257                                }
    233258
    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                                );
    235267                            }
    236268                        }
     
    248280    }
    249281
     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    }
    250305
    251306    /**
    252307     * Sorts the found services on the given preferences.
    253308     *
    254      * @since    1.2.1
    255309     * @param $records
    256310     * @param $field
    257311     * @param bool $reverse
     312     *
    258313     * @return array
     314     *@since    1.2.1
    259315     */
    260316    public function service_sort($records, $field, $reverse = false)
     
    276332        return $records;
    277333    }
     334
     335    private function formatDeliveryDate(\DateTimeInterface $date): string
     336    {
     337        $locale = get_locale();
     338        return \IntlDateFormatter::formatObject($date, 'd MMMM', $locale);
     339    }
    278340}
  • woo-parcel-pro/trunk/admin/data/parcelpro-shipping-settings-fields.php

    r3011954 r3030134  
    126126        'desc_tip'    => true
    127127    ),
     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    ),
    128160    'services'     => array(
    129161        'type' => 'services',
  • woo-parcel-pro/trunk/admin/data/parcelpro-shipping-settings-services.php

    r2981554 r3030134  
    154154
    155155            $type_id = '';
    156 //            if(array_key_exists('type-id',$v)){
    157 //                $type_id = '_' . $v['type-id'];
    158 //            }
    159156            if (!array_key_exists(ucfirst($parts[0]), $services)) {
    160157                $services[ucfirst($parts[0])] = array();
  • woo-parcel-pro/trunk/admin/partials/parcelpro-shipping-settings-tables.php

    r2981554 r3030134  
    152152                                <?php } ?>
    153153                                <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>-->
    155154                                <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>
    156155                                <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  
    11# Changelog
     2
     3## 1.7.0 - 2024-02-01
     4* Added optional delivery time expectations for DHL and PostNL
     5
    26## 1.6.21 - 2024-01-09
    37* Fix custom shipping types
  • woo-parcel-pro/trunk/composer.json

    r3019282 r3030134  
    33  "description": "Verzendmodule om gemakkelijk orders in te laden in het verzendsysteem van Parcel Pro.",
    44  "type": "wordpress-plugin",
    5   "version": "1.6.21",
     5  "version": "1.7.0",
    66  "require": {
    7     "php": ">=7.1"
     7    "php": ">=7.1",
     8    "ext-curl": "*",
     9    "ext-json": "*",
     10    "ext-intl": "*"
    811  },
    912  "license": [
  • woo-parcel-pro/trunk/includes/class-parcelpro-api.php

    r3019282 r3030134  
    278278
    279279    /**
    280      * Loads a list of available types that a user can add to their woocommerce enviroment. 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.
    281281     * through the api types.
    282282     *
     
    306306        return(($result_records));
    307307    }
     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    }
    308388}
  • woo-parcel-pro/trunk/woocommerce-parcelpro.php

    r3019282 r3030134  
    1717 * Plugin URI:      https://www.parcelpro.nl/koppelingen/woocommerce/
    1818 * 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.21
     19 * Version:         1.7.0
    2020 * Author:          Parcel Pro
    2121 * Author URI:      https://parcelpro.nl/
     
    3131
    3232define('PARCELPRO_NAME', 'WooCommerce Parcel Pro');
    33 define('PARCELPRO_VERSION', '1.6.21');
     33define('PARCELPRO_VERSION', '1.7.0');
    3434define('PARCELPRO_REQUIRED_PHP_VERSION', '5.3');
    3535define('PARCELPRO_REQUIRED_WP_VERSION', '3.1');
Note: See TracChangeset for help on using the changeset viewer.