Skip to content

Commit 29832c4

Browse files
committed
Merge branch 'MC-41092' of https://github.com/magento-l3/magento2ce into PR-20210423
2 parents 1061a2f + 7a1bf47 commit 29832c4

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model\Export\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
11+
use Magento\CatalogImportExport\Model\Export\ProductFilterInterface;
12+
13+
/**
14+
* Website filter for products export
15+
*/
16+
class WebsiteFilter implements ProductFilterInterface
17+
{
18+
private const NAME = 'website_id';
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public function filter(Collection $collection, array $filters): Collection
24+
{
25+
if (!isset($filters[self::NAME])) {
26+
return $collection;
27+
}
28+
29+
$collection->addWebsiteFilter($filters[self::NAME]);
30+
31+
return $collection;
32+
}
33+
}

app/code/Magento/CatalogImportExport/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<argument name="filters" xsi:type="array">
4949
<item name="category_ids" xsi:type="object">Magento\CatalogImportExport\Model\Export\Product\CategoryFilter</item>
5050
<item name="quantity_and_stock_status" xsi:type="object">Magento\CatalogImportExport\Model\Export\Product\StockStatusFilter</item>
51+
<item name="website_ids" xsi:type="object">Magento\CatalogImportExport\Model\Export\Product\WebsiteFilter</item>
5152
</argument>
5253
</arguments>
5354
</type>

app/code/Magento/ImportExport/Controller/Adminhtml/Export/Export.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function execute()
7676
{
7777
if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) {
7878
try {
79-
$params = $this->getRequest()->getParams();
79+
$params = $this->getRequestParameters();
8080

8181
if (!array_key_exists('skip_attr', $params)) {
8282
$params['skip_attr'] = [];
@@ -109,4 +109,14 @@ public function execute()
109109
$resultRedirect->setPath('adminhtml/*/index');
110110
return $resultRedirect;
111111
}
112+
113+
/**
114+
* Retrieve all params as array
115+
*
116+
* @return array
117+
*/
118+
public function getRequestParameters(): array
119+
{
120+
return $this->getRequest()->getParams();
121+
}
112122
}

app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public function filterEntityCollection(AbstractCollection $collection)
158158
$attributeCode,
159159
['eq' => $exportFilter[$attributeCode]]
160160
);
161+
} else if (is_array($exportFilter[$attributeCode])) {
162+
$collection->addAttributeToFilter(
163+
$attributeCode,
164+
['in' => $exportFilter[$attributeCode]]
165+
);
161166
}
162167
} elseif (Export::FILTER_TYPE_MULTISELECT == $attributeFilterType) {
163168
if (is_array($exportFilter[$attributeCode])) {

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,26 @@ public function filterByQuantityAndStockStatusDataProvider(): array
691691
];
692692
}
693693

694+
/**
695+
* Test that Product Export takes into account filtering by Website
696+
*
697+
* Fixtures provide two products, one assigned to default website only,
698+
* and the other is assigned to to default and custom websites. Only product assigned custom website is exported
699+
*
700+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_options.php
701+
* @magentoDataFixture Magento/Catalog/_files/product_with_two_websites.php
702+
*/
703+
public function testExportProductWithRestrictedWebsite(): void
704+
{
705+
$websiteRepository = $this->objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class);
706+
$website = $websiteRepository->get('second_website');
707+
708+
$exportData = $this->doExport(['website_id' => $website->getId()]);
709+
710+
$this->assertStringContainsString('"Simple Product"', $exportData);
711+
$this->assertStringNotContainsString('"Virtual Product With Custom Options"', $exportData);
712+
}
713+
694714
/**
695715
* Perform export
696716
*

0 commit comments

Comments
 (0)