Skip to content

Commit

Permalink
#31168 fix for customer which have more than two subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
korovitskyi committed Dec 11, 2020
1 parent b941603 commit f5cc98e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
21 changes: 0 additions & 21 deletions app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,6 @@ public function afterGetById(CustomerRepositoryInterface $subject, CustomerInter
return $customer;
}

/**
* Add subscription status to customer list
*
* @param CustomerRepositoryInterface $subject
* @param SearchResults $searchResults
* @return SearchResults
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetList(CustomerRepositoryInterface $subject, SearchResults $searchResults): SearchResults
{
foreach ($searchResults->getItems() as $customer) {
/** @var CustomerExtensionInterface $extensionAttributes */
$extensionAttributes = $customer->getExtensionAttributes();

$isSubscribed = (int) $extensionAttributes->getIsSubscribed() === Subscriber::STATUS_SUBSCRIBED ?: false;
$extensionAttributes->setIsSubscribed($isSubscribed);
}

return $searchResults;
}

/**
* Set Is Subscribed extension attribute
*
Expand Down
6 changes: 1 addition & 5 deletions app/code/Magento/Newsletter/etc/extension_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Customer\Api\Data\CustomerInterface">
<attribute code="is_subscribed" type="boolean" >
<join reference_table="newsletter_subscriber" reference_field="customer_id" join_on_field="entity_id">
<field>subscriber_status</field>
</join>
</attribute>
<attribute code="is_subscribed" type="boolean"/>
</extension_attributes>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,18 @@ public function testCustomerWithZeroStoreIdIsSubscribed()
$this->assertEquals($customer->getId(), (int)$subscriber->getCustomerId());
$this->assertEquals($currentStore, (int)$subscriber->getStoreId());
}

/**
* Test get list customer, which have more then 2 subscribes in newsletter_subscriber.
*
* @magentoAppArea frontend
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
*/
public function testCustomerWithTwoNewsLetterSubscriptions()
{
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
$searchBuilder = Bootstrap::getObjectManager()->create(\Magento\Framework\Api\SearchCriteriaBuilder::class);
$searchCriteria = $searchBuilder->addFilter('entity_id', 1)->create();
$this->customerRepository->getList($searchCriteria);
}
}

0 comments on commit f5cc98e

Please sign in to comment.