コード例 #1
0
 public function subscribeAction()
 {
     $errorMessage = false;
     $newsletterForm = $this->createForm(FrontForm::NEWSLETTER);
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         /** @var Customer $customer */
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname())->setLastname($customer->getLastname());
         } else {
             $event->setFirstname($form->get('firstname')->getData())->setLastname($form->get('lastname')->getData());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
         // If a success URL is defined in the form, redirect to it, otherwise use the defaut view
         if ($newsletterForm->hasSuccessUrl() && !$this->getRequest()->isXmlHttpRequest()) {
             return $this->generateSuccessRedirect($newsletterForm);
         }
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
         $newsletterForm->setErrorMessage($errorMessage);
     }
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         return new JsonResponse(["success" => $errorMessage ? false : true, "message" => $errorMessage ? $errorMessage : $this->getTranslator()->trans("Thanks for signing up! We'll keep you posted whenever we have any new updates.", [], Front::MESSAGE_DOMAIN)], $errorMessage ? 500 : 200);
     }
     $this->getParserContext()->setGeneralError($errorMessage)->addForm($newsletterForm);
     // If an error URL is defined in the form, redirect to it, otherwise use the defaut view
     if ($errorMessage && $newsletterForm->hasErrorUrl()) {
         return $this->generateErrorRedirect($newsletterForm);
     }
 }
コード例 #2
0
 public function subscribeAction()
 {
     $error_message = false;
     $newsletterForm = new NewsletterForm($this->getRequest());
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname());
             $event->setLastname($customer->getLastname());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
     } catch (\Exception $e) {
         $error_message = $e->getMessage();
     }
     \Thelia\Log\Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $error_message));
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         if ($error_message) {
             $response = $this->jsonResponse(json_encode(array("success" => false, "message" => $error_message)));
         } else {
             $response = $this->jsonResponse(json_encode(array("success" => true, "message" => "Thanks for signing up! We'll keep you posted whenever we have any new updates.")));
         }
         return $response;
     } else {
         $newsletterForm->setErrorMessage($error_message);
         $this->getParserContext()->addForm($newsletterForm)->setGeneralError($error_message);
     }
 }
コード例 #3
0
ファイル: NewsletterTest.php プロジェクト: bobanmilano/thelia
 /**
  * @depends testUpdate
  * @param NewsletterModel $newsletter
  */
 public function testUnsubscribe(NewsletterModel $newsletter)
 {
     $event = new NewsletterEvent('*****@*****.**', 'en_US');
     $event->setId($newsletter->getId());
     $action = new Newsletter();
     $action->unsubscribe($event);
     $deletedNewsletter = $event->getNewsletter();
     $this->assertInstanceOf('Thelia\\Model\\Newsletter', $deletedNewsletter);
     $this->assertEquals(1, NewsletterQuery::create()->filterByEmail('*****@*****.**')->filterByUnsubscribed(true)->count());
 }
コード例 #4
0
ファイル: NewsletterTest.php プロジェクト: alex63530/thelia
 /**
  * @depends testUpdate
  */
 public function testUnsubscribe(NewsletterModel $newsletter)
 {
     $event = new NewsletterEvent('*****@*****.**', 'en_US');
     $event->setId($newsletter->getId());
     $action = new Newsletter();
     $action->unsubscribe($event);
     $deletedNewsletter = $event->getNewsletter();
     $this->assertInstanceOf('Thelia\\Model\\Newsletter', $deletedNewsletter);
     $this->assertTrue($deletedNewsletter->isDeleted());
 }
コード例 #5
0
ファイル: Newsletter.php プロジェクト: NandoKstroNet/thelia
 public function update(NewsletterEvent $event)
 {
     if (null !== ($nl = NewsletterQuery::create()->findPk($event->getId()))) {
         $nl->setEmail($event->getEmail())->setFirstname($event->getFirstname())->setLastname($event->getLastname())->setLocale($event->getLocale())->save();
         $event->setNewsletter($nl);
     }
 }
コード例 #6
0
ファイル: CustomerController.php プロジェクト: badelas/thelia
 public function updateAction()
 {
     if ($this->getSecurityContext()->hasCustomerUser()) {
         $message = false;
         $customerProfileUpdateForm = new CustomerProfileUpdateForm($this->getRequest());
         try {
             $customer = $this->getSecurityContext()->getCustomerUser();
             $newsletterOldEmail = $customer->getEmail();
             $form = $this->validateForm($customerProfileUpdateForm, "post");
             $customerChangeEvent = $this->createEventInstance($form->getData());
             $customerChangeEvent->setCustomer($customer);
             // We do not allow customer email modification
             $customerChangeEvent->setEmailUpdateAllowed(false);
             $this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFILE, $customerChangeEvent);
             $updatedCustomer = $customerChangeEvent->getCustomer();
             // Newsletter
             if (true === $form->get('newsletter')->getData()) {
                 $nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale());
                 $nlEvent->setFirstname($updatedCustomer->getFirstname());
                 $nlEvent->setLastname($updatedCustomer->getLastname());
                 if (null !== ($newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail))) {
                     $nlEvent->setId($newsletter->getId());
                     $this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent);
                 } else {
                     $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent);
                 }
             } else {
                 if (null !== ($newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail))) {
                     $nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale());
                     $nlEvent->setId($newsletter->getId());
                     $this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $nlEvent);
                 }
             }
             $this->processLogin($updatedCustomer);
             return $this->generateSuccessRedirect($customerProfileUpdateForm);
         } catch (FormValidationException $e) {
             $message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
         } catch (\Exception $e) {
             $message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
         }
         if ($message !== false) {
             Tlog::getInstance()->error(sprintf("Error during customer modification process : %s.", $message));
             $customerProfileUpdateForm->setErrorMessage($message);
             $this->getParserContext()->addForm($customerProfileUpdateForm)->setGeneralError($message);
         }
     }
 }
コード例 #7
0
ファイル: Newsletter.php プロジェクト: vigourouxjulien/thelia
 /**
  * @since 2.3.0-alpha2
  */
 public function confirmSubscription(NewsletterEvent $event)
 {
     $this->mailer->sendEmailMessage('newsletter_subscription_confirmation', [ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName()], [$event->getEmail() => $event->getFirstname() . " " . $event->getLastname()], ['email' => $event->getEmail(), 'firstname' => $event->getFirstname(), 'lastname' => $event->getLastname()], $event->getLocale());
 }
コード例 #8
0
 protected function getEmailFromEvent(NewsletterEvent $event)
 {
     return NewsletterQuery::create()->findPk($event->getId())->getEmail();
 }