Skip to content

Commit

Permalink
Merge pull request #44 from wuunder/development
Browse files Browse the repository at this point in the history
Support page refresh selected parcelshop
  • Loading branch information
TimD90 authored Mar 18, 2020
2 parents aeef0cc + 7f41b8f commit 680ec3b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 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.15](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.15) - 2020-03-17

### Added
- Save selected parcelshop over page refresh

## [2.7.14](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.14) - 2020-03-06

### Added
Expand Down
24 changes: 24 additions & 0 deletions assets/js/parcelshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function initParcelshopLocator(url, apiUrl, carrierList, chooseParcelshopTxt, ch
jQuery( 'body' ).on( 'updated_checkout', function() {
_onShippingMethodChange();
});

_getSelectedParcelshopId();
}

function _onShippingMethodChange() {
Expand Down Expand Up @@ -92,6 +94,7 @@ function _openIframe() {
}

function onServicePointSelected(messageData) {
_setSelectedParcelshopId(messageData.parcelshopId);
window.parent.document.getElementById('parcelshop_id').value = messageData.parcelshopId;
_loadSelectedParcelshopAddress(messageData.parcelshopId);
removeServicePointPicker();
Expand Down Expand Up @@ -119,6 +122,27 @@ function _openIframe() {
window.addEventListener('message', onWindowMessage, false);
}

function _setSelectedParcelshopId(id) {
jQuery.post(baseUrl + "admin-ajax.php", {
action: 'wuunder_parcelshoplocator_set_selected_parcelshop',
parcelshop_id: id
}, function (data) {

});
}

function _getSelectedParcelshopId() {
jQuery.post(baseUrl + "admin-ajax.php", {
action: 'wuunder_parcelshoplocator_get_selected_parcelshop',
}, function (data) {
data = JSON.parse(data);
if (data['parcelshop_id'] !== undefined && data['parcelshop_id'] !== null) {
window.parent.document.getElementById('parcelshop_id').value = data['parcelshop_id'];
_loadSelectedParcelshopAddress(data['parcelshop_id']);
}
});
}

function _loadSelectedParcelshopAddress(id) {
jQuery.post(baseUrl + "admin-ajax.php", {
action: 'wuunder_parcelshoplocator_get_parcelshop_address',
Expand Down
1 change: 1 addition & 0 deletions includes/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ 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']));
WC()->session->__unset( 'WCWP_SELECTED_PARCELSHOP_ID' );
}
}

Expand Down
18 changes: 18 additions & 0 deletions includes/parcelshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function wcwp_getAddress() {
}

function wcwp_getParcelshopAddress() {

$shipping_address = null;
if(empty($_POST['parcelshop_id'])) {
echo null;
Expand Down Expand Up @@ -104,4 +105,21 @@ function wcwp_getParcelshopAddress() {
}

exit;
}

function wcwp_setSelectedParcelshop()
{
if (!empty($_POST['parcelshop_id'])) {
WC()->session->set('WCWP_SELECTED_PARCELSHOP_ID', $_POST['parcelshop_id']);
}
}

function wcwp_getSelectedParcelshop()
{
if (!empty(WC()->session->get( 'WCWP_SELECTED_PARCELSHOP_ID' ))) {
echo json_encode(array('parcelshop_id' => WC()->session->get( 'WCWP_SELECTED_PARCELSHOP_ID' )));
} else {
echo json_encode(array('parcelshop_id' => null));
}
wp_die();
}
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ You can best contact us via [email protected]
7. Eenvoudig labels printen

== Changelog ==
= 2.7.15 =
* Load selected parcelshop on refresh
= 2.7.14 =
* Support checkout updating from WC 3.9.x and >
= 2.7.13 =
Expand Down
8 changes: 6 additions & 2 deletions woocommerce-wuunder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Wuunder for-woocommerce
* Plugin URI: https://wearewuunder.com/wuunder-voor-webshops/
* Description: Wuunder shipping plugin
* Version: 2.7.14
* Version: 2.7.15
* 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.14';
const VERSION = '2.7.15';

public function __construct() {

Expand All @@ -76,6 +76,10 @@ public function __construct() {
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_get_parcelshop_address', 'wcwp_getParcelshopAddress');
add_action('wp_ajax_wuunder_parcelshoplocator_get_address', 'wcwp_getAddress');
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_get_address', 'wcwp_getAddress');
add_action('wp_ajax_wuunder_parcelshoplocator_set_selected_parcelshop', 'wcwp_setSelectedParcelshop');
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_set_selected_parcelshop', 'wcwp_setSelectedParcelshop');
add_action('wp_ajax_wuunder_parcelshoplocator_get_selected_parcelshop', 'wcwp_getSelectedParcelshop');
add_action('wp_ajax_nopriv_wuunder_parcelshoplocator_get_selected_parcelshop', 'wcwp_getSelectedParcelshop');

add_action( 'wp_loaded', function () {
if ( false !== strpos( $_SERVER['REQUEST_URI'], '/wuunder/webhook' ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) {
Expand Down

0 comments on commit 680ec3b

Please sign in to comment.