Skip to content

Commit

Permalink
NTR: Fix #704 (#718)
Browse files Browse the repository at this point in the history
* NTR: Fix #704

* NTR: check subscription with custom routes

* NTR: fix translation problem

---------

Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Feb 29, 2024
1 parent 89dd84e commit cfb4830
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 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", methods={"POST"})
* @return JsonResponse
*/
public function getSubscriptionConfig(): 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,6 +88,7 @@ systemConfig.getValues('MolliePayments').then(config => {
defaultSearchConfiguration,
});

}).finally(()=>{
// Now tell Shopware it's okay to load the administration
resolve();
});
18 changes: 17 additions & 1 deletion src/Service/PaymentMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -193,6 +203,11 @@ public function addPaymentMethods(array $paymentMethods, Context $context): void
'description' => '',
'mediaId' => $mediaId,
'afterOrderEnabled' => true,
'translations'=>[
Defaults::LANGUAGE_SYSTEM=>[
'name' => $paymentMethod['description']
]
]
];
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cfb4830

Please sign in to comment.