File tree Expand file tree Collapse file tree 5 files changed +70
-1
lines changed
Controller/Adminhtml/Export
dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export Expand file tree Collapse file tree 5 files changed +70
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 48
48
<argument name =" filters" xsi : type =" array" >
49
49
<item name =" category_ids" xsi : type =" object" >Magento\CatalogImportExport\Model\Export\Product\CategoryFilter</item >
50
50
<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 >
51
52
</argument >
52
53
</arguments >
53
54
</type >
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ public function execute()
76
76
{
77
77
if ($ this ->getRequest ()->getPost (ExportModel::FILTER_ELEMENT_GROUP )) {
78
78
try {
79
- $ params = $ this ->getRequest ()-> getParams ();
79
+ $ params = $ this ->getRequestParameters ();
80
80
81
81
if (!array_key_exists ('skip_attr ' , $ params )) {
82
82
$ params ['skip_attr ' ] = [];
@@ -109,4 +109,14 @@ public function execute()
109
109
$ resultRedirect ->setPath ('adminhtml/*/index ' );
110
110
return $ resultRedirect ;
111
111
}
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
+ }
112
122
}
Original file line number Diff line number Diff line change @@ -158,6 +158,11 @@ public function filterEntityCollection(AbstractCollection $collection)
158
158
$ attributeCode ,
159
159
['eq ' => $ exportFilter [$ attributeCode ]]
160
160
);
161
+ } else if (is_array ($ exportFilter [$ attributeCode ])) {
162
+ $ collection ->addAttributeToFilter (
163
+ $ attributeCode ,
164
+ ['in ' => $ exportFilter [$ attributeCode ]]
165
+ );
161
166
}
162
167
} elseif (Export::FILTER_TYPE_MULTISELECT == $ attributeFilterType ) {
163
168
if (is_array ($ exportFilter [$ attributeCode ])) {
Original file line number Diff line number Diff line change @@ -691,6 +691,26 @@ public function filterByQuantityAndStockStatusDataProvider(): array
691
691
];
692
692
}
693
693
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
+
694
714
/**
695
715
* Perform export
696
716
*
You can’t perform that action at this time.
0 commit comments