Skip to content

Commit c2b038e

Browse files
removed caching subscription status from plugin
1 parent 2e2af0a commit c2b038e

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ class CustomerPlugin
5252
*/
5353
private $storeManager;
5454

55-
/**
56-
* @var array
57-
*/
58-
private $customerSubscriber = [];
59-
6055
/**
6156
* @var SubscriberFactory
6257
*/
@@ -132,7 +127,6 @@ public function afterSave(
132127
$subscriber = $subscribeStatus
133128
? $this->subscriptionManager->subscribeCustomer((int)$result->getId(), $storeId)
134129
: $this->subscriptionManager->unsubscribeCustomer((int)$result->getId(), $storeId);
135-
$this->customerSubscriber[(int)$result->getId()] = $subscriber;
136130
}
137131
$this->addIsSubscribedExtensionAttribute($result, $subscriber->isSubscribed());
138132

@@ -314,11 +308,6 @@ private function deleteSubscriptionsAfterCustomerDelete(CustomerInterface $custo
314308
*/
315309
private function getSubscriber(CustomerInterface $customer): Subscriber
316310
{
317-
$customerId = (int)$customer->getId();
318-
if (isset($this->customerSubscriber[$customerId])) {
319-
return $this->customerSubscriber[$customerId];
320-
}
321-
322311
/** @var Subscriber $subscriber */
323312
$subscriber = $this->subscriberFactory->create();
324313
$websiteId = $this->getCurrentWebsiteId($customer);
@@ -330,7 +319,6 @@ private function getSubscriber(CustomerInterface $customer): Subscriber
330319
if (!$subscriber->getId()) {
331320
$subscriber->loadBySubscriberEmail((string)$customer->getEmail(), $websiteId);
332321
}
333-
$this->customerSubscriber[$customerId] = $subscriber;
334322

335323
return $subscriber;
336324
}

dev/tests/integration/testsuite/Magento/Newsletter/Model/SubscriberTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ public function testUnsubscribeSubscribeByCustomerId(): void
136136
);
137137
}
138138

139+
/**
140+
* Test subscribe and verify customer subscription status
141+
*
142+
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
143+
*
144+
* @return void
145+
*/
146+
public function testSubscribeAndVerifyCustomerSubscriptionStatus(): void
147+
{
148+
$customer = $this->customerRepository->getById(1);
149+
$subscriptionBefore = $customer->getExtensionAttributes()
150+
->getIsSubscribed();
151+
$subscriber = $this->subscriberFactory->create();
152+
$subscriber->subscribeCustomerById($customer->getId());
153+
154+
$customer = $this->customerRepository->getById(1);
155+
156+
$this->assertFalse($subscriptionBefore);
157+
$this->assertTrue($customer->getExtensionAttributes()->getIsSubscribed());
158+
}
159+
139160
/**
140161
* @magentoConfigFixture current_store newsletter/subscription/confirm 1
141162
*

0 commit comments

Comments
 (0)