NewsletterUnsubscribeEvent example

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

        $data['id'] = $recipient->getId();
        $data['status'] = NewsletterSubscribeRoute::STATUS_OPT_OUT;

        $validator = $this->getOptOutValidation();
        $this->validator->validate($data$validator);

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

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

        return new NoContentResponse();
    }

    private function getNewsletterRecipient(string $email, SalesChannelContext $context): NewsletterRecipientEntity
    {
        $criteria = new Criteria();
        $criteria->addFilter(
            new MultiFilter(MultiFilter::CONNECTION_AND),
            new EqualsFilter('email', $email),
            
Home | Imprint | This part of the site doesn't use cookies.