Skip to content

Commit 10104f6

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95875' into 2.2-develop-pr68
2 parents a110e3c + b4d6342 commit 10104f6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public function updateSubscription($customerId)
552552
}
553553

554554
/**
555-
* Saving customer subscription status
555+
* Saving customer subscription status.
556556
*
557557
* @param int $customerId
558558
* @param bool $subscribe indicates whether the customer should be subscribed or unsubscribed
@@ -588,7 +588,12 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
588588
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
589589
== $this->customerAccountManagement->getConfirmationStatus($customerId)
590590
) {
591-
$status = self::STATUS_UNCONFIRMED;
591+
if ($this->getId() && $this->getStatus() == self::STATUS_SUBSCRIBED) {
592+
// if a customer was already subscribed then keep the subscribed
593+
$status = self::STATUS_SUBSCRIBED;
594+
} else {
595+
$status = self::STATUS_UNCONFIRMED;
596+
}
592597
} elseif ($isConfirmNeed) {
593598
if ($this->getStatus() != self::STATUS_SUBSCRIBED) {
594599
$status = self::STATUS_NOT_ACTIVE;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ public function testSubscribeNotLoggedIn()
209209
$this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email));
210210
}
211211

212+
/**
213+
* Update status with Confirmation Status - required.
214+
*
215+
* @return void
216+
*/
212217
public function testUpdateSubscription()
213218
{
214219
$websiteId = 1;
@@ -225,7 +230,7 @@ public function testUpdateSubscription()
225230
->willReturn(
226231
[
227232
'subscriber_id' => 1,
228-
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED
233+
'subscriber_status' => Subscriber::STATUS_SUBSCRIBED,
229234
]
230235
);
231236
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
@@ -245,8 +250,9 @@ public function testUpdateSubscription()
245250
->getMock();
246251
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
247252
$storeModel->expects($this->exactly(2))->method('getWebsiteId')->willReturn($websiteId);
253+
$data = $this->subscriber->updateSubscription($customerId);
248254

249-
$this->assertEquals($this->subscriber, $this->subscriber->updateSubscription($customerId));
255+
$this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $data->getSubscriberStatus());
250256
}
251257

252258
public function testUnsubscribeCustomerById()

0 commit comments

Comments
 (0)