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

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.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             PreWriteValidationEvent::class => 'validate',
  22.         ];
  23.     }
  24.     public function validate(PreWriteValidationEvent $event): void
  25.     {
  26.         $ids $event->getDeletedPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME);
  27.         $ids \array_column($ids'id');
  28.         if (empty($ids)) {
  29.             return;
  30.         }
  31.         $pluginIds $this->connection->fetchOne(
  32.             'SELECT id FROM payment_method WHERE id IN (:ids) AND plugin_id IS NOT NULL',
  33.             ['ids' => $ids],
  34.             ['ids' => Connection::PARAM_STR_ARRAY]
  35.         );
  36.         if (!empty($pluginIds)) {
  37.             throw new PluginPaymentMethodsDeleteRestrictionException();
  38.         }
  39.     }
  40. }