diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php index 5720ff1..0f1bef7 100644 --- a/Controller/DefaultController.php +++ b/Controller/DefaultController.php @@ -116,6 +116,21 @@ public function subscribeAction(Request $request) 'status' => false, ); } + + if (empty($groups)) { + try { + $newsletterService->unsubscribe($user->getEmail(), $listIdGroups); + $messages[] = array( + 'message' => $translator->trans('plugin.newsletter.msg.unsubscribe', array('%list%' => $listIdGroups)), + 'status' => true, + ); + } catch(\Exception $e) { + $messages[] = array( + 'message' => $translator->trans('plugin.newsletter.msg.errorunsubscribe', array('%list%' => $listIdGroups)), + 'status' => false, + ); + } + } } return new JsonResponse(array('response' => $messages)); diff --git a/Services/NewsletterListsService.php b/Services/NewsletterListsService.php index 39ad5ab..6123b32 100644 --- a/Services/NewsletterListsService.php +++ b/Services/NewsletterListsService.php @@ -188,6 +188,10 @@ public function getUserGroups($listId, $groupName) { $user = $this->user->getCurrentUser(); if ($user) { + if (!$this->isSubscribed($user->getEmail(), $listId)) { + return array(); + } + $info = $this->initMailchimp()->lists->memberInfo($listId, array(array('email' => $user->getEmail()))); if (!$info['success_count']) { return array(); diff --git a/composer.json b/composer.json index 9c0e2b3..39fd669 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "newscoop/newsletter-plugin-bundle", "description": "Newscoop Newsletter Plugin bundle", "keywords": ["newscoop", "newsletter", "mailchimp", "email", "plugin"], - "version": "0.3", + "version": "0.4", "type": "newscoop-plugin", "license": "GPL-3.0", "authors": [ @@ -21,4 +21,4 @@ }, "target-dir": "Newscoop/NewsletterPluginBundle", "minimum-stability": "dev" -} \ No newline at end of file +}