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

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\Log\Package;
  7. use Shopware\Core\Framework\Uuid\Uuid;
  8. use Shopware\Core\System\SalesChannel\Aggregate\SalesChannelType\SalesChannelTypeDefinition;
  9. use Shopware\Core\System\SalesChannel\Exception\DefaultSalesChannelTypeCannotBeDeleted;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12.  * @deprecated tag:v6.5.0 - reason:becomes-internal - EventSubscribers will become internal in v6.5.0
  13.  */
  14. #[Package('sales-channel')]
  15. class SalesChannelTypeValidator implements EventSubscriberInterface
  16. {
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             PreWriteValidationEvent::class => 'preWriteValidateEvent',
  21.         ];
  22.     }
  23.     public function preWriteValidateEvent(PreWriteValidationEvent $event): void
  24.     {
  25.         foreach ($event->getCommands() as $command) {
  26.             if (!$command instanceof DeleteCommand || !$command->getDefinition() instanceof SalesChannelTypeDefinition) {
  27.                 continue;
  28.             }
  29.             $id Uuid::fromBytesToHex($command->getPrimaryKey()['id']);
  30.             if (\in_array($id, [Defaults::SALES_CHANNEL_TYPE_APIDefaults::SALES_CHANNEL_TYPE_STOREFRONTDefaults::SALES_CHANNEL_TYPE_PRODUCT_COMPARISON], true)) {
  31.                 $event->getExceptions()->add(new DefaultSalesChannelTypeCannotBeDeleted($id));
  32.             }
  33.         }
  34.     }
  35. }