Skip to content

Commit 20a332f

Browse files
author
Stanislav Idolov
authored
ENGCOM-2428: [Forwardport] Fix newsletter subscription behaviour for registered customer. #16947
2 parents 8700de5 + 3dbac7a commit 20a332f

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
@@ -419,7 +419,6 @@ public function subscribe($email)
419419
self::XML_PATH_CONFIRMATION_FLAG,
420420
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
421421
) == 1 ? true : false;
422-
$isOwnSubscribes = false;
423422

424423
$isSubscribeOwnEmail = $this->_customerSession->isLoggedIn()
425424
&& $this->_customerSession->getCustomerDataObject()->getEmail() == $email;
@@ -428,13 +427,7 @@ public function subscribe($email)
428427
|| $this->getStatus() == self::STATUS_NOT_ACTIVE
429428
) {
430429
if ($isConfirmNeed === true) {
431-
// if user subscribes own login email - confirmation is not needed
432-
$isOwnSubscribes = $isSubscribeOwnEmail;
433-
if ($isOwnSubscribes == true) {
434-
$this->setStatus(self::STATUS_SUBSCRIBED);
435-
} else {
436-
$this->setStatus(self::STATUS_NOT_ACTIVE);
437-
}
430+
$this->setStatus(self::STATUS_NOT_ACTIVE);
438431
} else {
439432
$this->setStatus(self::STATUS_SUBSCRIBED);
440433
}
@@ -460,9 +453,7 @@ public function subscribe($email)
460453
try {
461454
/* Save model before sending out email */
462455
$this->save();
463-
if ($isConfirmNeed === true
464-
&& $isOwnSubscribes === false
465-
) {
456+
if ($isConfirmNeed === true) {
466457
$this->sendConfirmationRequestEmail();
467458
} else {
468459
$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
*/
@@ -116,7 +118,7 @@ public function testSubscribe()
116118
$email = '[email protected]';
117119
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
118120
[
119-
'subscriber_status' => 3,
121+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
120122
'subscriber_email' => $email,
121123
'name' => 'subscriber_name'
122124
]
@@ -133,15 +135,15 @@ public function testSubscribe()
133135
$this->sendEmailCheck();
134136
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
135137

136-
$this->assertEquals(1, $this->subscriber->subscribe($email));
138+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
137139
}
138140

139141
public function testSubscribeNotLoggedIn()
140142
{
141143
$email = '[email protected]';
142144
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
143145
[
144-
'subscriber_status' => 3,
146+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED,
145147
'subscriber_email' => $email,
146148
'name' => 'subscriber_name'
147149
]
@@ -158,7 +160,7 @@ public function testSubscribeNotLoggedIn()
158160
$this->sendEmailCheck();
159161
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
160162

161-
$this->assertEquals(2, $this->subscriber->subscribe($email));
163+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
162164
}
163165

164166
public function testUpdateSubscription()
@@ -175,7 +177,7 @@ public function testUpdateSubscription()
175177
->willReturn(
176178
[
177179
'subscriber_id' => 1,
178-
'subscriber_status' => 1
180+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
179181
]
180182
);
181183
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -210,7 +212,7 @@ public function testUnsubscribeCustomerById()
210212
->willReturn(
211213
[
212214
'subscriber_id' => 1,
213-
'subscriber_status' => 1
215+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
214216
]
215217
);
216218
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -236,7 +238,7 @@ public function testSubscribeCustomerById()
236238
->willReturn(
237239
[
238240
'subscriber_id' => 1,
239-
'subscriber_status' => 3
241+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
240242
]
241243
);
242244
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -262,7 +264,7 @@ public function testSubscribeCustomerById1()
262264
->willReturn(
263265
[
264266
'subscriber_id' => 1,
265-
'subscriber_status' => 3
267+
'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED
266268
]
267269
);
268270
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -276,7 +278,7 @@ public function testSubscribeCustomerById1()
276278
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
277279

278280
$this->subscriber->subscribeCustomerById($customerId);
279-
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
281+
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
280282
}
281283

282284
public function testSubscribeCustomerByIdAfterConfirmation()
@@ -293,7 +295,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
293295
->willReturn(
294296
[
295297
'subscriber_id' => 1,
296-
'subscriber_status' => 4
298+
'subscriber_status' => Subscriber::STATUS_UNCONFIRMED
297299
]
298300
);
299301
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -305,7 +307,7 @@ public function testSubscribeCustomerByIdAfterConfirmation()
305307
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
306308

307309
$this->subscriber->updateSubscription($customerId);
308-
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
310+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
309311
}
310312

311313
public function testUnsubscribe()

0 commit comments

Comments
 (0)