Skip to content

Commit

Permalink
Merge pull request #28 from wuunder/development
Browse files Browse the repository at this point in the history
Adding preferred_service_level to rest api
  • Loading branch information
timoj authored Sep 30, 2019
2 parents 853c3c9 + 1def63f commit 6629e5f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Released

## [2.7.4](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.4) - 2019-09-27

### Added
- Preferred_service_level to Woocommerce REST API Orders resourcelist

## [2.7.3](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.3) - 2019-09-25

### Fix
Expand Down
41 changes: 41 additions & 0 deletions includes/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ function wcwp_parcelshop_html()
EOT;
}

/**
* Returns the filter (preferred service level) that is set in the Wuunder config
*
* @param $shipping_method
* @return
*/
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' );
} 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 ) {
Expand All @@ -71,6 +94,24 @@ function wcwp_add_parcelshop_id_field($checkout ) {
), $checkout->get_value( 'parcelshop_country' ) );
}

/*
* Add a referanse field to the Order API response.
*/
function prefix_wc_rest_prepare_order_object( $response, $object, $request ) {
$shipping_method_id = null;
try {
$order = new WC_Order($object->get_id());
$shipping_object = $order->get_items('shipping');
$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;

return $response;
}
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'prefix_wc_rest_prepare_order_object', 10, 3 );

// Save / Send the parcelshop id
add_action( 'woocommerce_checkout_update_order_meta', 'wcwp_update_parcelshop_id' );
function wcwp_update_parcelshop_id( $order_id ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/wcwuunder-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct() {
$this->version_obj = array(
'product' => 'Woocommerce extension',
'version' => array(
'build' => '2.7.3',
'build' => '2.7.4',
'plugin' => '2.0' ),
'platform' => array(
'name' => 'Woocommerce',
Expand Down Expand Up @@ -486,7 +486,7 @@ public function wcwp_add_meta_boxes() {
add_meta_box(
'wpo_wcpdf-box',
__( 'Wuunder', 'woocommerce-wuunder' ),
array( $this, 'sidebar_box_content' ),
array( $this, 'wcwp_sidebar_box_content' ),
'shop_order',
'side',
'default'
Expand Down
4 changes: 2 additions & 2 deletions woocommerce-wuunder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Wuunder
* Plugin URI: https://wearewuunder.com/wuunder-voor-webshops/
* Description: Wuunder shipping plugin
* Version: 2.7.3
* Version: 2.7.4
* Author: Wuunder
* Author URI: http://wearewuunder.com
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ class Woocommerce_Wuunder {
public static $plugin_path;
public static $plugin_basename;

const VERSION = '2.7.3';
const VERSION = '2.7.4';

public function __construct() {

Expand Down

0 comments on commit 6629e5f

Please sign in to comment.