Skip to content

Commit d00263a

Browse files
committed
MAGETWO-66793: [Backport] Merchant can't unsubscribe Customer from Newsletter in Admin
- Move get subscription status to separate method;
1 parent 9efbb79 commit d00263a

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,24 +555,13 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
555555
}
556556

557557
$sendInformationEmail = false;
558-
$status = self::STATUS_SUBSCRIBED;
559-
$isConfirmNeed = $this->_scopeConfig->getValue(
560-
self::XML_PATH_CONFIRMATION_FLAG,
561-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
562-
) == 1 ? true : false;
563-
if ($subscribe) {
564-
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
565-
== $this->customerAccountManagement->getConfirmationStatus($customerId)
566-
) {
567-
$status = self::STATUS_UNCONFIRMED;
568-
} elseif ($isConfirmNeed) {
569-
$status = self::STATUS_NOT_ACTIVE;
570-
}
571-
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && ($customerData->getConfirmation() === null)) {
572-
$status = self::STATUS_SUBSCRIBED;
558+
$isConfirmNeed = 1 === (int)$this->_scopeConfig->getValue(
559+
self::XML_PATH_CONFIRMATION_FLAG,
560+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
561+
);
562+
$status = $this->getSubscriptionStatus($subscribe, $isConfirmNeed, $customerId);
563+
if ($status == self::STATUS_SUBSCRIBED && $customerData->getConfirmation() === null) {
573564
$sendInformationEmail = true;
574-
} else {
575-
$status = self::STATUS_UNSUBSCRIBED;
576565
}
577566
/**
578567
* If subscription status has been changed then send email to the customer
@@ -619,6 +608,34 @@ protected function _updateCustomerSubscription($customerId, $subscribe)
619608
return $this;
620609
}
621610

611+
/**
612+
* Get subscription status
613+
*
614+
* @param bool $subscribe
615+
* @param bool $isConfirmNeed
616+
* @param string $customerId
617+
* @return int
618+
*/
619+
private function getSubscriptionStatus($subscribe, $isConfirmNeed, $customerId)
620+
{
621+
$status = self::STATUS_SUBSCRIBED;
622+
if ($subscribe) {
623+
if (AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED
624+
== $this->customerAccountManagement->getConfirmationStatus($customerId)
625+
) {
626+
$status = self::STATUS_UNCONFIRMED;
627+
} elseif ($isConfirmNeed) {
628+
$status = self::STATUS_NOT_ACTIVE;
629+
}
630+
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED)) {
631+
$status = self::STATUS_SUBSCRIBED;
632+
} else {
633+
$status = self::STATUS_UNSUBSCRIBED;
634+
}
635+
636+
return $status;
637+
}
638+
622639
/**
623640
* Confirms subscriber newsletter
624641
*

0 commit comments

Comments
 (0)