public function unSubscribe($email, $hash, LanguageInterface $language = null, $reason = null)
    {
        if (!$this->validateEmail($email)) {
            throw new NewsletterCannotBeRemovedException();
        }

        $conditions = [
            'email' => $email,
            'hash' => $hash,
        ];

        if ($language instanceof LanguageInterface) {
            $conditions['language'] = $language;
        }

        $newsletterSubscription = $this
            ->newsletterSubscriptionRepository
            ->findOneBy($conditions);

        if (!($newsletterSubscription instanceof NewsletterSubscriptionInterface)) {
            throw new NewsletterCannotBeRemovedException();
        }

        $newsletterSubscription
            ->setEnabled(false)
            ->setReason($reason);

        $this
            ->newsletterEventDispatcher
            ->dispatchUnsubscribeEvent($newsletterSubscription);

        return $this;
    }
public function unSubscribe($email, $hash, LanguageInterface $language = null, $reason = null)
    {
        if (!$this->validateEmail($email)) {
            throw new NewsletterCannotBeRemovedException();
        }

        $conditions = [
            'email' => $email,
            'hash' => $hash,
        ];

        if ($language instanceof LanguageInterface) {
            $conditions['language'] = $language;
        }

        $newsletterSubscription = $this
            ->newsletterSubscriptionRepository
            ->findOneBy($conditions);

        if (!($newsletterSubscription instanceof NewsletterSubscriptionInterface)) {
            throw new NewsletterCannotBeRemovedException();
        }

        $newsletterSubscription
            ->setEnabled(false)
            ->setReason($reason);

        $this
            ->newsletterEventDispatcher
            ->dispatchUnsubscribeEvent($newsletterSubscription);

        return $this;
    }
public function unSubscribe ( $ email , $ hash , LanguageInterface $ language = null , $ reason = null ) { if ( ! $ this -> validateEmail ( $ email ) ) { throw new NewsletterCannotBeRemovedException ( ) ; } $ conditions = [ 'email' => $ email , 'hash' => $ hash , ] ; if ( $ language instanceof LanguageInterface ) { $ conditions [ 'language' ] = $ language ; } $ newsletterSubscription = $ this -> newsletterSubscriptionRepository -> findOneBy ( $ conditions ) ; if ( ! ( $ newsletterSubscription instanceof NewsletterSubscriptionInterface ) ) { throw new NewsletterCannotBeRemovedException ( ) ; } $ newsletterSubscription -> setEnabled ( false ) -> setReason ( $ reason ) ; $ this -> newsletterEventDispatcher -> dispatchUnsubscribeEvent ( $ newsletterSubscription ) ; return $ this ; }
Unsubscribe email from newsletter.

@param string            $email    Email
@param string            $hash     Hash to remove
@param LanguageInterface $language Language
@param string            $reason   reason if it exists

@return $this

@throws NewsletterCannotBeRemovedException
Unsubscribe email from newsletter .