From 045595aa6dd9de8012d2fbcaf7ebb4ffdcbd8dc6 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 28 Feb 2024 15:48:59 +0100 Subject: [PATCH] NTR: check subscription with custom routes --- .../Api/PluginConfig/ConfigControllerBase.php | 12 ++++++++++++ .../api/mollie-payments-config.service.js | 15 +++++++++++++++ .../src/module/mollie-payments/index.js | 19 +++++++++++-------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Controller/Api/PluginConfig/ConfigControllerBase.php b/src/Controller/Api/PluginConfig/ConfigControllerBase.php index 88a1a5a9f..8df0fb221 100644 --- a/src/Controller/Api/PluginConfig/ConfigControllerBase.php +++ b/src/Controller/Api/PluginConfig/ConfigControllerBase.php @@ -206,6 +206,18 @@ public function getRefundManagerConfigLegacy(Request $request, Context $context) return $this->getRefundManagerConfig($request, $context); } + /** + * @Route("/api/_action/mollie/config/subscription", name="api.action.mollie.config.subscription-enabled", methods={"POST"}) + * @return JsonResponse + */ + public function isSubscriptionEnabled():JsonResponse + { + $config = $this->settings->getSettings(); + return new JsonResponse([ + 'enabled' => $config->isSubscriptionsEnabled() + ]); + } + /** * @param string $snippetName * @param string $locale diff --git a/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js b/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js index f11017177..946037192 100644 --- a/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js +++ b/src/Resources/app/administration/src/core/service/api/mollie-payments-config.service.js @@ -56,6 +56,21 @@ export default class MolliePaymentsConfigService extends ApiService { }); } + getSubscriptionConfig(){ + return this.httpClient + .post( + `_action/${this.getApiBasePath()}/config/subscription`, + { + locale: this.currentLocale, + }, + { + headers: this.getBasicHeaders(), + } + ).then((response) => { + return ApiService.handleResponse(response); + }); + } + /** * * @param salesChannelId diff --git a/src/Resources/app/administration/src/module/mollie-payments/index.js b/src/Resources/app/administration/src/module/mollie-payments/index.js index 3ba8a0af7..b543d1de5 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/index.js +++ b/src/Resources/app/administration/src/module/mollie-payments/index.js @@ -19,19 +19,24 @@ import './page/mollie-subscriptions-detail'; import defaultSearchConfiguration from './default-search-configuration'; + // eslint-disable-next-line no-undef -const {Module, ApiService, Plugin} = Shopware; +const {Module, Plugin,Service} = Shopware; // Tell Shopware to wait loading until we call resolve. const resolve = Plugin.addBootPromise(); -// Because we first have to load our config from the database -const systemConfig = ApiService.getByName('systemConfigApiService') -systemConfig.getValues('MolliePayments').then(config => { +/** + * + * @type {MolliePaymentsConfigService} + */ +const configService = Service('MolliePaymentsConfigService'); +// Because we first have to check if subscription is enabled or not +configService.getSubscriptionConfig().then(result => { const navigation = []; - if (config['MolliePayments.config.subscriptionsEnabled']) { + if (result.enabled === true) { navigation.push({ id: 'mollie-subscriptions', label: 'mollie-payments.subscriptions.navigation.title', @@ -83,9 +88,7 @@ systemConfig.getValues('MolliePayments').then(config => { defaultSearchConfiguration, }); -}).catch((error) => { - //here we might get an error because the user dont have the permissions to read system config, we ignore it and dont show mollie plugin at all -}).finally(() => { +}).finally(()=>{ // Now tell Shopware it's okay to load the administration resolve(); });