Skip to content

Commit af92b91

Browse files
committed
MAGETWO-54253: Export filters for products do not work
1 parent 54882fe commit af92b91

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Export;
77

8-
use Magento\Framework\DB\Ddl\Table;
98
use Magento\ImportExport\Model\Import;
109
use \Magento\Store\Model\Store;
1110
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
@@ -850,6 +849,24 @@ public function export()
850849
return $writer->getContents();
851850
}
852851

852+
/**
853+
* {@inheritdoc}
854+
*/
855+
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
856+
{
857+
$exportFilter = !empty($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP]) ?
858+
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP] : [];
859+
860+
if (isset($exportFilter['category_ids'])
861+
&& trim($exportFilter['category_ids'])
862+
&& $collection instanceof \Magento\Catalog\Model\ResourceModel\Product\Collection
863+
) {
864+
$collection->addCategoriesFilter(['in' => explode(',', $exportFilter['category_ids'])]);
865+
}
866+
867+
return parent::_prepareEntityCollection($collection);
868+
}
869+
853870
/**
854871
* Get export data for collection
855872
*

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,31 @@ public function testExportWithFieldsEnclosure()
230230
$this->assertContains('""Option 4 """"!@#$%^&*"""', $exportData);
231231
$this->assertContains('text_attribute=""!@#$%^&*()_+1234567890-=|\:;"""', $exportData);
232232
}
233+
234+
/**
235+
* Verify that "category ids" filter correctly applies to export result
236+
*
237+
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_categories.php
238+
*/
239+
public function testCategoryIdsFilter()
240+
{
241+
$this->model->setWriter(
242+
$this->objectManager->create(
243+
\Magento\ImportExport\Model\Export\Adapter\Csv::class
244+
)
245+
);
246+
247+
$this->model->setParameters([
248+
\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP => [
249+
'category_ids' => '2,13'
250+
]
251+
]);
252+
253+
$exportData = $this->model->export();
254+
255+
$this->assertContains('Simple Product', $exportData);
256+
$this->assertContains('Simple Product Three', $exportData);
257+
$this->assertNotContains('Simple Product Two', $exportData);
258+
$this->assertNotContains('Simple Product Not Visible On Storefront', $exportData);
259+
}
233260
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
8+
9+
require dirname(dirname(__DIR__)) . '/Catalog/_files/categories.php';

0 commit comments

Comments
 (0)