diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 679f83b..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/CHANGELOG.md b/CHANGELOG.md index b13f0f8..df40b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## Released +## [2.7.25](https://github.com/wuunder/wuunder-webshopplugin-woocommerce/tag/2.7.25) - 2022-11-24 + +### Fixed +- Weight calculations ensure number during calculations + ## [2.7.24](https://github.com/wuunder/wuunder-webshopplugin-woocommerce/tag/2.7.24) - 2022-04-19 ### Fixed diff --git a/includes/checkout.php b/includes/checkout.php index 1ad1f84..4b57cb9 100644 --- a/includes/checkout.php +++ b/includes/checkout.php @@ -34,7 +34,7 @@ function wcwp_parcelshop_html() $tmpEnvironment = new \Wuunder\Api\Environment(get_option('wc_wuunder_api_status') === 'staging' ? 'staging' : 'production'); $baseApiUrl = substr($tmpEnvironment->getStageBaseUrl(), 0, -3); - $carrierConfigList = get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] ? get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] : []; + $carrierConfigList = get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] ?? []; $carrierList = implode(',', $carrierConfigList); if (0 !== strlen($carrierList)) { $availableCarriers = $carrierList; @@ -112,7 +112,6 @@ function prefix_wc_rest_prepare_order_object($response, $object, $request) $shipping_method_id = wcwp_get_filter_from_shippingmethod(reset($shipping_object)->get_method_id()); } } catch (Exception $e) { - } $response->data['wuunder_preferred_service_level'] = $shipping_method_id; @@ -150,28 +149,34 @@ function wcwp_get_order_weight($order_id) // Create the product $product = $item->get_product(); // Set item weight - $weight = $product->get_weight(); + $weight = floatval($product->get_weight()); + $weight = empty($weight) ? 0 : $weight; $weight_unit = get_option('woocommerce_weight_unit'); - $quantity = $item['qty']; - switch ($weight_unit) { - case 'kg': - $data['weight'] = $weight * 1000; - break; - case 'g': - $data['weight'] = $weight; - break; - case 'lbs': - $data['weight'] = $weight * 0.45359237; - break; - case 'oz': - $data['weight'] = $weight * 0.0283495231; - break; - default: - $data['weight'] = $weight; - break; + $quantity = (int)$item->get_quantity(); + try { + switch ($weight_unit) { + case 'kg': + $data['weight'] = $weight * 1000; + break; + case 'g': + $data['weight'] = $weight; + break; + case 'lbs': + $data['weight'] = $weight * 0.45359237; + break; + case 'oz': + $data['weight'] = $weight * 0.0283495231; + break; + default: + $data['weight'] = $weight; + break; + } + } catch (\Throwable $e) { + $data['weight'] = 0; + wcwp_log('error', 'Invalid weight value: ' . $weight); } - $total_product_weight = $quantity * $data['weight']; + $total_product_weight = intval($quantity * $data['weight']); $total_weight += $total_product_weight; } } @@ -186,7 +191,7 @@ function wcwp_update_parcelshop_id($order_id) { if (!empty($_POST['parcelshop_id']) && isset($_POST['shipping_method']) && isset($_POST['shipping_method'][0]) && 'wuunder_parcelshop' === sanitize_text_field($_POST['shipping_method'][0])) { update_post_meta($order_id, 'parcelshop_id', sanitize_text_field($_POST['parcelshop_id'])); - WC()->session->__unset( 'WCWP_SELECTED_PARCELSHOP_ID' ); + WC()->session->__unset('WCWP_SELECTED_PARCELSHOP_ID'); } } @@ -204,5 +209,3 @@ function wcwp_check_parcelshop_selection() } } } - -?> diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php index 786e752..207367a 100644 --- a/includes/wcwuunder-create.php +++ b/includes/wcwuunder-create.php @@ -13,12 +13,14 @@ public function __construct() $this->version_obj = array( 'product' => 'Woocommerce extension', 'version' => array( - 'build' => '2.7.24', - 'plugin' => '2.0'), + 'build' => '2.7.25', + 'plugin' => '2.0' + ), 'platform' => array( 'name' => 'Woocommerce', 'build' => WC()->version - )); + ) + ); add_action('load-edit.php', array(&$this, 'wcwp_generateBookingUrl')); add_action('woocommerce_admin_order_actions_end', array(&$this, 'wcwp_add_listing_actions')); add_action('add_meta_boxes_shop_order', array(&$this, 'wcwp_add_meta_boxes')); @@ -44,15 +46,12 @@ public function wcwp_sample_admin_notice__error() $message .= ''; printf('

%2$s

', $class, $message); - } elseif ('success' == isset($_GET['notice']) && $_GET['notice']) { $class = 'notice notice-success'; $message = __('Het verzendlabel voor #' . sanitize_text_field($_GET['id']) . ' is aangemaakt', 'woocommerce-wuunder'); printf('

%2$s

