diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php
index 3bfedc5ca..464f7cf20 100755
--- a/core/lib/Thelia/Action/Customer.php
+++ b/core/lib/Thelia/Action/Customer.php
@@ -71,7 +71,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
->setTitleId($event->getTitle())
->setFirstname($event->getFirstname())
->setLastname($event->getLastname())
- ->setEmail($event->getEmail())
+ ->setEmail($event->getEmail(), true)
->setPassword($event->getPassword())
->setReseller($event->getReseller())
->setSponsor($event->getSponsor())
diff --git a/core/lib/Thelia/Action/Newsletter.php b/core/lib/Thelia/Action/Newsletter.php
index 905cf48b0..fe489e120 100644
--- a/core/lib/Thelia/Action/Newsletter.php
+++ b/core/lib/Thelia/Action/Newsletter.php
@@ -26,6 +26,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Action\BaseAction;
+use Thelia\Model\NewsletterQuery;
use Thelia\Model\Newsletter as NewsletterModel;
@@ -51,7 +52,20 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
public function unsubscribe(NewsletterEvent $event)
{
- // TODO
+ if(null !== $nl = NewsletterQuery::create()->findPk($event->getId())) {
+ $nl->delete();
+ }
+ }
+
+ 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();
+ }
}
/**
@@ -78,6 +92,7 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
{
return array(
TheliaEvents::NEWSLETTER_SUBSCRIBE => array('subscribe', 128),
+ TheliaEvents::NEWSLETTER_UPDATE => array('update', 128),
TheliaEvents::NEWSLETTER_UNSUBSCRIBE => array('unsubscribe', 128)
);
}
diff --git a/core/lib/Thelia/Controller/Front/CustomerController.php b/core/lib/Thelia/Controller/Front/CustomerController.php
index c02a36e57..5611675e8 100755
--- a/core/lib/Thelia/Controller/Front/CustomerController.php
+++ b/core/lib/Thelia/Controller/Front/CustomerController.php
@@ -25,6 +25,7 @@ namespace Thelia\Controller\Front;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerLoginEvent;
use Thelia\Core\Event\LostPasswordEvent;
+use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Security\Exception\UsernameNotFoundException;
@@ -146,7 +147,7 @@ class CustomerController extends BaseFrontController
'firstname' => $customer->getFirstName(),
'lastname' => $customer->getLastName(),
'email' => $customer->getEmail(),
- 'newsletter' => NewsletterQuery::isSubscribed($customer->getEmail())
+ 'newsletter' => null !== NewsletterQuery::create()->findOneByEmail($customer->getEmail()),
);
$customerProfilUpdateForm = new CustomerProfilUpdateForm($this->getRequest(), 'form', $data);
@@ -203,6 +204,7 @@ class CustomerController extends BaseFrontController
try {
$customer = $this->getSecurityContext()->getCustomerUser();
+ $newsletterOldEmail = $customer->getEmail();
$form = $this->validateForm($customerProfilUpdateForm, "post");
@@ -210,14 +212,29 @@ class CustomerController extends BaseFrontController
$customerChangeEvent->setCustomer($customer);
$this->dispatch(TheliaEvents::CUSTOMER_UPDATEPROFIL, $customerChangeEvent);
+ $updatedCustomer = $customerChangeEvent->getCustomer();
+
// Newsletter
- if ($form->get('newsletter')->getData()){
- //$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $customerChangeEvent);
+ 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 {
- //$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $customerChangeEvent);
+ 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($customerChangeEvent->getCustomer());
+ $this->processLogin($updatedCustomer);
$this->redirectSuccess($customerProfilUpdateForm);
diff --git a/core/lib/Thelia/Core/Event/Newsletter/NewsletterEvent.php b/core/lib/Thelia/Core/Event/Newsletter/NewsletterEvent.php
index fc50980c0..85948a621 100644
--- a/core/lib/Thelia/Core/Event/Newsletter/NewsletterEvent.php
+++ b/core/lib/Thelia/Core/Event/Newsletter/NewsletterEvent.php
@@ -32,6 +32,11 @@ use Thelia\Core\Event\ActionEvent;
*/
class NewsletterEvent extends ActionEvent
{
+ /**
+ * @var string email to save
+ */
+ protected $id;
+
/**
* @var string email to save
*/
@@ -138,6 +143,22 @@ class NewsletterEvent extends ActionEvent
return $this->locale;
}
+ /**
+ * @param string $id
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 6c44638d7..0754855eb 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -691,9 +691,6 @@ final class TheliaEvents
* sent for subscribing to the newsletter
*/
const NEWSLETTER_SUBSCRIBE = 'thelia.newsletter.subscribe';
-
- /**
- * sent for subscribing to the newsletter
- */
+ const NEWSLETTER_UPDATE = 'thelia.newsletter.update';
const NEWSLETTER_UNSUBSCRIBE = 'thelia.newsletter.unsubscribe';
}
diff --git a/core/lib/Thelia/Model/NewsletterQuery.php b/core/lib/Thelia/Model/NewsletterQuery.php
index d1577b73f..26b4d2614 100644
--- a/core/lib/Thelia/Model/NewsletterQuery.php
+++ b/core/lib/Thelia/Model/NewsletterQuery.php
@@ -17,8 +17,5 @@ use Thelia\Model\Base\NewsletterQuery as BaseNewsletterQuery;
*/
class NewsletterQuery extends BaseNewsletterQuery
{
- public static function isSubscribed($email)
- {
- return (null === self::create()->findOneByEmail($email)) ? false : true;
- }
+
} // NewsletterQuery
diff --git a/local/config/schema.xml b/local/config/schema.xml
index 2f12abf1e..81c10cbd3 100755
--- a/local/config/schema.xml
+++ b/local/config/schema.xml
@@ -84,7 +84,8 @@
-
+
+
@@ -767,13 +768,12 @@
-
+
-
@@ -783,7 +783,7 @@
-
+
@@ -792,9 +792,8 @@
-
-
-
+
+
@@ -932,16 +931,16 @@
-
+
-
+
-
+
-
+
@@ -972,13 +971,13 @@
-
+
-
+
-
+
@@ -995,8 +994,9 @@
-
-
+
+
+
@@ -1250,7 +1250,10 @@
-
+
+
+
+