From 4405c722f41086f0d68245dca42f4893f8722355 Mon Sep 17 00:00:00 2001 From: henrik-ecomatic Date: Wed, 19 Jun 2019 17:27:50 +0200 Subject: [PATCH 1/4] WPM-19 [BUGFIX] added city and street to session and customer in update ajax call from checkout --- .../class-billmate-checkout.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/woocommerce-gateway-billmate/class-billmate-checkout.php b/woocommerce-gateway-billmate/class-billmate-checkout.php index 7a7647db..9f4e0540 100644 --- a/woocommerce-gateway-billmate/class-billmate-checkout.php +++ b/woocommerce-gateway-billmate/class-billmate-checkout.php @@ -508,12 +508,20 @@ function billmate_update_address(){ WC()->customer->set_shipping_country( $shipping_address['country'] ); WC()->customer->set_billing_postcode( $billing_address['postcode'] ); WC()->customer->set_shipping_postcode( $shipping_address['postcode'] ); + WC()->customer->set_billing_city( $billing_address['city'] ); + WC()->customer->set_shipping_city( $shipping_address['city'] ); + WC()->customer->set_billing_address_1( $billing_address['address_1'] ); + WC()->customer->set_shipping_address_1( $shipping_address['address_1'] ); WC()->customer->save(); WC()->session->set('billmate_checkout_billing_country', $billing_address['country']); - WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']); WC()->session->set('billmate_checkout_shipping_country', $shipping_address['country']); + WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']); WC()->session->set('billmate_checkout_shipping_postcode', $shipping_address['postcode']); + WC()->session->set('billmate_checkout_billing_city', $billing_address['city']); + WC()->session->set('billmate_checkout_shipping_city', $shipping_address['city']); + WC()->session->set('billmate_checkout_billing_address_1', $billing_address['address_1']); + WC()->session->set('billmate_checkout_shipping_address_1', $shipping_address['address_1']); WC()->cart->calculate_shipping(); From b26cc09a013ec13cb535b00c4189d077fcc3d2e0 Mon Sep 17 00:00:00 2001 From: henrik-ecomatic Date: Thu, 4 Jul 2019 08:43:46 +0200 Subject: [PATCH 2/4] WPM-19 [BUGFIX] update address call now returns updated cart html which is replacing the previous cart section --- woocommerce-gateway-billmate/class-billmate-checkout.php | 3 ++- woocommerce-gateway-billmate/js/billmatecheckout.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/woocommerce-gateway-billmate/class-billmate-checkout.php b/woocommerce-gateway-billmate/class-billmate-checkout.php index 9f4e0540..1ad1b465 100644 --- a/woocommerce-gateway-billmate/class-billmate-checkout.php +++ b/woocommerce-gateway-billmate/class-billmate-checkout.php @@ -548,8 +548,9 @@ function billmate_update_address(){ $current_order_total = (int)WC_Payment_Gateway::get_order_total(); wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total)); } + $cart = do_shortcode('[woocommerce_cart]'); $current_order_total = (int)WC_Payment_Gateway::get_order_total(); - wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total)); + wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart)); } } diff --git a/woocommerce-gateway-billmate/js/billmatecheckout.js b/woocommerce-gateway-billmate/js/billmatecheckout.js index 370577ac..5ce4a1cc 100644 --- a/woocommerce-gateway-billmate/js/billmatecheckout.js +++ b/woocommerce-gateway-billmate/js/billmatecheckout.js @@ -69,6 +69,9 @@ var BillmateIframe = new function(){ } else { self.hideCheckoutLoading(); } + if (response.data.hasOwnProperty('cart')){ + document.getElementsByClassName("woocommerce")[0].innerHTML = response.data.cart; + } } }); From ff71735521cc2d19872e792adbc62ff191228aaa Mon Sep 17 00:00:00 2001 From: henrik-ecomatic Date: Fri, 19 Jul 2019 07:35:18 +0200 Subject: [PATCH 3/4] WPM-19 [BUGFIX] fixed bugs created by the solution to the original problem. shipping methods selection should now behave properly. --- .../class-billmate-checkout.php | 20 ++++++++++++++----- .../commonfunctions.php | 18 +++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/woocommerce-gateway-billmate/class-billmate-checkout.php b/woocommerce-gateway-billmate/class-billmate-checkout.php index 1ad1b465..f0dcff50 100644 --- a/woocommerce-gateway-billmate/class-billmate-checkout.php +++ b/woocommerce-gateway-billmate/class-billmate-checkout.php @@ -481,7 +481,7 @@ function billmate_update_address(){ || $order_shipping_address['address_1'] != $shipping_address['address_1'] || $order_shipping_address['address_2'] != $shipping_address['address_2'] || $order_shipping_address['city'] != $shipping_address['city'] - || $order_shipping_address['postcode'] != $shipping_address['postcode'] + || $order_shipping_address['postcode'] != $shipping_address['postcode'] || true ) { $isEmail = is_email($billing_address['email']); if ($isEmail != false AND is_string($isEmail) AND $isEmail == $billing_address['email']) { @@ -503,7 +503,6 @@ function billmate_update_address(){ $order->set_address($shipping_address, 'shipping'); } } - WC()->customer->set_billing_country( $billing_address['country'] ); WC()->customer->set_shipping_country( $shipping_address['country'] ); WC()->customer->set_billing_postcode( $billing_address['postcode'] ); @@ -512,7 +511,12 @@ function billmate_update_address(){ WC()->customer->set_shipping_city( $shipping_address['city'] ); WC()->customer->set_billing_address_1( $billing_address['address_1'] ); WC()->customer->set_shipping_address_1( $shipping_address['address_1'] ); + WC()->customer->set_billing_address( $billing_address['address_1'] ); + WC()->customer->set_shipping_address( $shipping_address['address_1'] ); WC()->customer->save(); + $chosen_shipping = WC()->session->get('billmate_checkout_saved_shipping_method'); + WC()->shipping->reset_shipping(); + WC()->session->set('chosen_shipping_methods', array( $chosen_shipping ) ); WC()->session->set('billmate_checkout_billing_country', $billing_address['country']); WC()->session->set('billmate_checkout_shipping_country', $shipping_address['country']); @@ -523,7 +527,6 @@ function billmate_update_address(){ WC()->session->set('billmate_checkout_billing_address_1', $billing_address['address_1']); WC()->session->set('billmate_checkout_shipping_address_1', $shipping_address['address_1']); - WC()->cart->calculate_shipping(); WC()->cart->calculate_fees(); WC()->cart->calculate_totals(); @@ -897,6 +900,7 @@ function get_url(){ $current_order_total = (int)WC_Payment_Gateway::get_order_total(); if ($previous_order_total != $current_order_total) { $this->updateCheckoutFromOrderId( $orderId ); + } $checkout = $billmate->getCheckout(array('PaymentData' => array('hash' => WC()->session->get( 'billmate_checkout_hash' )))); @@ -1029,6 +1033,12 @@ public function updateCheckoutFromOrderId( $orderId = null ) 'number' => $checkoutOrderNumber ); WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total()); + if (count(debug_backtrace()) < 25) { + do_action('billmate_checkout_save_shipping_method'); + } + else { + WC()->session->set('billmate_update_cart_timestamp', time()); + } return $billmate->updateCheckout($orderValues); } return array(); @@ -1039,7 +1049,7 @@ function initCheckout($orderId = null){ $billmate = $this->getBillmateConnection(); $result = $billmate->initCheckout($orderValues); - + do_action('billmate_checkout_save_shipping_method'); // Save checkout hash if(!isset($result['code']) AND isset($result['url']) AND $result['url'] != "") { $url = $result['url']; @@ -1140,7 +1150,7 @@ public function updateCheckout($result, $order) WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total()); $data = $billmate->updateCheckout($orderValues); - + do_action('billmate_checkout_save_shipping_method'); if(!isset($data['code'])){ $current_order_total = (int)WC_Payment_Gateway::get_order_total(); if($previousTotal != $orderValues['Cart']['Total']['withtax']){ diff --git a/woocommerce-gateway-billmate/commonfunctions.php b/woocommerce-gateway-billmate/commonfunctions.php index b299e709..677414c6 100644 --- a/woocommerce-gateway-billmate/commonfunctions.php +++ b/woocommerce-gateway-billmate/commonfunctions.php @@ -10,6 +10,24 @@ if (!function_exists('is_plugin_active')) { require_once(ABSPATH.'wp-admin/includes/plugin.php'); } +add_action('billmate_checkout_save_shipping_method', 'updateshipping'); +add_action('woocommerce_proceed_to_checkout', 'updatecartshipping'); + +function updatecartshipping() { + $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); + $chosen_shipping = $chosen_methods[0]; + if ($chosen_shipping !== null && is_cart() && (time() - WC()->session->get( 'billmate_update_cart_timestamp') > 5)) { + WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping); + } +} + +function updateshipping() { + $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); + $chosen_shipping = $chosen_methods[0]; + if ($chosen_shipping !== null) { + WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping); + } +} function convertToUTF8($str) { $enc = mb_detect_encoding($str); From 309dced4439ef6e5f5424afa67e6edd60e764980 Mon Sep 17 00:00:00 2001 From: henrik-ecomatic Date: Fri, 19 Jul 2019 11:07:08 +0200 Subject: [PATCH 4/4] WPM-19 [BUGFIX] when using an alternate delivery address shipping method no longer resets to first option --- woocommerce-gateway-billmate/class-billmate-checkout.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/woocommerce-gateway-billmate/class-billmate-checkout.php b/woocommerce-gateway-billmate/class-billmate-checkout.php index f0dcff50..4ad89dfe 100644 --- a/woocommerce-gateway-billmate/class-billmate-checkout.php +++ b/woocommerce-gateway-billmate/class-billmate-checkout.php @@ -481,7 +481,7 @@ function billmate_update_address(){ || $order_shipping_address['address_1'] != $shipping_address['address_1'] || $order_shipping_address['address_2'] != $shipping_address['address_2'] || $order_shipping_address['city'] != $shipping_address['city'] - || $order_shipping_address['postcode'] != $shipping_address['postcode'] || true + || $order_shipping_address['postcode'] != $shipping_address['postcode'] ) { $isEmail = is_email($billing_address['email']); if ($isEmail != false AND is_string($isEmail) AND $isEmail == $billing_address['email']) { @@ -517,7 +517,6 @@ function billmate_update_address(){ $chosen_shipping = WC()->session->get('billmate_checkout_saved_shipping_method'); WC()->shipping->reset_shipping(); WC()->session->set('chosen_shipping_methods', array( $chosen_shipping ) ); - WC()->session->set('billmate_checkout_billing_country', $billing_address['country']); WC()->session->set('billmate_checkout_shipping_country', $shipping_address['country']); WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']); @@ -548,8 +547,9 @@ function billmate_update_address(){ } } else { + $cart = do_shortcode('[woocommerce_cart]'); $current_order_total = (int)WC_Payment_Gateway::get_order_total(); - wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total)); + wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart)); } $cart = do_shortcode('[woocommerce_cart]'); $current_order_total = (int)WC_Payment_Gateway::get_order_total();