Skip to content

Commit

Permalink
ENGCOM-8034: #28422 :- Newsletter subscription confirmation email nev…
Browse files Browse the repository at this point in the history
…er sent again #29510
  • Loading branch information
sidolov committed Aug 21, 2020
2 parents 13c29a2 + ec8a262 commit 9de03f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
45 changes: 37 additions & 8 deletions app/code/Magento/Newsletter/Model/SubscriptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ private function saveSubscriber(
): bool {
$statusChanged = (int)$subscriber->getStatus() !== $status;
$emailChanged = $subscriber->getEmail() !== $customer->getEmail();
if ($subscriber->getId()
&& !$statusChanged
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
&& (int)$subscriber->getStoreId() === $storeId
&& !$emailChanged
) {
if ($this->dontNeedToSaveSubscriber(
$subscriber,
$customer,
$statusChanged,
$storeId,
$status,
$emailChanged
)) {
return false;
}

Expand All @@ -220,10 +222,37 @@ private function saveSubscriber(

/**
* If the subscriber is waiting to confirm from the customer
* and customer changed the email
* or customer changed the email
* than need to send confirmation letter to the new email
*/
return $status === Subscriber::STATUS_NOT_ACTIVE && $emailChanged;
return $status === Subscriber::STATUS_NOT_ACTIVE || $emailChanged;
}

/**
* Don't need to save subscriber model
*
* @param Subscriber $subscriber
* @param CustomerInterface $customer
* @param bool $statusChanged
* @param int $storeId
* @param int $status
* @param bool $emailChanged
* @return bool
*/
private function dontNeedToSaveSubscriber(
Subscriber $subscriber,
CustomerInterface $customer,
bool $statusChanged,
int $storeId,
int $status,
bool $emailChanged
): bool {
return $subscriber->getId()
&& !$statusChanged
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
&& (int)$subscriber->getStoreId() === $storeId
&& !$emailChanged
&& $status !== Subscriber::STATUS_NOT_ACTIVE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public function subscribeCustomerDataProvider(): array
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED,
'subscriber_confirm_code' => '',
],
'needToSendEmail' => false,
'needToSendEmail' => true,
],
'Update subscription data: subscription confirm required ' => [
'subscriber_data' => [
Expand Down Expand Up @@ -618,7 +618,7 @@ public function unsubscribeCustomerDataProvider(): array
'subscriber_status' => Subscriber::STATUS_NOT_ACTIVE,
'subscriber_confirm_code' => '',
],
'needToSendEmail' => false,
'needToSendEmail' => true,
],
'Update subscription data' => [
'subscriber_data' => [
Expand All @@ -642,7 +642,7 @@ public function unsubscribeCustomerDataProvider(): array
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
'subscriber_confirm_code' => '',
],
'needToSendEmail' => false,
'needToSendEmail' => true,
],
];
}
Expand Down

0 comments on commit 9de03f5

Please sign in to comment.