', $class, $message); - } - } /** @@ -268,7 +267,7 @@ public function wcwp_get_company_address() */ private function wcwp_get_customer_address_part($order_meta, $suffix, $prefix = null) { - if (!is_null($prefix)){ + if (!is_null($prefix)) { if (isset($order_meta[$prefix . $suffix]) && !empty($order_meta[$prefix . $suffix][0])) { return $order_meta[$prefix . $suffix][0]; } @@ -408,17 +407,12 @@ public function wcwp_add_listing_actions($order) echo '
'; foreach ($listing_actions as $action => $data) { $target = ' target="_blank" '; - ?> - href=" " - class=" button tips " - style="background:#8dcc00; height:2em; width:2em; padding:3px;" - alt="" data-tip=""> - <?php echo $data['title']; ?> +?> + href=" " class=" button tips " style="background:#8dcc00; height:2em; width:2em; padding:3px;" alt="" data-tip=""> + <?php echo $data['title']; ?> - '; } else { @@ -431,17 +425,13 @@ class=" button tips " ); foreach ($listing_actions as $action => $data) { - ?> - - <?php echo $data['alt']; ?> + ?> + + <?php echo $data['alt']; ?> - wcwp_webhook(); exit; } - }, 20 ); - if ( version_compare( WOOCOMMERCE_VERSION, '3.7', '>=' )) { - add_action( 'wp_loaded', array(WC_Wuunder_Settings::class, 'wcwp_save_action_for_update_settings' ) ); + }, 20); + if (version_compare(WOOCOMMERCE_VERSION, '3.7', '>=')) { + add_action('wp_loaded', array(WC_Wuunder_Settings::class, 'wcwp_save_action_for_update_settings')); } - add_action('plugins_loaded', array( &$this, 'wcwp_load_textdomain' ) ); + add_action('plugins_loaded', array(&$this, 'wcwp_load_textdomain')); } - public function wcwp_load_textdomain() { + public function wcwp_load_textdomain() + { $domain = 'woocommerce-wuunder'; - load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); + load_plugin_textdomain($domain, FALSE, basename(dirname(__FILE__)) . '/languages/'); } - public function wcwp_webhook() { - if ( !isset($_REQUEST['order'] ) || !isset( $_REQUEST['token'] ) ) { - wp_redirect( '', 500 ); + public function wcwp_webhook() + { + if (!isset($_REQUEST['order']) || !isset($_REQUEST['token'])) { + wp_redirect('', 500); return; } $orderId = sanitize_text_field($_REQUEST['order']); $bookingToken = sanitize_text_field($_REQUEST['token']); - wcwp_log( 'info', 'Test webhook' ); - wcwp_log( 'info', $orderId ); - wcwp_log( 'info', $bookingToken ); + wcwp_log('info', 'Test webhook'); + wcwp_log('info', $orderId); + wcwp_log('info', $bookingToken); - $data = json_decode(file_get_contents( 'php://input' ), true ); + $data = json_decode(file_get_contents('php://input'), true); $errorRedirect = true; - $orderBookingToken = get_post_meta( $orderId, '_wuunder_label_booking_token' )[0]; - if ( 'shipment_booked' === $data['action'] ) { - if ( $orderBookingToken === $bookingToken ) { - if ( ! empty( $data['shipment']['id'] ) || ! empty($data['shipment']['track_and_trace_url']) || ! empty( $data['shipment']['label_url'] ) ) { - update_post_meta( $orderId, '_wuunder_label_id', $data['shipment']['id'] ); - update_post_meta( $orderId, '_wuunder_track_and_trace_url', $data['shipment']['track_and_trace_url'] ); - update_post_meta( $orderId, '_wuunder_label_url', $data['shipment']['label_url'] ); + $orderBookingToken = get_post_meta($orderId, '_wuunder_label_booking_token')[0]; + if ('shipment_booked' === $data['action']) { + if ($orderBookingToken === $bookingToken) { + if (!empty($data['shipment']['id']) || !empty($data['shipment']['track_and_trace_url']) || !empty($data['shipment']['label_url'])) { + update_post_meta($orderId, '_wuunder_label_id', $data['shipment']['id']); + update_post_meta($orderId, '_wuunder_track_and_trace_url', $data['shipment']['track_and_trace_url']); + update_post_meta($orderId, '_wuunder_label_url', $data['shipment']['label_url']); - $order = new WC_Order( $orderId ); - $order->update_status( get_option( 'wc_wuunder_post_booking_status' ) ); + $order = new WC_Order($orderId); + $order->update_status(get_option('wc_wuunder_post_booking_status')); $errorRedirect = false; } } - } elseif ( 'track_and_trace_updated' === $data['action'] ) { + } elseif ('track_and_trace_updated' === $data['action']) { // This is the 2nd webhook - $order = wc_get_order( $orderId ); + $order = wc_get_order($orderId); if ($order) { - $note = __( 'Het pakket is aangemeld bij: ' . $data['carrier_name'] . '\n De track and trace code is: ' . $data['track_and_trace_code'] ); - $order->add_order_note( $note ); + $note = __('Het pakket is aangemeld bij: ' . $data['carrier_name'] . '\n De track and trace code is: ' . $data['track_and_trace_code']); + $order->add_order_note($note); $order->save(); $errorRedirect = false; } else { - wcwp_log( 'error', 'T&T webhook for unknown order with id: ' . $orderId ); + wcwp_log('error', 'T&T webhook for unknown order with id: ' . $orderId); } } - if ( $errorRedirect ) { - wp_redirect('', 500 ); + if ($errorRedirect) { + wp_redirect('', 500); } } - } }