diff --git a/src/EventListener/SendEmailWithGiftCardToCustomerSubscriber.php b/src/EventListener/SendEmailWithGiftCardToCustomerSubscriber.php
index 140a395d..18a3fae3 100644
--- a/src/EventListener/SendEmailWithGiftCardToCustomerSubscriber.php
+++ b/src/EventListener/SendEmailWithGiftCardToCustomerSubscriber.php
@@ -42,6 +42,10 @@ public function postCreate(ResourceControllerEvent $event): void
return;
}
+ if (!$giftCard->getSendNotificationEmail()) {
+ return;
+ }
+
$this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($customer, $giftCard);
}
}
diff --git a/src/Form/Type/GiftCardType.php b/src/Form/Type/GiftCardType.php
index cb16d7b1..78a259ee 100644
--- a/src/Form/Type/GiftCardType.php
+++ b/src/Form/Type/GiftCardType.php
@@ -41,55 +41,68 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options): void
{
- $builder
- ->addEventSubscriber(new AddCodeFormSubscriber())
- ->add('customer', CustomerAutocompleteChoiceType::class, [
- 'label' => 'sylius.ui.customer',
- ])
- ->add('amount', NumberType::class, [
- 'label' => 'sylius.ui.amount',
- ])
- ->add('enabled', CheckboxType::class, [
- 'label' => 'sylius.ui.enabled',
- 'required' => false,
- ])
- ->add('customMessage', TextareaType::class, [
- 'label' => 'setono_sylius_gift_card.form.gift_card.custom_message',
+ $builder->addEventSubscriber(new AddCodeFormSubscriber());
+ $builder->add('customer', CustomerAutocompleteChoiceType::class, [
+ 'label' => 'sylius.ui.customer',
+ ]);
+ $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
+ /** @var GiftCardInterface $giftCard */
+ $giftCard = $event->getData();
+
+ // We only add the notification input if the gift card is new
+ if (null !== $giftCard->getId()) {
+ return;
+ }
+
+ $form = $event->getForm();
+ $form->add('sendNotificationEmail', CheckboxType::class, [
'required' => false,
- 'attr' => [
- 'placeholder' => 'setono_sylius_gift_card.form.gift_card.custom_message_placeholder',
- ],
- ])
- ->add('expiresAt', DateTimeType::class, [
- 'label' => 'setono_sylius_gift_card.form.gift_card.expires_at',
- 'widget' => 'single_text',
- 'html5' => true,
- ])
- ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
- /** @var GiftCardInterface $giftCard */
- $giftCard = $event->getData();
-
- if ($giftCard->getCode() === null) {
- $giftCard->setCode($this->giftCardCodeGenerator->generate());
- }
-
- /** @var ChannelInterface $channel */
- $channel = $giftCard->getChannel();
-
- /** @var CurrencyInterface $currency */
- $currency = $channel->getBaseCurrency();
-
- $form = $event->getForm();
- $form
- ->add('currencyCode', ChoiceType::class, [
- 'label' => 'sylius.ui.currency',
- 'choices' => $this->currencyRepository->findAll(),
- 'choice_label' => 'code',
- 'choice_value' => 'code',
- 'preferred_choices' => [$currency->getCode()],
- ]);
- })
- ;
+ 'label' => 'setono_sylius_gift_card.form.gift_card.send_notification_email',
+ ]);
+ });
+ $builder->add('amount', NumberType::class, [
+ 'label' => 'sylius.ui.amount',
+ ]);
+ $builder->add('enabled', CheckboxType::class, [
+ 'label' => 'sylius.ui.enabled',
+ 'required' => false,
+ ]);
+ $builder->add('customMessage', TextareaType::class, [
+ 'label' => 'setono_sylius_gift_card.form.gift_card.custom_message',
+ 'required' => false,
+ 'attr' => [
+ 'placeholder' => 'setono_sylius_gift_card.form.gift_card.custom_message_placeholder',
+ ],
+ ]);
+ $builder->add('expiresAt', DateTimeType::class, [
+ 'label' => 'setono_sylius_gift_card.form.gift_card.expires_at',
+ 'widget' => 'single_text',
+ 'html5' => true,
+ ]);
+ $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
+ /** @var GiftCardInterface $giftCard */
+ $giftCard = $event->getData();
+
+ if ($giftCard->getCode() === null) {
+ $giftCard->setCode($this->giftCardCodeGenerator->generate());
+ }
+
+ /** @var ChannelInterface $channel */
+ $channel = $giftCard->getChannel();
+
+ /** @var CurrencyInterface $currency */
+ $currency = $channel->getBaseCurrency();
+
+ $form = $event->getForm();
+ $form
+ ->add('currencyCode', ChoiceType::class, [
+ 'label' => 'sylius.ui.currency',
+ 'choices' => $this->currencyRepository->findAll(),
+ 'choice_label' => 'code',
+ 'choice_value' => 'code',
+ 'preferred_choices' => [$currency->getCode()],
+ ]);
+ });
$builder->get('amount')->addModelTransformer(new CallbackTransformer(static function (?int $amount): ?float {
if (null === $amount) {
diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php
index c8f02e1f..9c6b5600 100644
--- a/src/Model/GiftCard.php
+++ b/src/Model/GiftCard.php
@@ -49,6 +49,8 @@ class GiftCard implements GiftCardInterface
protected ?DateTimeInterface $expiresAt = null;
+ protected bool $sendNotificationEmail = true;
+
public function __construct()
{
$this->appliedOrders = new ArrayCollection();
@@ -296,4 +298,14 @@ public function isExpired(DateTimeInterface $date = null): bool
return $date > $giftCardValidUntil;
}
+
+ public function getSendNotificationEmail(): bool
+ {
+ return $this->sendNotificationEmail;
+ }
+
+ public function setSendNotificationEmail(bool $sendNotificationEmail = true): void
+ {
+ $this->sendNotificationEmail = $sendNotificationEmail;
+ }
}
diff --git a/src/Model/GiftCardInterface.php b/src/Model/GiftCardInterface.php
index 2cd52965..40911a1f 100644
--- a/src/Model/GiftCardInterface.php
+++ b/src/Model/GiftCardInterface.php
@@ -127,4 +127,8 @@ public function getExpiresAt(): ?\DateTimeInterface;
public function setExpiresAt(?\DateTimeInterface $expiresAt): void;
public function isExpired(\DateTimeInterface $date = null): bool;
+
+ public function getSendNotificationEmail(): bool;
+
+ public function setSendNotificationEmail(bool $sendNotificationEmail = true): void;
}
diff --git a/src/Resources/config/app/config.yaml b/src/Resources/config/app/config.yaml
index 0cc44f08..7d55f54c 100644
--- a/src/Resources/config/app/config.yaml
+++ b/src/Resources/config/app/config.yaml
@@ -33,3 +33,7 @@ sylius_ui:
setono_sylius_gift_card.admin.gift_card_configuration.update.javascripts:
blocks:
live_pdf_rendering_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/Update/_javascripts.html.twig'
+
+ setono_sylius_gift_card.admin.gift_card.create.javascripts:
+ blocks:
+ send_customer_email_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Create/_javascripts.html.twig'
diff --git a/src/Resources/config/validation/GiftCard.xml b/src/Resources/config/validation/GiftCard.xml
index 2a7acc72..aae70712 100644
--- a/src/Resources/config/validation/GiftCard.xml
+++ b/src/Resources/config/validation/GiftCard.xml
@@ -37,5 +37,12 @@
+