Skip to content

Commit 208b1ef

Browse files
author
olysenko
committed
MAGETWO-71829: is_subscribed extended attribute isn't returned in REST customer calls
1 parent d3a7b40 commit 208b1ef

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public function afterSave(CustomerRepository $subject, CustomerInterface $result
8181
}
8282
$newExtensionAttributes = $customer->getExtensionAttributes();
8383
if ($newExtensionAttributes
84-
&& $initialExtensionAttributes->getIsSubscribed() !== $newExtensionAttributes->getIsSubscribed()) {
84+
&& $initialExtensionAttributes->getIsSubscribed() !== $newExtensionAttributes->getIsSubscribed()
85+
) {
8586
if ($newExtensionAttributes->getIsSubscribed() === true) {
8687
$subscriber->subscribeCustomerById($resultId);
8788
} elseif ($newExtensionAttributes->getIsSubscribed() === false) {
@@ -149,18 +150,13 @@ public function afterGetById(CustomerRepository $subject, CustomerInterface $cus
149150
{
150151
$extensionAttributes = $customer->getExtensionAttributes();
151152
if ($extensionAttributes === null) {
152-
/** @var CustomerExtensionInterface $customerExtension */
153-
$customerExtension = $this->extensionFactory->create(CustomerInterface::class);
154-
$isSubscribed = $this->isSubscribed($customer);
155-
$customerExtension->setIsSubscribed($isSubscribed);
156-
$customer->setExtensionAttributes($customerExtension);
157-
return $customer;
153+
/** @var CustomerExtensionInterface $extensionAttributes */
154+
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);
155+
$customer->setExtensionAttributes($extensionAttributes);
158156
}
159157
if ($extensionAttributes->getIsSubscribed() === null) {
160158
$isSubscribed = $this->isSubscribed($customer);
161159
$extensionAttributes->setIsSubscribed($isSubscribed);
162-
$customer->setExtensionAttributes($extensionAttributes);
163-
return $customer;
164160
}
165161
return $customer;
166162
}

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
201201
$this->extensionFactoryMock->expects($this->any())
202202
->method('create')
203203
->willReturn($this->customerExtensionMock);
204+
$this->customerMock->expects($this->once())
205+
->method('setExtensionAttributes')
206+
->with($this->customerExtensionMock)
207+
->willReturnSelf();
204208
$this->customerMock->expects($this->any())
205209
->method('getId')
206210
->willReturn(1);
@@ -209,10 +213,6 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
209213
->with($this->customerMock)
210214
->willReturn($subscriber);
211215
$this->customerExtensionMock->expects($this->once())->method('setIsSubscribed')->with($isSubscribed);
212-
$this->customerMock->expects($this->once())
213-
->method('setExtensionAttributes')
214-
->with($this->customerExtensionMock)
215-
->willReturnSelf();
216216
$this->assertEquals(
217217
$this->customerMock,
218218
$this->plugin->afterGetById($subject, $this->customerMock)
@@ -236,10 +236,6 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
236236
$this->customerExtensionMock->expects($this->once())
237237
->method('setIsSubscribed')
238238
->willReturnSelf();
239-
$this->customerMock->expects($this->once())
240-
->method('setExtensionAttributes')
241-
->with($this->customerExtensionMock)
242-
->willReturnSelf();
243239
$this->assertEquals(
244240
$this->customerMock,
245241
$this->plugin->afterGetById($subject, $this->customerMock)

0 commit comments

Comments
 (0)