getConfirmedAt example

throw new DecorationPatternException(self::class);
    }

    #[Route(path: '/store-api/newsletter/confirm', name: 'store-api.newsletter.confirm', methods: ['POST'])]     public function confirm(RequestDataBag $dataBag, SalesChannelContext $context): NoContentResponse
    {
        $recipient = $this->getNewsletterRecipient('hash', $dataBag->get('hash', '')$context->getContext());

        $data = [
            'id' => $recipient->getId(),
            'status' => $recipient->getStatus(),
            '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());
        
'storefrontUrl'
        );

        $recipientId = $this->getNewsletterRecipientId($data['email']$context);

        if (isset($recipientId)) {
            /** @var NewsletterRecipientEntity $recipient */
            $recipient = $this->newsletterRecipientRepository->search(new Criteria([$recipientId])$context->getContext())->first();

            // If the user was previously subscribed but has unsubscribed now, the `getConfirmedAt()`             // will still be set. So we need to check for the status as well.             if ($recipient->getStatus() !== self::STATUS_OPT_OUT && $recipient->getConfirmedAt()) {
                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)) {
            
/** @var EntityRepository $repository */
        $repository = $this->getContainer()->get('newsletter_recipient.repository');

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('email', $email));

        /** @var NewsletterRecipientEntity $result */
        $result = $repository->search($criteria, Context::createDefaultContext())->getEntities()->first();

        static::assertInstanceOf(NewsletterRecipientEntity::class$result);
        static::assertNotNull($result->getConfirmedAt());
        static::assertSame((new \DateTime())->format('y-m-d')$result->getConfirmedAt()->format('y-m-d'));
        static::assertSame('optIn', $result->getStatus());
    }

    public function testUnsubscribeNewsletterExpectsNewsletterRecipientNotFoundException(): void
    {
        $this->installTestData();
        $email = 'not@existend.email';
        $dataBag = new RequestDataBag([
            'email' => $email,
            'salutationId' => 'ad165c1faac14059832b6258ac0a7339',
            
Home | Imprint | This part of the site doesn't use cookies.