Skip to content

Commit

Permalink
Merge pull request #925 from plentymarkets/fix/detect_currency
Browse files Browse the repository at this point in the history
check for a valid currency
  • Loading branch information
stentrop authored Nov 30, 2020
2 parents fb87217 + 8096dfe commit 5988e34
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Middlewares/DetectCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@

class DetectCurrency extends Middleware
{
// TODO: move check to the core after 5.0.X
public static $allCurrencies = [
'AED', 'ARS', 'AUD', 'BGN', 'BHD', 'BRL',
'CAD', 'CHF', 'CNY', 'CZK', 'DKK', 'EUR',
'GBP', 'HKD', 'HRK', 'HUF', 'IDR', 'INR',
'JPY', 'MXN', 'MYR', 'NOK', 'NZD', 'PHP',
'PLN', 'QAR', 'RON', 'RUB', 'SEK', 'SGD',
'THB', 'TRY', 'TWD', 'UAH', 'USD', 'VND', 'XCD', 'ZAR'];

/**
* @param Request $request
*/
Expand All @@ -23,8 +32,7 @@ public function before(Request $request)
/** @var TemplateConfigService $templateConfigService */
$templateConfigService = pluginApp(TemplateConfigService::class);
$enabledCurrencies = explode(', ', $templateConfigService->get('currency.available_currencies'));

if (in_array($currency, $enabledCurrencies) || array_pop($enabledCurrencies) == 'all') {
if (in_array($currency, $enabledCurrencies) || (array_pop($enabledCurrencies) == 'all' && in_array(strtoupper($currency), self::$allCurrencies))) {
/** @var CheckoutService $checkoutService */
$checkoutService = pluginApp(CheckoutService::class);
$checkoutService->setCurrency($currency);
Expand Down

0 comments on commit 5988e34

Please sign in to comment.