platform/src/Core/Checkout/Payment/DataAbstractionLayer/PaymentDistinguishableNameSubscriber.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\DataAbstractionLayer;
  3. use Shopware\Core\Checkout\Payment\PaymentEvents;
  4. use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class PaymentDistinguishableNameSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             PaymentEvents::PAYMENT_METHOD_LOADED_EVENT => 'addDistinguishablePaymentName',
  13.         ];
  14.     }
  15.     public function addDistinguishablePaymentName(EntityLoadedEvent $event): void
  16.     {
  17.         /** @var PaymentMethodEntity $payment */
  18.         foreach ($event->getEntities() as $payment) {
  19.             if ($payment->getTranslation('distinguishableName') === null) {
  20.                 $payment->addTranslated('distinguishableName'$payment->getTranslation('name'));
  21.             }
  22.             if ($payment->getDistinguishableName() === null) {
  23.                 $payment->setDistinguishableName($payment->getName());
  24.             }
  25.         }
  26.     }
  27. }