Skip to content

Commit ec8a262

Browse files
ENGCOM-8034: #28422 :- Newsletter subscription confirmation email never sent again #29510
- Merge Pull Request #29510 from konarshankar07/magento2:newsletter-confirmation-email--task-28422 - Merged commits: 1. 1a7c8cd 2. 6e53e0d 3. ea584f9 4. ab3db16
2 parents 8b7d949 + ab3db16 commit ec8a262

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

app/code/Magento/Newsletter/Model/SubscriptionManager.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ private function saveSubscriber(
195195
): bool {
196196
$statusChanged = (int)$subscriber->getStatus() !== $status;
197197
$emailChanged = $subscriber->getEmail() !== $customer->getEmail();
198-
if ($subscriber->getId()
199-
&& !$statusChanged
200-
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
201-
&& (int)$subscriber->getStoreId() === $storeId
202-
&& !$emailChanged
203-
) {
198+
if ($this->dontNeedToSaveSubscriber(
199+
$subscriber,
200+
$customer,
201+
$statusChanged,
202+
$storeId,
203+
$status,
204+
$emailChanged
205+
)) {
204206
return false;
205207
}
206208

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

221223
/**
222224
* If the subscriber is waiting to confirm from the customer
223-
* and customer changed the email
225+
* or customer changed the email
224226
* than need to send confirmation letter to the new email
225227
*/
226-
return $status === Subscriber::STATUS_NOT_ACTIVE && $emailChanged;
228+
return $status === Subscriber::STATUS_NOT_ACTIVE || $emailChanged;
229+
}
230+
231+
/**
232+
* Don't need to save subscriber model
233+
*
234+
* @param Subscriber $subscriber
235+
* @param CustomerInterface $customer
236+
* @param bool $statusChanged
237+
* @param int $storeId
238+
* @param int $status
239+
* @param bool $emailChanged
240+
* @return bool
241+
*/
242+
private function dontNeedToSaveSubscriber(
243+
Subscriber $subscriber,
244+
CustomerInterface $customer,
245+
bool $statusChanged,
246+
int $storeId,
247+
int $status,
248+
bool $emailChanged
249+
): bool {
250+
return $subscriber->getId()
251+
&& !$statusChanged
252+
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
253+
&& (int)$subscriber->getStoreId() === $storeId
254+
&& !$emailChanged
255+
&& $status !== Subscriber::STATUS_NOT_ACTIVE;
227256
}
228257

229258
/**

app/code/Magento/Newsletter/Test/Unit/Model/SubscriptionManagerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public function subscribeCustomerDataProvider(): array
454454
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED,
455455
'subscriber_confirm_code' => '',
456456
],
457-
'needToSendEmail' => false,
457+
'needToSendEmail' => true,
458458
],
459459
'Update subscription data: subscription confirm required ' => [
460460
'subscriber_data' => [
@@ -618,7 +618,7 @@ public function unsubscribeCustomerDataProvider(): array
618618
'subscriber_status' => Subscriber::STATUS_NOT_ACTIVE,
619619
'subscriber_confirm_code' => '',
620620
],
621-
'needToSendEmail' => false,
621+
'needToSendEmail' => true,
622622
],
623623
'Update subscription data' => [
624624
'subscriber_data' => [
@@ -642,7 +642,7 @@ public function unsubscribeCustomerDataProvider(): array
642642
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
643643
'subscriber_confirm_code' => '',
644644
],
645-
'needToSendEmail' => false,
645+
'needToSendEmail' => true,
646646
],
647647
];
648648
}

0 commit comments

Comments
 (0)