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

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. class SalesChannelTypeValidator implements EventSubscriberInterface
  11. {
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             PreWriteValidationEvent::class => 'preWriteValidateEvent',
  16.         ];
  17.     }
  18.     public function preWriteValidateEvent(PreWriteValidationEvent $event): void
  19.     {
  20.         foreach ($event->getCommands() as $command) {
  21.             if (!$command instanceof DeleteCommand || !$command->getDefinition() instanceof SalesChannelTypeDefinition) {
  22.                 continue;
  23.             }
  24.             $id Uuid::fromBytesToHex($command->getPrimaryKey()['id']);
  25.             if (\in_array($id, [Defaults::SALES_CHANNEL_TYPE_APIDefaults::SALES_CHANNEL_TYPE_STOREFRONTDefaults::SALES_CHANNEL_TYPE_PRODUCT_COMPARISON], true)) {
  26.                 $event->getExceptions()->add(new DefaultSalesChannelTypeCannotBeDeleted($id));
  27.             }
  28.         }
  29.     }
  30. }