-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAYOSWXP-158: Remove 'v2' from name and description and add it to 'di…
…stinguishableName' via subscriber
- Loading branch information
1 parent
0de124c
commit b8b7746
Showing
4 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/EventListener/PaymentDistinguishableNameEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters