Plugin Directory

Changeset 2544845


Ignore:
Timestamp:
06/09/2021 07:32:06 AM (5 years ago)
Author:
cocolis
Message:

Version 1.0.5

  • Fix issue when cocolis api raise an exception
Location:
cocolis
Files:
127 added
3 edited

Legend:

Unmodified
Added
Removed
  • cocolis/trunk/class/wc-cocolis-payment.php

    r2513485 r2544845  
    100100    function cocolis_payment_complete($order_id)
    101101    {
    102         $order = wc_get_order($order_id);
    103         $order_data = $order->get_data();
    104         if ($order->has_shipping_method('cocolis')) {
    105             // The main address pieces:
    106             $store_name = get_bloginfo('name');
    107             $store_address     = get_option('woocommerce_store_address');
    108             $store_address_2   = get_option('woocommerce_store_address_2');
    109             $store_city        = get_option('woocommerce_store_city');
    110             $store_postcode    = get_option('woocommerce_store_postcode');
    111 
    112             // The country/state
    113             $store_raw_country = get_option('woocommerce_default_country');
    114 
    115             // Split the country/state
    116             $split_country = explode(":", $store_raw_country);
    117 
    118             // Country and state separated:
    119             $store_country = $split_country[0];
    120 
    121             $order_shipping_first_name = $order_data['shipping']['first_name'];
    122             $order_shipping_last_name = $order_data['shipping']['last_name'];
    123             $order_shipping_email = $order_data['billing']['email'];
    124             $order_shipping_company = $order_data['shipping']['company'];
    125             $order_shipping_address_1 = $order_data['shipping']['address_1'];
    126             $order_shipping_address_2 = $order_data['shipping']['address_2'];
    127             $order_shipping_city = $order_data['shipping']['city'];
    128             $order_shipping_state = $order_data['shipping']['state'];
    129             $order_shipping_postcode = $order_data['shipping']['postcode'];
    130             $order_shipping_country = $order_data['shipping']['country'];
    131             $order_shipping_phone = $order_data['billing']['phone'];
    132             $order_birthdate = $order->get_meta('birth_date');
    133 
    134             $from_composed_address = $store_address . ', '
    135                 . $store_postcode . ' ' . $store_city;
    136 
    137             $composed_address = $order_shipping_address_1 . ', ' . $order_shipping_postcode . ' ' . $order_shipping_city;
    138 
    139             $from_date = new DateTime('NOW');
    140             $from_date->setTimeZone(new DateTimeZone("Europe/Paris"));
    141 
    142             $to_date = new DateTime('NOW');
    143             $to_date  = $to_date->add(new DateInterval('P21D'));
    144             $to_date->setTimeZone(new DateTimeZone("Europe/Paris"));
    145 
    146             $from_date = $from_date->format('c');
    147             $to_date = $to_date->format('c');
    148 
    149             $products = (object) $order->get_items();
    150             $dimensions = 0;
    151 
    152             $arrayproducts = [];
    153 
    154             $arrayname = [];
    155 
    156             $shipping_class = new WC_Cocolis_Shipping_Method();
    157 
    158             $client = $shipping_class->cocolis_authenticated_client();
    159 
    160             $phone = $shipping_class->settings['phone'];
    161             if (empty($phone)) {
    162                 wp_die(__("No phone number provided in the Cocolis configuration", 'cocolis'), __("Required seller phone number", 'cocolis'), ['response' => 401, 'back_link' => true]);
    163                 exit;
     102        try {
     103            $order = wc_get_order($order_id);
     104            $order_data = $order->get_data();
     105            if ($order->has_shipping_method('cocolis')) {
     106                // The main address pieces:
     107                $store_name = get_bloginfo('name');
     108                $store_address     = get_option('woocommerce_store_address');
     109                $store_address_2   = get_option('woocommerce_store_address_2');
     110                $store_city        = get_option('woocommerce_store_city');
     111                $store_postcode    = get_option('woocommerce_store_postcode');
     112
     113                // The country/state
     114                $store_raw_country = get_option('woocommerce_default_country');
     115
     116                // Split the country/state
     117                $split_country = explode(":", $store_raw_country);
     118
     119                // Country and state separated:
     120                $store_country = $split_country[0];
     121
     122                $order_shipping_first_name = $order_data['shipping']['first_name'];
     123                $order_shipping_last_name = $order_data['shipping']['last_name'];
     124                $order_shipping_email = $order_data['billing']['email'];
     125                $order_shipping_company = $order_data['shipping']['company'];
     126                $order_shipping_address_1 = $order_data['shipping']['address_1'];
     127                $order_shipping_address_2 = $order_data['shipping']['address_2'];
     128                $order_shipping_city = $order_data['shipping']['city'];
     129                $order_shipping_state = $order_data['shipping']['state'];
     130                $order_shipping_postcode = $order_data['shipping']['postcode'];
     131                $order_shipping_country = $order_data['shipping']['country'];
     132                $order_shipping_phone = $order_data['billing']['phone'];
     133                $order_birthdate = $order->get_meta('birth_date');
     134
     135                $from_composed_address = $store_address . ', '
     136                    . $store_postcode . ' ' . $store_city;
     137
     138                $composed_address = $order_shipping_address_1 . ', ' . $order_shipping_postcode . ' ' . $order_shipping_city;
     139
     140                $from_date = new DateTime('NOW');
     141                $from_date->setTimeZone(new DateTimeZone("Europe/Paris"));
     142
     143                $to_date = new DateTime('NOW');
     144                $to_date  = $to_date->add(new DateInterval('P21D'));
     145                $to_date->setTimeZone(new DateTimeZone("Europe/Paris"));
     146
     147                $from_date = $from_date->format('c');
     148                $to_date = $to_date->format('c');
     149
     150                $products = (object) $order->get_items();
     151                $dimensions = 0;
     152
     153                $arrayproducts = [];
     154
     155                $arrayname = [];
     156
     157                $shipping_class = new WC_Cocolis_Shipping_Method();
     158
     159                $client = $shipping_class->cocolis_authenticated_client();
     160
     161                $phone = $shipping_class->settings['phone'];
     162                if (empty($phone)) {
     163                    wp_die(__("No phone number provided in the Cocolis configuration", 'cocolis'), __("Required seller phone number", 'cocolis'), ['response' => 401, 'back_link' => true]);
     164                    exit;
     165                }
     166
     167                $dimensions = 0;
     168
     169                foreach ($products as $product) {
     170                    $product = (object) $product;
     171                    $data = wc_get_product($product->get_product_id());
     172                    $width = (int) $data->get_width();
     173                    $length = (int) $data->get_length();
     174                    $height = (int) $data->get_height();
     175
     176                    if ($width == 0 || $length == 0 || $height == 0) {
     177                        // Use the default value of volume for delivery fees
     178                        $width = $shipping_class->width;
     179                        $length = $shipping_class->length;
     180                        $height = $shipping_class->height;
     181                        $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product['qty'];
     182                    } else {
     183                        $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product['qty'];
     184                    }
     185
     186
     187                    array_push($arrayname, $product->get_name());
     188                    array_push($arrayproducts, [
     189                        "title" => $product->get_name(),
     190                        "qty" => $product['qty'],
     191                        "img" => wp_get_attachment_url($data->get_image_id()),
     192                        "height" => (int) $height,
     193                        "width" => (int) $width,
     194                        "length" => (int) $length,
     195                    ]);
     196                }
     197
     198                $images = [];
     199                foreach ($arrayproducts as $image) {
     200                    if (!empty($image['img'])) {
     201                        array_push($images, $image['img']);
     202                    }
     203                }
     204
     205                if (strpos($order->get_shipping_method(), "with insurance") !== false || strpos($order->get_shipping_method(), "avec assurance") !== false) {
     206                    $birthday = new DateTime($order_birthdate);
     207
     208                    $params = [
     209                        "description" => "Livraison de la commande : " . implode(", ", $arrayname) . " vendue sur le site marketplace.",
     210                        "external_id" => $order_id,
     211                        "from_address" => $from_composed_address,
     212                        "from_postal_code" => $store_postcode,
     213                        "to_address" => $composed_address,
     214                        "to_postal_code" => $order_shipping_postcode,
     215                        "from_is_flexible" => false,
     216                        "from_pickup_date" => $from_date,
     217                        "from_need_help" => true,
     218                        "to_is_flexible" => false,
     219                        "to_need_help" => true,
     220                        "content_value" => floatval($order->get_subtotal_to_display(true)) * 100,
     221                        "with_insurance" => true,
     222                        "to_pickup_date" => $to_date,
     223                        "is_passenger" => false,
     224                        "is_packaged" => true,
     225                        "price" => (int) $order->get_shipping_total() * 100,
     226                        "volume" => $dimensions,
     227                        "environment" => "objects",
     228                        "photo_urls" => $images,
     229                        "rider_extra_information" => "Livraison de la commande : " . implode(", ", $arrayname),
     230                        "ride_objects_attributes" => $arrayproducts,
     231                        "ride_delivery_information_attributes" => [
     232                            "from_address" => $store_address,
     233                            "from_postal_code" => $store_postcode,
     234                            "from_city" => $store_city,
     235                            "from_country" => $store_country,
     236                            "from_contact_email" => $shipping_class->settings['email'],
     237                            "from_contact_phone" => $phone,
     238                            "from_contact_name" => $store_name,
     239                            "from_extra_information" => 'Vendeur Marketplace',
     240                            "to_address" => $order_shipping_address_1,
     241                            "to_postal_code" => $order_shipping_postcode,
     242                            "to_city" => $order_shipping_city,
     243                            "to_country" => $order_shipping_country,
     244                            "to_contact_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name,
     245                            "to_contact_email" => $order_shipping_email,
     246                            "to_contact_phone" => $order_shipping_phone,
     247                            "insurance_firstname" => $order_shipping_first_name,
     248                            "insurance_lastname" =>  $order_shipping_last_name,
     249                            "insurance_address" => $order_shipping_address_1,
     250                            "insurance_postal_code" => $order_shipping_postcode,
     251                            "insurance_city" => $order_shipping_city,
     252                            "insurance_country" => $order_shipping_country,
     253                            "insurance_birthdate" => $birthday->format('c')
     254                        ],
     255                    ];
     256
     257                    $client = $client->getRideClient();
     258                    $client->create($params);
     259                } else {
     260                    $params = [
     261                        "description" => "Livraison de la commande : " . implode(", ", $arrayname) . " vendue sur le site marketplace.",
     262                        "external_id" => $order_id,
     263                        "from_address" => $from_composed_address,
     264                        "from_postal_code" => $store_postcode,
     265                        "to_address" => $composed_address,
     266                        "to_postal_code" => $order_shipping_postcode,
     267                        "from_is_flexible" => false,
     268                        "from_pickup_date" => $from_date,
     269                        "from_need_help" => true,
     270                        "to_is_flexible" => false,
     271                        "to_need_help" => true,
     272                        "with_insurance" => false,
     273                        "to_pickup_date" => $to_date,
     274                        "is_passenger" => false,
     275                        "is_packaged" => true,
     276                        "price" => floatval($order->get_subtotal_to_display(true)) * 100,
     277                        "volume" => $dimensions,
     278                        "environment" => "objects",
     279                        "photo_urls" => $images,
     280                        "rider_extra_information" => "Livraison de la commande : " . implode(", ", $arrayname),
     281                        "ride_objects_attributes" => $arrayproducts,
     282                        "ride_delivery_information_attributes" => [
     283                            "from_address" => $store_address,
     284                            "from_postal_code" => $store_postcode,
     285                            "from_city" => $store_city,
     286                            "from_country" => $store_country,
     287                            "from_contact_email" => $shipping_class->settings['email'],
     288                            "from_contact_phone" => $phone,
     289                            "from_contact_name" => $store_name,
     290                            "from_extra_information" => 'Vendeur Marketplace',
     291                            "to_address" => $order_shipping_address_1,
     292                            "to_postal_code" => $order_shipping_postcode,
     293                            "to_city" => $order_shipping_city,
     294                            "to_country" => $order_shipping_country,
     295                            "to_contact_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name,
     296                            "to_contact_email" => $order_shipping_email,
     297                            "to_contact_phone" => $order_shipping_phone
     298                        ],
     299                    ];
     300
     301                    $client = $client->getRideClient();
     302                    $client->create($params);
     303                }
    164304            }
    165 
    166             $dimensions = 0;
    167 
    168             foreach ($products as $product) {
    169                 $product = (object) $product;
    170                 $data = wc_get_product($product->get_product_id());
    171                 $width = (int) $data->get_width();
    172                 $length = (int) $data->get_length();
    173                 $height = (int) $data->get_height();
    174 
    175                 if ($width == 0 || $length == 0 || $height == 0) {
    176                     // Use the default value of volume for delivery fees
    177                     $width = $shipping_class->width;
    178                     $length = $shipping_class->length;
    179                     $height = $shipping_class->height;
    180                     $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product['qty'];
    181                 } else {
    182                     $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product['qty'];
    183                 }
    184 
    185 
    186                 array_push($arrayname, $product->get_name());
    187                 array_push($arrayproducts, [
    188                     "title" => $product->get_name(),
    189                     "qty" => $product['qty'],
    190                     "img" => wp_get_attachment_url($data->get_image_id()),
    191                     "height" => (int) $height,
    192                     "width" => (int) $width,
    193                     "length" => (int) $length,
    194                 ]);
    195             }
    196 
    197             $images = [];
    198             foreach ($arrayproducts as $image) {
    199                 if (!empty($image['img'])) {
    200                     array_push($images, $image['img']);
    201                 }
    202             }
    203 
    204             if (strpos($order->get_shipping_method(), "with insurance") !== false || strpos($order->get_shipping_method(), "avec assurance") !== false) {
    205                 $birthday = new DateTime($order_birthdate);
    206 
    207                 $params = [
    208                     "description" => "Livraison de la commande : " . implode(", ", $arrayname) . " vendue sur le site marketplace.",
    209                     "external_id" => $order_id,
    210                     "from_address" => $from_composed_address,
    211                     "from_postal_code" => $store_postcode,
    212                     "to_address" => $composed_address,
    213                     "to_postal_code" => $order_shipping_postcode,
    214                     "from_is_flexible" => false,
    215                     "from_pickup_date" => $from_date,
    216                     "from_need_help" => true,
    217                     "to_is_flexible" => false,
    218                     "to_need_help" => true,
    219                     "content_value" => floatval($order->get_subtotal_to_display(true)) * 100,
    220                     "with_insurance" => true,
    221                     "to_pickup_date" => $to_date,
    222                     "is_passenger" => false,
    223                     "is_packaged" => true,
    224                     "price" => (int) $order->get_shipping_total() * 100,
    225                     "volume" => $dimensions,
    226                     "environment" => "objects",
    227                     "photo_urls" => $images,
    228                     "rider_extra_information" => "Livraison de la commande : " . implode(", ", $arrayname),
    229                     "ride_objects_attributes" => $arrayproducts,
    230                     "ride_delivery_information_attributes" => [
    231                         "from_address" => $store_address,
    232                         "from_postal_code" => $store_postcode,
    233                         "from_city" => $store_city,
    234                         "from_country" => $store_country,
    235                         "from_contact_email" => $shipping_class->settings['email'],
    236                         "from_contact_phone" => $phone,
    237                         "from_contact_name" => $store_name,
    238                         "from_extra_information" => 'Vendeur Marketplace',
    239                         "to_address" => $order_shipping_address_1,
    240                         "to_postal_code" => $order_shipping_postcode,
    241                         "to_city" => $order_shipping_city,
    242                         "to_country" => $order_shipping_country,
    243                         "to_contact_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name,
    244                         "to_contact_email" => $order_shipping_email,
    245                         "to_contact_phone" => $order_shipping_phone,
    246                         "insurance_firstname" => $order_shipping_first_name,
    247                         "insurance_lastname" =>  $order_shipping_last_name,
    248                         "insurance_address" => $order_shipping_address_1,
    249                         "insurance_postal_code" => $order_shipping_postcode,
    250                         "insurance_city" => $order_shipping_city,
    251                         "insurance_country" => $order_shipping_country,
    252                         "insurance_birthdate" => $birthday->format('c')
    253                     ],
    254                 ];
    255 
    256                 $client = $client->getRideClient();
    257                 $client->create($params);
    258             } else {
    259                 $params = [
    260                     "description" => "Livraison de la commande : " . implode(", ", $arrayname) . " vendue sur le site marketplace.",
    261                     "external_id" => $order_id,
    262                     "from_address" => $from_composed_address,
    263                     "from_postal_code" => $store_postcode,
    264                     "to_address" => $composed_address,
    265                     "to_postal_code" => $order_shipping_postcode,
    266                     "from_is_flexible" => false,
    267                     "from_pickup_date" => $from_date,
    268                     "from_need_help" => true,
    269                     "to_is_flexible" => false,
    270                     "to_need_help" => true,
    271                     "with_insurance" => false,
    272                     "to_pickup_date" => $to_date,
    273                     "is_passenger" => false,
    274                     "is_packaged" => true,
    275                     "price" => floatval($order->get_subtotal_to_display(true)) * 100,
    276                     "volume" => $dimensions,
    277                     "environment" => "objects",
    278                     "photo_urls" => $images,
    279                     "rider_extra_information" => "Livraison de la commande : " . implode(", ", $arrayname),
    280                     "ride_objects_attributes" => $arrayproducts,
    281                     "ride_delivery_information_attributes" => [
    282                         "from_address" => $store_address,
    283                         "from_postal_code" => $store_postcode,
    284                         "from_city" => $store_city,
    285                         "from_country" => $store_country,
    286                         "from_contact_email" => $shipping_class->settings['email'],
    287                         "from_contact_phone" => $phone,
    288                         "from_contact_name" => $store_name,
    289                         "from_extra_information" => 'Vendeur Marketplace',
    290                         "to_address" => $order_shipping_address_1,
    291                         "to_postal_code" => $order_shipping_postcode,
    292                         "to_city" => $order_shipping_city,
    293                         "to_country" => $order_shipping_country,
    294                         "to_contact_name" => $order_shipping_first_name . ' ' . $order_shipping_last_name,
    295                         "to_contact_email" => $order_shipping_email,
    296                         "to_contact_phone" => $order_shipping_phone
    297                     ],
    298                 ];
    299 
    300                 $client = $client->getRideClient();
    301                 $client->create($params);
    302             }
     305        } catch (\Throwable $th) {
     306            error_log('Cocolis ERROR : ' . $th);
     307            return false;
    303308        }
    304309    }
  • cocolis/trunk/readme.txt

    r2533455 r2544845  
    5656== Changelog ==
    5757
     58= 1.0.5 =
     59* En cas de soucis avec l'api cocolis, ne pas proposer cocolis comme mode de livraison
     60
    5861= 1.0.4 =
    5962* Correctif sur les logos devant les modes de livraison
  • cocolis/trunk/wc-cocolis-shipping.php

    r2533455 r2544845  
    77 * Author:  Cocolis.fr
    88 * Author URI: https://www.cocolis.fr
    9  * Version: 1.0.4
     9 * Version: 1.0.5
    1010 * Developer: Alexandre BETTAN, Sebastien FIELOUX
    1111 * Developer URI: https://github.com/btnalexandre, https://github.com/sebfie
     
    260260                public function calculate_shipping($package = array())
    261261                {
    262                     $package = (object) $package;
    263                     $destination = (object) $package->destination;
    264                     $postcode = $destination->postcode;
    265                     $total = 0;
    266                     $dimensions = 0;
    267                     if (!empty($postcode)) {
    268                         $client = $this->cocolis_authenticated_client();
    269                         $products = $package->contents;
    270                         foreach ($products as $product) {
    271                             $product = (object) $product;
    272                             $width = (int) $product->data->get_width();
    273                             $length = (int) $product->data->get_length();
    274                             $height = (int) $product->data->get_height();
    275 
    276                             if ($width == 0 || $length == 0 || $height == 0) {
    277                                 // Use the default value of volume for delivery fees
    278                                 $width = $this->width;
    279                                 $length = $this->length;
    280                                 $height = $this->height;
    281                                 $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product->quantity;
    282                             } else {
    283                                 $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product->quantity;
     262                    try {
     263                        $package = (object) $package;
     264                        $destination = (object) $package->destination;
     265                        $postcode = $destination->postcode;
     266                        $total = 0;
     267                        $dimensions = 0;
     268                        if (!empty($postcode)) {
     269                            $client = $this->cocolis_authenticated_client();
     270                            $products = $package->contents;
     271                            foreach ($products as $product) {
     272                                $product = (object) $product;
     273                                $width = (int) $product->data->get_width();
     274                                $length = (int) $product->data->get_length();
     275                                $height = (int) $product->data->get_height();
     276
     277                                if ($width == 0 || $length == 0 || $height == 0) {
     278                                    // Use the default value of volume for delivery fees
     279                                    $width = $this->width;
     280                                    $length = $this->length;
     281                                    $height = $this->height;
     282                                    $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product->quantity;
     283                                } else {
     284                                    $dimensions += (($width * $length * $height) / pow(10, 6)) * (int) $product->quantity;
     285                                }
     286
     287                                $total += (int) $product->data->get_price() * (int) $product->quantity;
    284288                            }
    285289
    286                             $total += (int) $product->data->get_price() * (int) $product->quantity;
    287                         }
    288 
    289 
    290                         if ($dimensions < 0.01) {
    291                             $dimensions += 0.01;
    292                         }
    293 
    294                         $dimensions = round($dimensions, 2);
    295 
    296                         $match = $client->getRideClient()->canMatch(get_option('woocommerce_store_postcode'), $postcode, $dimensions, $total * 100);
    297 
    298                         // Register the rate
    299                         if ($match->result) {
    300                             $shipping_cost = ($match->estimated_prices->regular) / 100;
    301 
    302                             if ($shipping_cost > 0) {
    303                                 $rate = array(
    304                                     'id'   => 'cocolis',
    305                                     'label' => '<svg viewBox="0 0 136.1 40" width="84" height="26"><path d="M107.9 10.1c2 0 3.6-1.6 3.6-3.6s-1.6-3.6-3.6-3.6-3.6 1.6-3.6 3.6 1.6 3.6 3.6 3.6m12.4 9c.7 0 1.4 0 2 .1l-2.5-5.3c-.4-.1-.8-.1-1.3-.1-4.3 0-6.5 2.6-6.5 6.5 0 2.2 2 7.2 2 9 0 1.2-.8 1.9-2.3 1.9-.6 0-1.7 0-2.7-.2l2.5 5.3c.6.1 1.2.2 1.9.2 4.4 0 6.7-2.7 6.7-6.4 0-2.7-2-7.2-2-9-.1-1 .5-2 2.2-2m-11.5-4.9h-6.1l-3.1 11.5-7.4 4.3 7.2-26.8h-6.1L86.1 30c-.3 1.1-.3 1.7-.3 2.3 0 2.3 1.9 4.2 4.3 4.2 1.2 0 2.2-.5 3.2-1.1l4.9-2.8c.1 2.2 1.9 3.9 4.3 3.9 1.2 0 2.2-.5 3.2-1.1l1.4-.8 1.9-7.1-4.3 2.5 4.1-15.8zM74 30.9c-3.2 0-5.7-2.4-5.7-5.8 0-3.5 2.6-5.8 5.7-5.8 3.2 0 5.8 2.4 5.8 5.8s-2.6 5.8-5.8 5.8m0-17.2c-6.5 0-11.8 5.1-11.8 11.4 0 1.2.2 2.3.5 3.4C61 30 59.1 31 56.5 31c-3.8 0-6-2.7-6-5.9s2.3-5.8 6.4-5.8c.8 0 1.7 0 2.7.2l-2.7-5.7c-.4-.1-.9-.1-1.3-.1-5.9 0-11.1 5.3-11.1 11.5 0 6.4 4.8 11.2 11.8 11.2 3.6 0 6.5-1.5 9-3.9 2.2 2.4 5.3 3.9 8.8 3.9 6.5 0 11.8-5.1 11.8-11.4-.1-6.2-5.4-11.3-11.9-11.3" fill="#484867"></path><path d="M31.4 30.9c-3.2 0-5.7-2.4-5.7-5.8 0-3.5 2.6-5.8 5.7-5.8 3.2 0 5.8 2.4 5.8 5.8s-2.6 5.8-5.8 5.8m0-17.2c-6.5 0-11.8 5.1-11.8 11.4 0 1.2.2 2.3.5 3.4-1.7 1.5-3.6 2.5-6.2 2.5-3.8 0-6-2.7-6-5.9s2.3-5.8 6.4-5.8c.8 0 1.7 0 2.7.2l-2.7-5.7c-.4-.1-.9-.1-1.3-.1-5.9 0-11.2 5.3-11.2 11.5 0 6.4 4.8 11.2 11.8 11.2 3.6 0 6.5-1.5 9-3.9 2.2 2.4 5.3 3.9 8.8 3.9 6.5 0 11.8-5.1 11.8-11.4.1-6.2-5.3-11.3-11.8-11.3" fill="#0069D8"></path></svg> ' . $this->title,
    306                                     'cost' => $shipping_cost,
    307                                 );
    308 
    309                                 $this->add_rate($rate);
    310 
    311 
    312 
    313                                 if ($total >= 500) {
    314                                     $shipping_cost_insurance = ($match->estimated_prices->with_insurance) / 100;
    315                                     if ($shipping_cost_insurance > 0) {
    316                                         $rate = array(
    317                                             'id'   => 'cocolis_assurance',
    318                                             'label' => $this->title . __(' with insurance', 'cocolis'),
    319                                             'cost' => $shipping_cost_insurance,
    320                                         );
    321                                         $this->add_rate($rate);
     290
     291                            if ($dimensions < 0.01) {
     292                                $dimensions += 0.01;
     293                            }
     294
     295                            $dimensions = round($dimensions, 2);
     296
     297                            $match = $client->getRideClient()->canMatch(get_option('woocommerce_store_postcode'), $postcode, $dimensions, $total * 100);
     298
     299                            // Register the rate
     300                            if ($match->result) {
     301                                $shipping_cost = ($match->estimated_prices->regular) / 100;
     302
     303                                if ($shipping_cost > 0) {
     304                                    $rate = array(
     305                                        'id'   => 'cocolis',
     306                                        'label' => '<svg viewBox="0 0 136.1 40" width="84" height="26"><path d="M107.9 10.1c2 0 3.6-1.6 3.6-3.6s-1.6-3.6-3.6-3.6-3.6 1.6-3.6 3.6 1.6 3.6 3.6 3.6m12.4 9c.7 0 1.4 0 2 .1l-2.5-5.3c-.4-.1-.8-.1-1.3-.1-4.3 0-6.5 2.6-6.5 6.5 0 2.2 2 7.2 2 9 0 1.2-.8 1.9-2.3 1.9-.6 0-1.7 0-2.7-.2l2.5 5.3c.6.1 1.2.2 1.9.2 4.4 0 6.7-2.7 6.7-6.4 0-2.7-2-7.2-2-9-.1-1 .5-2 2.2-2m-11.5-4.9h-6.1l-3.1 11.5-7.4 4.3 7.2-26.8h-6.1L86.1 30c-.3 1.1-.3 1.7-.3 2.3 0 2.3 1.9 4.2 4.3 4.2 1.2 0 2.2-.5 3.2-1.1l4.9-2.8c.1 2.2 1.9 3.9 4.3 3.9 1.2 0 2.2-.5 3.2-1.1l1.4-.8 1.9-7.1-4.3 2.5 4.1-15.8zM74 30.9c-3.2 0-5.7-2.4-5.7-5.8 0-3.5 2.6-5.8 5.7-5.8 3.2 0 5.8 2.4 5.8 5.8s-2.6 5.8-5.8 5.8m0-17.2c-6.5 0-11.8 5.1-11.8 11.4 0 1.2.2 2.3.5 3.4C61 30 59.1 31 56.5 31c-3.8 0-6-2.7-6-5.9s2.3-5.8 6.4-5.8c.8 0 1.7 0 2.7.2l-2.7-5.7c-.4-.1-.9-.1-1.3-.1-5.9 0-11.1 5.3-11.1 11.5 0 6.4 4.8 11.2 11.8 11.2 3.6 0 6.5-1.5 9-3.9 2.2 2.4 5.3 3.9 8.8 3.9 6.5 0 11.8-5.1 11.8-11.4-.1-6.2-5.4-11.3-11.9-11.3" fill="#484867"></path><path d="M31.4 30.9c-3.2 0-5.7-2.4-5.7-5.8 0-3.5 2.6-5.8 5.7-5.8 3.2 0 5.8 2.4 5.8 5.8s-2.6 5.8-5.8 5.8m0-17.2c-6.5 0-11.8 5.1-11.8 11.4 0 1.2.2 2.3.5 3.4-1.7 1.5-3.6 2.5-6.2 2.5-3.8 0-6-2.7-6-5.9s2.3-5.8 6.4-5.8c.8 0 1.7 0 2.7.2l-2.7-5.7c-.4-.1-.9-.1-1.3-.1-5.9 0-11.2 5.3-11.2 11.5 0 6.4 4.8 11.2 11.8 11.2 3.6 0 6.5-1.5 9-3.9 2.2 2.4 5.3 3.9 8.8 3.9 6.5 0 11.8-5.1 11.8-11.4.1-6.2-5.3-11.3-11.8-11.3" fill="#0069D8"></path></svg> ' . $this->title,
     307                                        'cost' => $shipping_cost,
     308                                    );
     309
     310                                    $this->add_rate($rate);
     311
     312
     313
     314                                    if ($total >= 500) {
     315                                        $shipping_cost_insurance = ($match->estimated_prices->with_insurance) / 100;
     316                                        if ($shipping_cost_insurance > 0) {
     317                                            $rate = array(
     318                                                'id'   => 'cocolis_assurance',
     319                                                'label' => $this->title . __(' with insurance', 'cocolis'),
     320                                                'cost' => $shipping_cost_insurance,
     321                                            );
     322                                            $this->add_rate($rate);
     323                                        }
    322324                                    }
    323325                                }
    324326                            }
    325327                        }
     328                    } catch (\Throwable $th) {
     329                        error_log('Cocolis ERROR : ' . $th);
     330                        return false;
    326331                    }
    327332                }
Note: See TracChangeset for help on using the changeset viewer.