Skip to content

Commit

Permalink
NTR: fix translation problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Feb 29, 2024
1 parent 8317847 commit d17aee2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Api/PluginConfig/ConfigControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
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 d17aee2

Please sign in to comment.