vendor/shopware/core/Checkout/Payment/DataAbstractionLayer/PaymentMethodValidator.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Payment\DataAbstractionLayer;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Checkout\Payment\Exception\PluginPaymentMethodsDeleteRestrictionException;
  5. use Shopware\Core\Checkout\Payment\PaymentMethodDefinition;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Write\Validation\PreWriteValidationEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. final class PaymentMethodValidator implements EventSubscriberInterface
  9. {
  10.     private Connection $connection;
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(Connection $connection)
  15.     {
  16.         $this->connection $connection;
  17.     }
  18.     /**
  19.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  20.      */
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             PreWriteValidationEvent::class => 'validate',
  25.         ];
  26.     }
  27.     public function validate(PreWriteValidationEvent $event): void
  28.     {
  29.         $ids $event->getDeletedPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME);
  30.         $ids = \array_column($ids'id');
  31.         if (empty($ids)) {
  32.             return;
  33.         }
  34.         $pluginIds $this->connection->fetchOne(
  35.             'SELECT id FROM payment_method WHERE id IN (:ids) AND plugin_id IS NOT NULL',
  36.             ['ids' => $ids],
  37.             ['ids' => Connection::PARAM_STR_ARRAY]
  38.         );
  39.         if (!empty($pluginIds)) {
  40.             throw new PluginPaymentMethodsDeleteRestrictionException();
  41.         }
  42.     }
  43. }