Skip to content

Commit

Permalink
NTR: check subscription with custom routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Feb 28, 2024
1 parent 6ba28ba commit 045595a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/Controller/Api/PluginConfig/ConfigControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
});

0 comments on commit 045595a

Please sign in to comment.