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

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 Shopware\Core\Framework\Log\Package;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  11.  */
  12. #[Package('core')]
  13. final class PaymentMethodValidator implements EventSubscriberInterface
  14. {
  15.     private Connection $connection;
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(Connection $connection)
  20.     {
  21.         $this->connection $connection;
  22.     }
  23.     /**
  24.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             PreWriteValidationEvent::class => 'validate',
  30.         ];
  31.     }
  32.     public function validate(PreWriteValidationEvent $event): void
  33.     {
  34.         $ids $event->getDeletedPrimaryKeys(PaymentMethodDefinition::ENTITY_NAME);
  35.         $ids = \array_column($ids'id');
  36.         if (empty($ids)) {
  37.             return;
  38.         }
  39.         $pluginIds $this->connection->fetchOne(
  40.             'SELECT id FROM payment_method WHERE id IN (:ids) AND plugin_id IS NOT NULL',
  41.             ['ids' => $ids],
  42.             ['ids' => Connection::PARAM_STR_ARRAY]
  43.         );
  44.         if (!empty($pluginIds)) {
  45.             throw new PluginPaymentMethodsDeleteRestrictionException();
  46.         }
  47.     }
  48. }