Skip to content

Commit ef16761

Browse files
author
Stanislav Idolov
authored
ENGCOM-2272: Fix newsletter subscription behaviour for registered customer. #15479
2 parents 45f94fe + effc9ea commit ef16761

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ public function subscribe($email)
447447
self::XML_PATH_CONFIRMATION_FLAG,
448448
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
449449
) == 1 ? true : false;
450-
$isOwnSubscribes = false;
451450

452451
$isSubscribeOwnEmail = $this->_customerSession->isLoggedIn()
453452
&& $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
@@ -456,13 +455,7 @@ public function subscribe($email)
456455
|| $this->getStatus() == self::STATUS_NOT_ACTIVE
457456
) {
458457
if ($isConfirmNeed === true) {
459-
// if user subscribes own login email - confirmation is not needed
460-
$isOwnSubscribes = $isSubscribeOwnEmail;
461-
if ($isOwnSubscribes == true) {
462-
$this->setStatus(self::STATUS_SUBSCRIBED);
463-
} else {
464-
$this->setStatus(self::STATUS_NOT_ACTIVE);
465-
}
458+
$this->setStatus(self::STATUS_NOT_ACTIVE);
466459
} else {
467460
$this->setStatus(self::STATUS_SUBSCRIBED);
468461
}
@@ -488,9 +481,7 @@ public function subscribe($email)
488481
try {
489482
/* Save model before sending out email */
490483
$this->save();
491-
if ($isConfirmNeed === true
492-
&& $isOwnSubscribes === false
493-
) {
484+
if ($isConfirmNeed === true) {
494485
$this->sendConfirmationRequestEmail();
495486
} else {
496487
$this->sendConfirmationSuccessEmail();

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Newsletter\Test\Unit\Model;
77

8+
use Magento\Newsletter\Model\Subscriber;
9+
810
/**
911
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1012
*/
@@ -148,7 +150,7 @@ public function testSubscribe()
148150
);
149151
$this->resource->expects($this->any())->method('loadByCustomerData')->with($customer)->willReturn(
150152
[
151-
'subscriber_status' => 3,
153+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
152154
'subscriber_email' => $email,
153155
'name' => 'subscriber_name'
154156
]
@@ -165,7 +167,7 @@ public function testSubscribe()
165167
$this->sendEmailCheck();
166168
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
167169

168-
$this->assertEquals(1, $this->subscriber->subscribe($email));
170+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
169171
}
170172

171173
public function testSubscribeNotLoggedIn()
@@ -187,7 +189,7 @@ public function testSubscribeNotLoggedIn()
187189
);
188190
$this->resource->expects($this->any())->method('loadByCustomerData')->with($customer)->willReturn(
189191
[
190-
'subscriber_status' => 3,
192+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
191193
'subscriber_email' => $email,
192194
'name' => 'subscriber_name'
193195
]
@@ -204,7 +206,7 @@ public function testSubscribeNotLoggedIn()
204206
$this->sendEmailCheck();
205207
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
206208

207-
$this->assertEquals(2, $this->subscriber->subscribe($email));
209+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
208210
}
209211

210212
public function testUpdateSubscription()
@@ -221,7 +223,7 @@ public function testUpdateSubscription()
221223
->willReturn(
222224
[
223225
'subscriber_id' => 1,
224-
'subscriber_status' => 1
226+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
225227
]
226228
);
227229
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -256,7 +258,7 @@ public function testUnsubscribeCustomerById()
256258
->willReturn(
257259
[
258260
'subscriber_id' => 1,
259-
'subscriber_status' => 1
261+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
260262
]
261263
);
262264
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -282,7 +284,7 @@ public function testSubscribeCustomerById()
282284
->willReturn(
283285
[
284286
'subscriber_id' => 1,
285-
'subscriber_status' => 3
287+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
286288
]
287289
);
288290
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -308,7 +310,7 @@ public function testSubscribeCustomerById1()
308310
->willReturn(
309311
[
310312
'subscriber_id' => 1,
311-
'subscriber_status' => 3
313+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
312314
]
313315
);
314316
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -322,7 +324,7 @@ public function testSubscribeCustomerById1()
322324
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
323325

324326
$this->subscriber->subscribeCustomerById($customerId);
325-
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
327+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
326328
}
327329

328330
public function testSubscribeCustomerByIdAfterConfirmation()
@@ -339,7 +341,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
339341
->willReturn(
340342
[
341343
'subscriber_id' => 1,
342-
'subscriber_status' => 4
344+
'subscriber_status' => Subscriber::STATUS_UNCONFIRMED
343345
]
344346
);
345347
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -351,7 +353,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
351353
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
352354

353355
$this->subscriber->updateSubscription($customerId);
354-
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
356+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
355357
}
356358

357359
public function testUnsubscribe()

0 commit comments

Comments
 (0)