diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6aabe0..5e0907d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
## Released
+## [2.7.7](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.7) - 2019-10-11
+
+### Added
+- Support for value and weight via mywuunder import (REST API)
+
+
## [2.7.6](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.6) - 2019-10-07
### Added
diff --git a/includes/checkout.php b/includes/checkout.php
index b55b326..0249446 100644
--- a/includes/checkout.php
+++ b/includes/checkout.php
@@ -1,5 +1,5 @@
getStageBaseUrl(), 0, -3);
$carrierConfigList = get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] ? get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] : [];
$carrierList = implode(',', $carrierConfigList);
- if ( 0 !== strlen($carrierList) ) {
+ if (0 !== strlen($carrierList)) {
$availableCarriers = $carrierList;
} else {
$defaultCarrierConfig = get_option('default_carrier_list') ? get_option('default_carrier_list') : [];
@@ -59,45 +60,48 @@ function wcwp_parcelshop_html()
* @param $shipping_method
* @return
*/
-function wcwp_get_filter_from_shippingmethod($shipping_method ) {
- if ( false !== strpos( $shipping_method, ':' ) ) {
- $shipping_method = explode( ':', $shipping_method )[0];
+function wcwp_get_filter_from_shippingmethod($shipping_method)
+{
+ if (false !== strpos($shipping_method, ':')) {
+ $shipping_method = explode(':', $shipping_method)[0];
}
- if ( $shipping_method === get_option( 'wc_wuunder_mapping_method_1' ) ) {
- return get_option( 'wc_wuunder_mapping_filter_1' );
- } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_2' ) ) {
- return get_option( 'wc_wuunder_mapping_filter_2' );
- } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_3') ) {
- return get_option( 'wc_wuunder_mapping_filter_3' );
- } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_4' ) ) {
- return get_option( 'wc_wuunder_mapping_filter_4' );
+ if ($shipping_method === get_option('wc_wuunder_mapping_method_1')) {
+ return get_option('wc_wuunder_mapping_filter_1');
+ } elseif ($shipping_method === get_option('wc_wuunder_mapping_method_2')) {
+ return get_option('wc_wuunder_mapping_filter_2');
+ } elseif ($shipping_method === get_option('wc_wuunder_mapping_method_3')) {
+ return get_option('wc_wuunder_mapping_filter_3');
+ } elseif ($shipping_method === get_option('wc_wuunder_mapping_method_4')) {
+ return get_option('wc_wuunder_mapping_filter_4');
} else {
return '';
}
}
// Field added for the parcelshop_id, so that it can be requested from backend
-add_action( 'woocommerce_after_order_notes', 'wcwp_add_parcelshop_id_field' );
-function wcwp_add_parcelshop_id_field($checkout ) {
+add_action('woocommerce_after_order_notes', 'wcwp_add_parcelshop_id_field');
+function wcwp_add_parcelshop_id_field($checkout)
+{
woocommerce_form_field('parcelshop_id', array(
'type' => 'text',
'class' => array(
'wuunder-hidden-checkout-field form-row-wide'
),
- ), $checkout->get_value( 'parcelshop_id' ) );
+ ), $checkout->get_value('parcelshop_id'));
woocommerce_form_field('parcelshop_country', array(
'type' => 'text',
'class' => array(
'wuunder-hidden-checkout-field form-row-wide'
),
- ), $checkout->get_value( 'parcelshop_country' ) );
+ ), $checkout->get_value('parcelshop_country'));
}
/*
* Add a referanse field to the Order API response.
*/
-function prefix_wc_rest_prepare_order_object( $response, $object, $request ) {
+function prefix_wc_rest_prepare_order_object($response, $object, $request)
+{
$shipping_method_id = null;
try {
$order = new WC_Order($object->get_id());
@@ -108,40 +112,92 @@ function prefix_wc_rest_prepare_order_object( $response, $object, $request ) {
}
$response->data['wuunder_preferred_service_level'] = $shipping_method_id;
- $bookingTokenData = get_post_meta( $object->get_id(), '_wuunder_label_booking_token' );
+ $bookingTokenData = get_post_meta($object->get_id(), '_wuunder_label_booking_token');
if (count($bookingTokenData)) {
$bookingToken = $bookingTokenData[0];
} else {
$bookingToken = uniqid();
- update_post_meta( $object->get_id(), '_wuunder_label_booking_token', $bookingToken );
+ update_post_meta($object->get_id(), '_wuunder_label_booking_token', $bookingToken);
}
$response->data['wuunder_booking_token'] = $bookingToken;
+
+ $total_order_weight = wcwp_get_order_weight($object->get_id());
+ $response->data['wuunder_total_order_weight'] = $total_order_weight;
+
+
return $response;
}
-add_filter( 'woocommerce_rest_prepare_shop_order_object', 'prefix_wc_rest_prepare_order_object', 10, 3 );
+
+add_filter('woocommerce_rest_prepare_shop_order_object', 'prefix_wc_rest_prepare_order_object', 10, 3);
+
+function wcwp_get_order_weight($order_id)
+{
+ global $woocommerce;
+ $order = new WC_Order($order_id);
+ //global $_product;
+ $items = $order->get_items();
+ $total_weight = 0;
+
+ if (sizeof($items) > 0) {
+ foreach ($items as $item) {
+ // Create the product
+ $product = $order->get_product_from_item($item);
+ // Set item weight
+ $weight = $product->get_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;
+ }
+
+ $total_product_weight = $quantity * $data['weight'];
+ $total_weight += $total_product_weight;
+ }
+ }
+
+ return $total_weight;
+}
+
// Save / Send the parcelshop id
-add_action( 'woocommerce_checkout_update_order_meta', 'wcwp_update_parcelshop_id' );
-function wcwp_update_parcelshop_id( $order_id ) {
- if ( ! empty( $_POST['parcelshop_id'] ) ) {
- update_post_meta( $order_id, 'parcelshop_id', sanitize_text_field( $_POST['parcelshop_id'] ) );
+add_action('woocommerce_checkout_update_order_meta', 'wcwp_update_parcelshop_id');
+function wcwp_update_parcelshop_id($order_id)
+{
+ if (!empty($_POST['parcelshop_id'])) {
+ update_post_meta($order_id, 'parcelshop_id', sanitize_text_field($_POST['parcelshop_id']));
}
}
// Check to see if a parcelshop is selected when parcel method is selected && Check if shipping country == parcelshop country
-add_action( 'woocommerce_checkout_process', 'wcwp_check_parcelshop_selection' );
-function wcwp_check_parcelshop_selection() {
- if ( 'wuunder_parcelshop' === $_POST['shipping_method'][0] ) {
- if ( !$_POST['parcelshop_id'] ) {
- wc_add_notice( __( 'Kies eerst een parcelshop' ), 'error' );
+add_action('woocommerce_checkout_process', 'wcwp_check_parcelshop_selection');
+function wcwp_check_parcelshop_selection()
+{
+ if ('wuunder_parcelshop' === $_POST['shipping_method'][0]) {
+ if (!$_POST['parcelshop_id']) {
+ wc_add_notice(__('Kies eerst een parcelshop'), 'error');
}
- if ( $_POST['shipping_country'] != $_POST['parcelshop_country'] ) {
- wc_add_notice( __( 'Het land van de verzendgegevens moet overeenkomen met het land van de parcelshop '), 'error' );
+ if ($_POST['shipping_country'] != $_POST['parcelshop_country']) {
+ wc_add_notice(__('Het land van de verzendgegevens moet overeenkomen met het land van de parcelshop '), 'error');
}
}
}
+
?>
diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php
index 453ae9c..5ae601b 100644
--- a/includes/wcwuunder-create.php
+++ b/includes/wcwuunder-create.php
@@ -12,7 +12,7 @@ public function __construct() {
$this->version_obj = array(
'product' => 'Woocommerce extension',
'version' => array(
- 'build' => '2.7.6 ',
+ 'build' => '2.7.7 ',
'plugin' => '2.0' ),
'platform' => array(
'name' => 'Woocommerce',
diff --git a/woocommerce-wuunder.php b/woocommerce-wuunder.php
index 1d773aa..dee55d7 100644
--- a/woocommerce-wuunder.php
+++ b/woocommerce-wuunder.php
@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Wuunder
* Plugin URI: https://wearewuunder.com/wuunder-voor-webshops/
* Description: Wuunder shipping plugin
- * Version: 2.7.6
+ * Version: 2.7.7
* Author: Wuunder
* Author URI: http://wearewuunder.com
*/
@@ -57,7 +57,7 @@ class Woocommerce_Wuunder {
public static $plugin_path;
public static $plugin_basename;
- const VERSION = '2.7.6';
+ const VERSION = '2.7.7';
public function __construct() {