Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility aelia currency switcher #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Main class to handle Aelia Currency Switcher for WooCommerce compatibility.
* Tested up to: Aelia Currency Switcher 4.9.14.210215.
*
* @package WC_Gateway_Amazon_Pay\Compats
* @link https://aelia.co/shop/currency-switcher-woocommerce/
*/

/**
* WooCommerce Aelia Currency Switcher for WooCommerce Multi-currency compatibility.
*
* @author Aelia
* @link https://aelia.co/shop/currency-switcher-woocommerce/
*/
class WC_Amazon_Payments_Advanced_Multi_Currency_Aelia_Currency_Switcher extends WC_Amazon_Payments_Advanced_Multi_Currency_Abstract {
/**
* Holds Aelia Currency Switcher instance.
*
* @var Aelia\WC\CurrencySwitcher\WC_Aelia_CurrencySwitcher
*/
protected $currency_switcher;

/**
* Specify hooks where compatibility action takes place.
*/
public function __construct() {
$this->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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ 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 <[email protected]>
'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',
Expand Down Expand Up @@ -68,6 +78,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 <[email protected]>
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;
}
}
}
Expand All @@ -87,7 +103,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
Expand Down