From b0c2a4f78cc18a870cd2b1f43fa2ea0e14994203 Mon Sep 17 00:00:00 2001 From: jkindly Date: Wed, 25 Sep 2024 08:59:56 +0200 Subject: [PATCH] OP-547: Fix for error during registration when agreements are empty --- src/EventSubscriber/UserRegistrationAgreementSubscriber.php | 3 +++ .../bundles/SyliusShopBundle/Register/_form.html.twig | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/EventSubscriber/UserRegistrationAgreementSubscriber.php b/src/EventSubscriber/UserRegistrationAgreementSubscriber.php index b957a90..628f73f 100644 --- a/src/EventSubscriber/UserRegistrationAgreementSubscriber.php +++ b/src/EventSubscriber/UserRegistrationAgreementSubscriber.php @@ -49,6 +49,9 @@ public function processAgreementsFromUserRegister(ResourceControllerEvent $resou /** @var Collection $userAgreements */ $userAgreements = $customer->getAgreements(); + if ($userAgreements->isEmpty()) { + return; + } $context = $userAgreements->first()->getContexts()[0]; diff --git a/tests/Application/templates/bundles/SyliusShopBundle/Register/_form.html.twig b/tests/Application/templates/bundles/SyliusShopBundle/Register/_form.html.twig index d576a54..02b0ce6 100644 --- a/tests/Application/templates/bundles/SyliusShopBundle/Register/_form.html.twig +++ b/tests/Application/templates/bundles/SyliusShopBundle/Register/_form.html.twig @@ -10,7 +10,7 @@ {{ form_row(form.user.plainPassword.first, sylius_test_form_attribute('password-first')) }} {{ form_row(form.user.plainPassword.second, sylius_test_form_attribute('password-second')) }} -{% if form.agreements is defined %} +{% if form.agreements is defined and form.agreements is not empty %}

{{ 'bitbag_sylius_agreement_plugin.ui.agreements'|trans }}

{% for agreement in form.agreements %}