src/Core/Checkout/Payment/DataAbstractionLayer/PaymentDistinguishableNameSubscriber.php line 24

  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 Shopware\Core\Framework\Log\Package;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * @internal
  10.  */
  11. #[Package('core')]
  12. class PaymentDistinguishableNameSubscriber implements EventSubscriberInterface
  13. {
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             PaymentEvents::PAYMENT_METHOD_LOADED_EVENT => 'addDistinguishablePaymentName',
  18.         ];
  19.     }
  20.     public function addDistinguishablePaymentName(EntityLoadedEvent $event): void
  21.     {
  22.         /** @var PaymentMethodEntity $payment */
  23.         foreach ($event->getEntities() as $payment) {
  24.             if ($payment->getTranslation('distinguishableName') === null) {
  25.                 $payment->addTranslated('distinguishableName'$payment->getTranslation('name'));
  26.             }
  27.             if ($payment->getDistinguishableName() === null) {
  28.                 $payment->setDistinguishableName($payment->getName());
  29.             }
  30.         }
  31.     }
  32. }