custom/plugins/LoyxxSeminar/src/Subscriber/StorefrontRenderEventSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace LoyxxSeminar\Subscriber;
  3. use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException;
  7. use Shopware\Storefront\Event\StorefrontRenderEvent;
  8. use Shopware\Storefront\Page\Account\Order\AccountOrderPage;
  9. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPage;
  10. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPage;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class StorefrontRenderEventSubscriber implements EventSubscriberInterface
  13. {
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [
  17.             StorefrontRenderEvent::class => 'onStorefrontRenderEvent',
  18.         ];
  19.     }
  20.     public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
  21.     {
  22.         $view $event->getView();
  23.         if (strpos($view'checkout/confirm/index') === FALSE) {
  24.             return;
  25.         }
  26.         $attributes $event->getRequest()->attributes;
  27.         /** @var ConstraintViolationException $formViolations */
  28.         $formViolations $attributes->get('formViolations');
  29.         if ($formViolations === null) {
  30.             return;
  31.         }
  32.         $alreadyExistingViolationCodes = [];
  33.         foreach ($formViolations->getViolations() as $key => $violation) {
  34.             if ($violation->getPropertyPath() === "/participants") {
  35.                 if (!in_array($violation->getCode(), $alreadyExistingViolationCodestrue)) {
  36.                     $alreadyExistingViolationCodes[] = $violation->getCode();
  37.                 } else {
  38.                     $formViolations->getViolations()->remove($key);
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }