Skip to content

Commit

Permalink
Ensure subscribing works correctly when email is already a member in
Browse files Browse the repository at this point in the history
Mailchimp
  • Loading branch information
lumnn committed Apr 13, 2022
1 parent 273df41 commit 551f384
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Controller/Subscribe/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public function execute()

if (empty($errors)) {
try {
$saved = $members->add($listId, "subscribed", $post['email'], null, $mergeFields, $interests);
$search = $members->getAll($listId, null, null, 1, null, null, null, null, null, null, null, $post['email']);
$member = count($search['members']) === 1 ? $search['members'][0] : null;

$saved = $member
? $members->update($listId, $member['id'], null, "subscribed", $postMergeFields, $interests)
: $members->add($listId, "subscribed", $post['email'], null, $mergeFields, $interests);

$this->messageManager->addSuccess(__("You have been successfully subscribed to newsletter!"));

return $this->_redirect("newsletter/preferences", ["memberId" => $saved["unique_email_id"]]);
Expand Down

0 comments on commit 551f384

Please sign in to comment.