Description
Preconditions (*)
magento/product-community-edition 2.3.2
Steps to reproduce (*)
I'm trying to modify the customer filters. See <backend>/customer/index/index
, click Filters, change a value and click Apply Filters. I'm trying to say "for this particular filter, also search for null values".
The documentation for \Magento\Framework\Api\Search\FilterGroup
says that it "Groups two or more filters together using a logical OR" so in theory I just need to add an extra filter to the filter group.
To achieve this I've created a di.xml as follows:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\Api\Search\ReportingInterface">
<plugin name="customer_grid_collection" type="Vendor\Module\Plugin\Reporting"/>
</type>
</config>
The plugin class has:
public function beforeSearch(ReportingInterface $subject, SearchCriteriaInterface $searchCriteria)
{
foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
foreach ($filterGroup->getFilters() as $filter) {
if ($myConditionsAreMet) {
$filterGroup->setFilters(array_merge(
$filterGroup->getFilters(),
[new Filter([
'field' => $filter->getField(),
'value' => true,
'condition_type' => 'null',
])]
));
return [$searchCriteria];
}
}
}
return [$searchCriteria];
}
To debug this I have another function in the plugin class:
public function afterSearch(ReportingInterface $subject, SearchResultInterface $collection)
{
$this->log($collection->getSelect()->__toString());
return $collection;
}
Actual result (*)
The afterSearch function outputs the following:
SELECT `main_table`.* FROM `customer_grid_flat` AS `main_table`
WHERE (`my_field` LIKE \'%value%\') AND (`my_field` IS NULL)
The filters are AND'd together. This is the same as #4287 which says that the issue has been fixed. Rather than re-open it I thought I would post my issue here.
Looking at \Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool
the applyFilters
function loops through each group, then each filter, and applies each filter one at a time, completely ignoring the fact that groups should be processed together. So even if I were to create my own filterApplier here, it won't fix my problem since my applier will receive the filters one at a time.
Expected result (*)
I would expect to see, as per the intended behaviour of FilterGroup
, for my filters to be OR'd together like the following:
... WHERE ((`my_field` LIKE \'%value%\') OR (`my_field` IS NULL))
Thank you.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status