Skip to content

Commit f5cc98e

Browse files
committed
#31168 fix for customer which have more than two subscriptions
1 parent b941603 commit f5cc98e

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,6 @@ public function afterGetById(CustomerRepositoryInterface $subject, CustomerInter
234234
return $customer;
235235
}
236236

237-
/**
238-
* Add subscription status to customer list
239-
*
240-
* @param CustomerRepositoryInterface $subject
241-
* @param SearchResults $searchResults
242-
* @return SearchResults
243-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
244-
*/
245-
public function afterGetList(CustomerRepositoryInterface $subject, SearchResults $searchResults): SearchResults
246-
{
247-
foreach ($searchResults->getItems() as $customer) {
248-
/** @var CustomerExtensionInterface $extensionAttributes */
249-
$extensionAttributes = $customer->getExtensionAttributes();
250-
251-
$isSubscribed = (int) $extensionAttributes->getIsSubscribed() === Subscriber::STATUS_SUBSCRIBED ?: false;
252-
$extensionAttributes->setIsSubscribed($isSubscribed);
253-
}
254-
255-
return $searchResults;
256-
}
257-
258237
/**
259238
* Set Is Subscribed extension attribute
260239
*

app/code/Magento/Newsletter/etc/extension_attributes.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
1010
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
11-
<attribute code="is_subscribed" type="boolean" >
12-
<join reference_table="newsletter_subscriber" reference_field="customer_id" join_on_field="entity_id">
13-
<field>subscriber_status</field>
14-
</join>
15-
</attribute>
11+
<attribute code="is_subscribed" type="boolean"/>
1612
</extension_attributes>
1713
</config>

dev/tests/integration/testsuite/Magento/Newsletter/Model/Plugin/PluginTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,18 @@ public function testCustomerWithZeroStoreIdIsSubscribed()
205205
$this->assertEquals($customer->getId(), (int)$subscriber->getCustomerId());
206206
$this->assertEquals($currentStore, (int)$subscriber->getStoreId());
207207
}
208+
209+
/**
210+
* Test get list customer, which have more then 2 subscribes in newsletter_subscriber.
211+
*
212+
* @magentoAppArea frontend
213+
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
214+
*/
215+
public function testCustomerWithTwoNewsLetterSubscriptions()
216+
{
217+
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
218+
$searchBuilder = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
219+
$searchCriteria = $searchBuilder->addFilter('entity_id', 1)->create();
220+
$this->customerRepository->getList($searchCriteria);
221+
}
208222
}

0 commit comments

Comments
 (0)