From da725c2cbc8cdf2e0b1967bbde39b77c4d9bb55e Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 1 Mar 2021 14:28:09 +0100 Subject: [PATCH 1/2] Added support for Aelia Currency Switcher --- ...multi-currency-aelia-currency-switcher.php | 68 +++++++++++++++++++ ...mazon-payments-advanced-multi-currency.php | 11 ++- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 includes/compats/class-wc-amazon-payments-advanced-multi-currency-aelia-currency-switcher.php diff --git a/includes/compats/class-wc-amazon-payments-advanced-multi-currency-aelia-currency-switcher.php b/includes/compats/class-wc-amazon-payments-advanced-multi-currency-aelia-currency-switcher.php new file mode 100644 index 00000000..dc7ecbcc --- /dev/null +++ b/includes/compats/class-wc-amazon-payments-advanced-multi-currency-aelia-currency-switcher.php @@ -0,0 +1,68 @@ +currency_switcher = $GLOBALS['woocommerce-aelia-currencyswitcher']; + add_filter( 'init', array( $this, 'remove_shortcode_currency_switcher_on_order_reference_suspended' ) ); + + parent::__construct(); + } + + + /** + * Get the selected currency from the Currency Switcher. + * + * @return string + */ + public function get_selected_currency() { + return $this->currency_switcher->get_selected_currency(); + } + + /** + * The name of this method is misleading. It should return "true" if the multi-currency + * plugin only DISPLAYS prices in multiple currencies, but the transactions occur in + * a single currency. The Aelia Currency Switcher always ensures that transactions are + * completed in the currency used to place an order, therefore this method should return + * false. + * + * @return bool + */ + public function is_front_end_compatible() { + return false; + } + + /** + * On OrderReferenceStatus === Suspended, hide currency switcher. + */ + // TODO Clarify what this method does + public function remove_shortcode_currency_switcher_on_order_reference_suspended( $value ) { + if ( $this->is_order_reference_checkout_suspended() ) { + // By Pass Multi-currency, so we don't trigger a new set_order_reference_details on process_payment + $this->bypass_currency_session(); + } + } + +} diff --git a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php index 89794afc..e18dd4b3 100644 --- a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php +++ b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php @@ -23,6 +23,9 @@ class WC_Amazon_Payments_Advanced_Multi_Currency { 'class_WC_Product_Price_Based_Country' => 'Price Based on Country for WooCommerce', 'global_woocommerce_wpml' => 'WPML WooCommerce Multilingual', 'class_WC_Currency_Converter' => 'Currency Converter Widget', + // Aelia Currency Switcher + // @author Aelia + 'class_Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' => 'Aelia Currency Switcher', ); /** @@ -68,6 +71,12 @@ public static function init( $region = null ) { require_once 'class-wc-amazon-payments-advanced-multi-currency-wccw.php'; self::$compatible_instance = new WC_Amazon_Payments_Advanced_Multi_Currency_Converted_Widget(); break; + // Aelia Currency Switcher + // @author Aelia + case 'class_Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher': + require_once 'class-wc-amazon-payments-advanced-multi-currency-aelia-currency-switcher.php'; + self::$compatible_instance = new WC_Amazon_Payments_Advanced_Multi_Currency_Aelia_Currency_Switcher(); + break; } } } @@ -87,7 +96,7 @@ public static function compatible_region( $region = null ) { /** * Singleton to get if there is a compatible instance running. Region can be injected. - * + * * @param bool $region * * @return WC_Amazon_Payments_Advanced_Multi_Currency_Abstract From 8f2c548a539a84bd60aa0d9ab13498e71ff13c96 Mon Sep 17 00:00:00 2001 From: Diego Date: Tue, 2 Mar 2021 20:40:32 +0100 Subject: [PATCH 2/2] Updated multi-currency integration * Put the Aelia Currency Switcher at the top of the list, to ensure that it's detected even when WCML is installed. --- ...s-wc-amazon-payments-advanced-multi-currency.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php index e18dd4b3..751b5e16 100644 --- a/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php +++ b/includes/compats/class-wc-amazon-payments-advanced-multi-currency.php @@ -19,13 +19,20 @@ class WC_Amazon_Payments_Advanced_Multi_Currency { * List of compatible plugins, with its global variable name or main class. */ const COMPATIBLE_PLUGINS = array( + // Aelia Currency Switcher + // + // Note + // The Aelia Currency Switcher integration must come before the WooCommerce Multilingual one. + // This is needed because this integration class stops as soon as it finds one of the supported + // plugins. If it finds the WooCommerce Multilingual, it will not look for any other, even if + // the multi-currency features in WCML are disabled. In that case, the integration with the + // Aelia Currency Switcher would not be loaded, even though the plugin is active and running. + // @author Aelia + 'class_Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' => 'Aelia Currency Switcher', 'global_WOOCS' => 'WOOCS – Currency Switcher for WooCommerce', 'class_WC_Product_Price_Based_Country' => 'Price Based on Country for WooCommerce', 'global_woocommerce_wpml' => 'WPML WooCommerce Multilingual', 'class_WC_Currency_Converter' => 'Currency Converter Widget', - // Aelia Currency Switcher - // @author Aelia - 'class_Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher' => 'Aelia Currency Switcher', ); /**