NewsletterConfirmEvent example

'confirmedAt' => $recipient->getConfirmedAt(),
            'em' => $dataBag->get('em'),
        ];

        $this->validator->validate($data$this->getBeforeConfirmSubscribeValidation(hash('sha1', $recipient->getEmail())));

        $data['status'] = NewsletterSubscribeRoute::STATUS_OPT_IN;
        $data['confirmedAt'] = new \DateTime();

        $this->newsletterRecipientRepository->update([$data]$context->getContext());

        $event = new NewsletterConfirmEvent($context->getContext()$recipient$context->getSalesChannel()->getId());
        $this->eventDispatcher->dispatch($event);

        return new NoContentResponse();
    }

    private function getNewsletterRecipient(string $identifier, string $value, Context $context): NewsletterRecipientEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter($identifier$value));
        $criteria->addAssociation('salutation');
        $criteria->setLimit(1);

        
return new NoContentResponse();
            }
        }

        $data = $this->completeData($data$context);

        $this->newsletterRecipientRepository->upsert([$data]$context->getContext());

        $recipient = $this->getNewsletterRecipient('email', $data['email']$context->getContext());

        if (!$this->isNewsletterDoi($context)) {
            $event = new NewsletterConfirmEvent($context->getContext()$recipient$context->getSalesChannel()->getId());
            $this->eventDispatcher->dispatch($event);

            return new NoContentResponse();
        }

        $hashedEmail = hash('sha1', $data['email']);
        $url = $this->getSubscribeUrl($context$hashedEmail$data['hash']$data$recipient);

        $event = new NewsletterRegisterEvent($context->getContext()$recipient$url$context->getSalesChannel()->getId());
        $this->eventDispatcher->dispatch($event);

        
Home | Imprint | This part of the site doesn't use cookies.