vendor/shopware/core/System/SalesChannel/Subscriber/SalesChannelTypeValidator.php line 25

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\SalesChannel\Subscriber;
  3. use Shopware\Core\Defaults;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Write\Command\DeleteCommand;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Write\Validation\PreWriteValidationEvent;
  6. use Shopware\Core\Framework\Uuid\Uuid;
  7. use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelType\SalesChannelTypeDefinition;
  8. use Shopware\Core\System\SalesChannel\Exception\DefaultSalesChannelTypeCannotBeDeleted;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  12.  */
  13. class SalesChannelTypeValidator implements EventSubscriberInterface
  14. {
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             PreWriteValidationEvent::class => 'preWriteValidateEvent',
  19.         ];
  20.     }
  21.     public function preWriteValidateEvent(PreWriteValidationEvent $event): void
  22.     {
  23.         foreach ($event->getCommands() as $command) {
  24.             if (!$command instanceof DeleteCommand || !$command->getDefinition() instanceof SalesChannelTypeDefinition) {
  25.                 continue;
  26.             }
  27.             $id Uuid::fromBytesToHex($command->getPrimaryKey()['id']);
  28.             if (\in_array($id, [Defaults::SALES_CHANNEL_TYPE_APIDefaults::SALES_CHANNEL_TYPE_STOREFRONTDefaults::SALES_CHANNEL_TYPE_PRODUCT_COMPARISON], true)) {
  29.                 $event->getExceptions()->add(new DefaultSalesChannelTypeCannotBeDeleted($id));
  30.             }
  31.         }
  32.     }
  33. }