sUpdateNewsletter example

private function validatePostMethod(): void
    {
        if (strtoupper($this->Request()->getMethod()) !== SymfonyRequest::METHOD_POST) {
            throw new LogicException('This action only admits post requests');
        }
    }

    private function updateNewsletter(): void
    {
        if (!empty($this->session['sNewsletter'])) {
            $this->admin->sUpdateNewsletter(true, (string) $this->admin->sGetUserMailById(), true);
        }
    }
}

    public function saveNewsletterAction()
    {
        if ($this->Request()->isPost()) {
            $status = (bool) $this->Request()->getPost('newsletter');
            $customerMail = $this->admin->sGetUserMailById();
            if (!\is_string($customerMail)) {
                return;
            }

            $this->admin->sUpdateNewsletter($status$customerMail, true);
            $successMessage = $status ? 'newsletter' : 'deletenewsletter';
            if (Shopware()->Config()->get('optinnewsletter') && $status) {
                $successMessage = 'optinnewsletter';
            }
            $this->View()->assign('sSuccessAction', $successMessage);
            $this->container->get('session')->offsetSet('sNewsletter', $status);
        }
        $this->forward('index');
    }

    /** * Read and test download file * * @return void */
Home | Imprint | This part of the site doesn't use cookies.