#[Route(path: '/store-api/newsletter/unsubscribe', name: 'store-api.newsletter.unsubscribe', methods: ['POST'])]
public function unsubscribe(RequestDataBag
$dataBag, SalesChannelContext
$context): NoContentResponse
{ $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
{