<?php
namespace LoyxxSeminar\Subscriber;
use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Validation\Exception\ConstraintViolationException;
use Shopware\Storefront\Event\StorefrontRenderEvent;
use Shopware\Storefront\Page\Account\Order\AccountOrderPage;
use Shopware\Storefront\Page\Account\Overview\AccountOverviewPage;
use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPage;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class StorefrontRenderEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
StorefrontRenderEvent::class => 'onStorefrontRenderEvent',
];
}
public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
{
$view = $event->getView();
if (strpos($view, 'checkout/confirm/index') === FALSE) {
return;
}
$attributes = $event->getRequest()->attributes;
/** @var ConstraintViolationException $formViolations */
$formViolations = $attributes->get('formViolations');
if ($formViolations === null) {
return;
}
$alreadyExistingViolationCodes = [];
foreach ($formViolations->getViolations() as $key => $violation) {
if ($violation->getPropertyPath() === "/participants") {
if (!in_array($violation->getCode(), $alreadyExistingViolationCodes, true)) {
$alreadyExistingViolationCodes[] = $violation->getCode();
} else {
$formViolations->getViolations()->remove($key);
}
}
}
}
}