Skip to content

Commit 0a4275a

Browse files
committed
MAGETWO-71179: Customers are unsubscribed from the newsletter after confirming their account
1 parent e669b04 commit 0a4275a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
555555
} elseif ($isConfirmNeed) {
556556
$status = self::STATUS_NOT_ACTIVE;
557557
}
558+
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
559+
$status = self::STATUS_SUBSCRIBED;
560+
$sendInformationEmail = true;
558561
} else {
559562
$status = self::STATUS_UNSUBSCRIBED;
560563
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,35 @@ public function testSubscribeCustomerById1()
273273
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
274274
}
275275

276+
public function testSubscribeCustomerByIdAfterConfirmation()
277+
{
278+
$customerId = 1;
279+
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
280+
->getMock();
281+
$this->customerRepository->expects($this->atLeastOnce())
282+
->method('getById')
283+
->with($customerId)->willReturn($customerDataMock);
284+
$this->resource->expects($this->atLeastOnce())
285+
->method('loadByCustomerData')
286+
->with($customerDataMock)
287+
->willReturn(
288+
[
289+
'subscriber_id' => 1,
290+
'subscriber_status' => 4
291+
]
292+
);
293+
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
294+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
295+
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
296+
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
297+
$this->sendEmailCheck();
298+
$this->customerAccountManagement->expects($this->never())->method('getConfirmationStatus');
299+
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
300+
301+
$this->subscriber->updateSubscription($customerId);
302+
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus());
303+
}
304+
276305
public function testUnsubscribe()
277306
{
278307
$this->resource->expects($this->once())->method('save')->willReturnSelf();

0 commit comments

Comments
 (0)