Skip to content

Commit 0f6671c

Browse files
committed
Merge branch 'MAGETWO-58498' into 2.0-develop-pr1
2 parents a0bd7c5 + 0b9e1f6 commit 0f6671c

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,17 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
548548

549549
$sendInformationEmail = false;
550550
$status = self::STATUS_SUBSCRIBED;
551+
$isConfirmNeed = $this->_scopeConfig->getValue(
552+
self::XML_PATH_CONFIRMATION_FLAG,
553+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
554+
) == 1 ? true : false;
551555
if ($subscribe) {
552556
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
553557
== $this->customerAccountManagement->getConfirmationStatus($customerId)
554558
) {
555559
$status = self::STATUS_UNCONFIRMED;
560+
} else if ($isConfirmNeed) {
561+
$status = self::STATUS_NOT_ACTIVE;
556562
}
557563
} else {
558564
$status = self::STATUS_UNSUBSCRIBED;
@@ -587,7 +593,9 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
587593
$sendSubscription = $sendInformationEmail;
588594
if ($sendSubscription === null xor $sendSubscription) {
589595
try {
590-
if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
596+
if ($isConfirmNeed) {
597+
$this->sendConfirmationRequestEmail();
598+
} else if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
591599
$this->sendUnsubscriptionEmail();
592600
} elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
593601
$this->sendConfirmationSuccessEmail();

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,37 @@ public function testSubscribeCustomerById()
256256

257257
$this->subscriber->subscribeCustomerById($customerId);
258258
}
259+
260+
public function testSubscribeCustomerById1()
261+
{
262+
$customerId = 1;
263+
$customerDataMock = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
264+
->getMock();
265+
$this->customerRepository->expects($this->atLeastOnce())
266+
->method('getById')
267+
->with($customerId)->willReturn($customerDataMock);
268+
$this->resource->expects($this->atLeastOnce())
269+
->method('loadByCustomerData')
270+
->with($customerDataMock)
271+
->willReturn(
272+
[
273+
'subscriber_id' => 1,
274+
'subscriber_status' => 3
275+
]
276+
);
277+
$customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id');
278+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
279+
$customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
280+
$customerDataMock->expects($this->once())->method('getEmail')->willReturn('email');
281+
$this->sendEmailCheck();
282+
$this->customerAccountManagement->expects($this->once())
283+
->method('getConfirmationStatus')
284+
->willReturn(\Magento\Customer\Api\AccountManagementInterface::ACCOUNT_CONFIRMATION_NOT_REQUIRED);
285+
$this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true);
286+
287+
$this->subscriber->subscribeCustomerById($customerId);
288+
$this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus());
289+
}
259290

260291
public function testUnsubscribe()
261292
{

0 commit comments

Comments
 (0)