Skip to content

Commit

Permalink
PAYOSWXP-158: Remove 'v2' from name and description and add it to 'di…
Browse files Browse the repository at this point in the history
…stinguishableName' via subscriber
  • Loading branch information
momocode-de committed Dec 11, 2024
1 parent 0de124c commit b8b7746
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/DependencyInjection/listeners.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<tag name="kernel.event_subscriber"/>
</service>

<service id="PayonePayment\EventListener\PaymentDistinguishableNameEventListener">
<tag name="kernel.event_subscriber"/>
</service>

<service id="PayonePayment\EventListener\PayPalV2ExpressEventListener">
<argument key="$activePaymentMethodsLoader" type="service" id="PayonePayment\Components\Helper\ActivePaymentMethodsLoaderInterface"/>
<argument key="$configReader" type="service" id="PayonePayment\Components\ConfigReader\ConfigReaderInterface"/>
Expand Down
35 changes: 35 additions & 0 deletions src/EventListener/PaymentDistinguishableNameEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace PayonePayment\EventListener;

use PayonePayment\PaymentMethod\PayonePaypalV2;
use PayonePayment\PaymentMethod\PayonePaypalV2Express;
use Shopware\Core\Checkout\Payment\PaymentEvents;
use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class PaymentDistinguishableNameEventListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
PaymentEvents::PAYMENT_METHOD_LOADED_EVENT => 'updateDistinguishablePaymentNameForPayPalV2',
];
}

public function updateDistinguishablePaymentNameForPayPalV2(EntityLoadedEvent $event): void
{
/** @var PaymentMethodEntity $payment */
foreach ($event->getEntities() as $payment) {
// Technical name is nullable <6.7.0
$technicalName = $payment->getTechnicalName() ?? '';

if (in_array($technicalName, [PayonePaypalV2::TECHNICAL_NAME, PayonePaypalV2Express::TECHNICAL_NAME], true)) {
$distinguishableName = str_replace('PayPal', 'PayPal v2', $payment->getTranslation('distinguishableName'));
$payment->setDistinguishableName($distinguishableName);
$payment->addTranslated('distinguishableName', $distinguishableName);
}
}
}
}
12 changes: 6 additions & 6 deletions src/PaymentMethod/PayonePaypalV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ class PayonePaypalV2 extends AbstractPaymentMethod

protected string $id = self::UUID;

protected string $name = 'PAYONE PayPal v2';
protected string $name = 'PAYONE PayPal';

protected string $description = 'Pay easily and secure with PayPal v2.';
protected string $description = 'Pay easily and secure with PayPal.';

protected string $paymentHandler = PayonePaypalV2PaymentHandler::class;

protected ?string $template = null;

protected array $translations = [
'de-DE' => [
'name' => 'PAYONE PayPal v2',
'description' => 'Zahlen Sie sicher und bequem mit PayPal v2.',
'name' => 'PAYONE PayPal',
'description' => 'Zahlen Sie sicher und bequem mit PayPal.',
],
'en-GB' => [
'name' => 'PAYONE PayPal v2',
'description' => 'Pay easily and secure with PayPal v2.',
'name' => 'PAYONE PayPal',
'description' => 'Pay easily and secure with PayPal.',
],
];

Expand Down
12 changes: 6 additions & 6 deletions src/PaymentMethod/PayonePaypalV2Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ class PayonePaypalV2Express extends AbstractPaymentMethod

protected string $id = self::UUID;

protected string $name = 'PAYONE Paypal Express v2';
protected string $name = 'PAYONE Paypal Express';

protected string $description = 'Pay easily and secure with PayPal Express v2.';
protected string $description = 'Pay easily and secure with PayPal Express.';

protected string $paymentHandler = PayonePaypalV2ExpressPaymentHandler::class;

protected ?string $template = null;

protected array $translations = [
'de-DE' => [
'name' => 'PAYONE PayPal Express v2',
'description' => 'Zahlen Sie sicher und bequem mit PayPal Express v2.',
'name' => 'PAYONE PayPal Express',
'description' => 'Zahlen Sie sicher und bequem mit PayPal Express.',
],
'en-GB' => [
'name' => 'PAYONE PayPal Express v2',
'description' => 'Pay easily and secure with PayPal Express v2.',
'name' => 'PAYONE PayPal Express',
'description' => 'Pay easily and secure with PayPal Express.',
],
];

Expand Down

0 comments on commit b8b7746

Please sign in to comment.