From 6ba28ba5678a71aefc284352bacab5ee324a591f Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 28 Feb 2024 14:30:33 +0100 Subject: [PATCH 1/3] NTR: Fix #704 --- .../app/administration/src/module/mollie-payments/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 0fad54643..3ba8a0af7 100644 --- a/src/Resources/app/administration/src/module/mollie-payments/index.js +++ b/src/Resources/app/administration/src/module/mollie-payments/index.js @@ -31,7 +31,7 @@ systemConfig.getValues('MolliePayments').then(config => { const navigation = []; - if(config['MolliePayments.config.subscriptionsEnabled']) { + if (config['MolliePayments.config.subscriptionsEnabled']) { navigation.push({ id: 'mollie-subscriptions', label: 'mollie-payments.subscriptions.navigation.title', @@ -83,6 +83,9 @@ 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(() => { // Now tell Shopware it's okay to load the administration resolve(); }); From 831784755d20c029f2c83e040d34bb3db85e311a Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 28 Feb 2024 15:48:59 +0100 Subject: [PATCH 2/3] 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..433f91e1a 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(); }); From d17aee25e69ace0ad75d3345ce67399a17dffeca Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 28 Feb 2024 15:55:18 +0100 Subject: [PATCH 3/3] NTR: fix translation problem --- .../Api/PluginConfig/ConfigControllerBase.php | 4 ++-- src/Service/PaymentMethodService.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Controller/Api/PluginConfig/ConfigControllerBase.php b/src/Controller/Api/PluginConfig/ConfigControllerBase.php index 8df0fb221..a3b65a153 100644 --- a/src/Controller/Api/PluginConfig/ConfigControllerBase.php +++ b/src/Controller/Api/PluginConfig/ConfigControllerBase.php @@ -207,10 +207,10 @@ public function getRefundManagerConfigLegacy(Request $request, Context $context) } /** - * @Route("/api/_action/mollie/config/subscription", name="api.action.mollie.config.subscription-enabled", methods={"POST"}) + * @Route("/api/_action/mollie/config/subscription", name="api.action.mollie.config.subscription", methods={"POST"}) * @return JsonResponse */ - public function isSubscriptionEnabled():JsonResponse + public function getSubscriptionConfig(): JsonResponse { $config = $this->settings->getSettings(); return new JsonResponse([ diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index 5d9c1e85d..446d4d703 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -37,6 +37,7 @@ use Shopware\Core\Checkout\Payment\PaymentMethodEntity; use Shopware\Core\Content\Media\MediaCollection; use Shopware\Core\Content\Media\MediaService; +use Shopware\Core\Defaults; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent; use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException; @@ -175,8 +176,17 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void # unfortunately some fields are required (*sigh) # so we need to provide those with the value of # the existing method!!! - 'name' => $existingPaymentMethod->getName(), + 'name' => $existingPaymentMethod->getName() ]; + $translations = $existingPaymentMethod->getTranslations(); + + if ($translations !== null) { + foreach ($translations as $translation) { + $paymentMethodData['translations'][$translation->getLanguageId()]=[ + 'name' => $translation->getName() + ]; + } + } if ($this->versionCompare->gte('6.5.7.0')) { # we do a string cast here, since getTechnicalName will be not nullable in the future @@ -193,6 +203,11 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void 'description' => '', 'mediaId' => $mediaId, 'afterOrderEnabled' => true, + 'translations'=>[ + Defaults::LANGUAGE_SYSTEM=>[ + 'name' => $paymentMethod['description'] + ] + ] ]; } @@ -377,6 +392,7 @@ private function getPaymentMethod($handlerIdentifier, Context $context): ?Paymen // Fetch ID for update $paymentCriteria = new Criteria(); $paymentCriteria->addFilter(new EqualsFilter('handlerIdentifier', $handlerIdentifier)); + $paymentCriteria->addAssociation('translations'); // Get payment IDs $paymentMethods = $this->paymentRepository->search($paymentCriteria, $context);