Skip to content

Commit 92c4f36

Browse files
committed
ACP2E-3720: Missing Website Filter Option in Export Process
1 parent a68324b commit 92c4f36

File tree

14 files changed

+306
-30
lines changed

14 files changed

+306
-30
lines changed

app/code/Magento/AdvancedPricingImportExport/Controller/Adminhtml/Export/GetFilter.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
namespace Magento\AdvancedPricingImportExport\Controller\Adminhtml\Export;
78

9+
use Magento\Backend\App\Action\Context;
810
use Magento\Framework\App\Action\HttpGetActionInterface;
911
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1012
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
1113
use Magento\Framework\Controller\ResultFactory;
1214
use Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing as ExportAdvancedPricing;
1315
use Magento\Catalog\Model\Product as CatalogProduct;
16+
use Magento\ImportExport\Model\Export\EntityFiltersProviderInterface;
1417

1518
class GetFilter extends ExportController implements HttpGetActionInterface, HttpPostActionInterface
1619
{
20+
/**
21+
* @param Context $context
22+
* @param EntityFiltersProviderInterface $filtersProvider
23+
*/
24+
public function __construct(
25+
Context $context,
26+
private readonly EntityFiltersProviderInterface $filtersProvider
27+
) {
28+
parent::__construct($context);
29+
}
30+
1731
/**
1832
* Get grid-filter of entity attributes action.
1933
*
@@ -34,9 +48,7 @@ public function execute()
3448
/** @var $export \Magento\ImportExport\Model\Export */
3549
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3650
$export->setData($data);
37-
$attrFilterBlock->prepareCollection(
38-
$export->filterAttributeCollection($export->getEntityAttributeCollection())
39-
);
51+
$attrFilterBlock->prepareCollection($this->filtersProvider->getFilters($export));
4052
return $resultLayout;
4153
} catch (\Exception $e) {
4254
$this->messageManager->addErrorMessage($e->getMessage());

app/code/Magento/AdvancedPricingImportExport/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"require": {
88
"php": "~8.2.0||~8.3.0||~8.4.0",
99
"magento/framework": "*",
10+
"magento/module-backend": "*",
1011
"magento/module-catalog": "*",
1112
"magento/module-catalog-import-export": "*",
1213
"magento/module-catalog-inventory": "*",

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2015 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -19,4 +19,11 @@
1919
</arguments>
2020
</type>
2121
<preference for="Magento\ImportExport\Controller\Adminhtml\Export\GetFilter" type="Magento\AdvancedPricingImportExport\Controller\Adminhtml\Export\GetFilter" />
22+
<type name="Magento\ImportExport\Model\Export\EntityFiltersProvider">
23+
<arguments>
24+
<argument name="providers" xsi:type="array">
25+
<item name="advanced_pricing" xsi:type="object">Magento\CatalogImportExport\Model\Export\EntityFiltersProvider</item>
26+
</argument>
27+
</arguments>
28+
</type>
2229
</config>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model\Export;
9+
10+
use Magento\ImportExport\Model\Export;
11+
use Magento\ImportExport\Model\Export\EntityFiltersProviderInterface;
12+
13+
class EntityFiltersProvider implements EntityFiltersProviderInterface
14+
{
15+
/**
16+
* @param array[] $additionalFilters
17+
*/
18+
public function __construct(
19+
private readonly array $additionalFilters = []
20+
) {
21+
}
22+
23+
/**
24+
* @inheritDoc
25+
*/
26+
public function getFilters(Export $export): \Magento\Framework\Data\Collection
27+
{
28+
$collection = $export->filterAttributeCollection($export->getEntityAttributeCollection());
29+
foreach ($this->additionalFilters as $data) {
30+
$attribute = $collection->getNewEmptyItem();
31+
$attribute->setId($data['attribute_code']);
32+
foreach ($data as $key => $value) {
33+
$attribute->setDataUsingMethod($key, $value);
34+
}
35+
$collection->addItem($attribute);
36+
}
37+
38+
return $collection;
39+
}
40+
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\CatalogImportExport\Model\Export\Product;
@@ -15,19 +16,21 @@
1516
*/
1617
class WebsiteFilter implements ProductFilterInterface
1718
{
18-
private const NAME = 'website_id';
19+
private const WEBSITE_ID = 'website_id';
20+
private const WEBSITE_IDS = 'website_ids';
1921

2022
/**
2123
* @inheritDoc
2224
*/
2325
public function filter(Collection $collection, array $filters): Collection
2426
{
25-
if (!isset($filters[self::NAME])) {
27+
if (!isset($filters[self::WEBSITE_ID]) && !isset($filters[self::WEBSITE_IDS])) {
2628
return $collection;
2729
}
2830

29-
$collection->addWebsiteFilter($filters[self::NAME]);
30-
$collection->setFlag(self::NAME . '_filter_applied');
31+
$collection->addWebsiteFilter($filters[self::WEBSITE_IDS] ?? $filters[self::WEBSITE_ID]);
32+
$collection->setFlag(self::WEBSITE_ID . '_filter_applied');
33+
$collection->setFlag(self::WEBSITE_IDS . '_filter_applied');
3134

3235
return $collection;
3336
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model\Export\Product;
9+
10+
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
13+
class WebsiteFilterOptions extends AbstractSource
14+
{
15+
/**
16+
* @param StoreManagerInterface $storeManager
17+
*/
18+
public function __construct(
19+
private readonly StoreManagerInterface $storeManager
20+
) {
21+
}
22+
23+
/**
24+
* @inheritDoc
25+
*/
26+
public function getAllOptions()
27+
{
28+
return array_map(
29+
fn ($website) => ['value' => $website->getId(), 'label' => $website->getName()],
30+
$this->storeManager->getWebsites(false)
31+
);
32+
}
33+
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2013 Adobe
5+
* All Rights Reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
@@ -58,4 +58,24 @@
5858
</argument>
5959
</arguments>
6060
</type>
61+
<type name="Magento\ImportExport\Model\Export\EntityFiltersProvider">
62+
<arguments>
63+
<argument name="providers" xsi:type="array">
64+
<item name="catalog_product" xsi:type="object">Magento\CatalogImportExport\Model\Export\EntityFiltersProvider</item>
65+
</argument>
66+
</arguments>
67+
</type>
68+
<type name="Magento\CatalogImportExport\Model\Export\EntityFiltersProvider">
69+
<arguments>
70+
<argument name="additionalFilters" xsi:type="array">
71+
<item name="website_ids" xsi:type="array">
72+
<item name="attribute_code" xsi:type="string">website_ids</item>
73+
<item name="default_frontend_label" xsi:type="string" translatable="true">Websites</item>
74+
<item name="backend_type" xsi:type="string">int</item>
75+
<item name="frontend_input" xsi:type="string">multiselect</item>
76+
<item name="source_model" xsi:type="string">Magento\CatalogImportExport\Model\Export\Product\WebsiteFilterOptions</item>
77+
</item>
78+
</argument>
79+
</arguments>
80+
</type>
6181
</config>

app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
namespace Magento\ImportExport\Block\Adminhtml\Export;
78

89
use Magento\Eav\Model\Entity\Attribute;
@@ -27,8 +28,6 @@ class Filter extends \Magento\Backend\Block\Widget\Grid\Extended
2728
protected $_helper;
2829

2930
/**
30-
* Import export data
31-
*
3231
* @var \Magento\ImportExport\Helper\Data
3332
*/
3433
protected $_importExportData = null;
@@ -167,7 +166,7 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
167166
$arguments = [
168167
'name' => $this->getFilterElementName($attribute->getAttributeCode()) . '[]',
169168
'id' => $this->getFilterElementId($attribute->getAttributeCode()),
170-
'class' => 'multiselect multiselect-export-filter',
169+
'class' => 'admin__control-multiselect multiselect multiselect-export-filter',
171170
'extra_params' => 'multiple="multiple" size="' . ($size > 5 ? 5 : ($size < 2 ? 2 : $size)) . '"',
172171
];
173172
/** @var $selectBlock \Magento\Framework\View\Element\Html\Select */
@@ -176,7 +175,7 @@ protected function _getMultiSelectHtmlWithValue(Attribute $attribute, $value)
176175
'',
177176
['data' => $arguments]
178177
);
179-
return $selectBlock->setOptions($options)->setValue($value)->getHtml();
178+
return $selectBlock->setOptions($options)->setValue($value !== '' ? $value : null)->getHtml();
180179
} else {
181180
return __('We can\'t filter an attribute with no attribute options.');
182181
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
namespace Magento\ImportExport\Controller\Adminhtml\Export;
78

9+
use Magento\Backend\App\Action\Context;
810
use Magento\Framework\App\Action\HttpGetActionInterface;
911
use Magento\Framework\App\Action\HttpPostActionInterface;
1012
use Magento\ImportExport\Controller\Adminhtml\Export as ExportController;
1113
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\ImportExport\Model\Export\EntityFiltersProviderInterface;
1215

1316
class GetFilter extends ExportController implements HttpGetActionInterface, HttpPostActionInterface
1417
{
18+
19+
/**
20+
* @param Context $context
21+
* @param EntityFiltersProviderInterface $filtersProvider
22+
*/
23+
public function __construct(
24+
Context $context,
25+
private readonly EntityFiltersProviderInterface $filtersProvider
26+
) {
27+
parent::__construct($context);
28+
}
29+
1530
/**
1631
* Get grid-filter of entity attributes action.
1732
*
@@ -30,9 +45,7 @@ public function execute()
3045
$export = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
3146
$export->setData($data);
3247

33-
$export->filterAttributeCollection(
34-
$attrFilterBlock->prepareCollection($export->getEntityAttributeCollection())
35-
);
48+
$attrFilterBlock->prepareCollection($this->filtersProvider->getFilters($export));
3649
return $resultLayout;
3750
} catch (\Exception $e) {
3851
$this->messageManager->addErrorMessage($e->getMessage());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ImportExport\Model\Export;
9+
10+
use Magento\ImportExport\Model\Export;
11+
12+
class EntityFiltersProvider implements EntityFiltersProviderInterface
13+
{
14+
/**
15+
* @param EntityFiltersProviderInterface[] $providers
16+
*/
17+
public function __construct(
18+
private readonly array $providers = []
19+
) {
20+
// validate that all providers implement the interface
21+
array_map(fn (EntityFiltersProviderInterface $provider) => $provider, $this->providers);
22+
}
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
public function getFilters(Export $export): \Magento\Framework\Data\Collection
28+
{
29+
return isset($this->providers[$export->getEntity()])
30+
? $this->providers[$export->getEntity()]->getFilters($export)
31+
: $export->filterAttributeCollection($export->getEntityAttributeCollection());
32+
}
33+
}

0 commit comments

Comments
 (0)