Skip to content

Adding created_at, status and grand_total filters to customer Orders query and fixing multiple filters failure #36949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class OrderFilter
*/
private $fieldTranslatorArray = [
'number' => 'increment_id',
'order_date' => 'created_at',
'grand_total' => 'base_grand_total',
];

/**
Expand Down Expand Up @@ -85,7 +87,6 @@ public function createFilterGroups(
$filterGroups[] = $this->filterGroupBuilder->create();

if (isset($args['filter'])) {
$filters = [];
foreach ($args['filter'] as $field => $cond) {
if (isset($this->fieldTranslatorArray[$field])) {
$field = $this->fieldTranslatorArray[$field];
Expand All @@ -96,21 +97,21 @@ public function createFilterGroups(
throw new InputException(__('Invalid match filter'));
}
$searchValue = $value !== null ? str_replace('%', '', $value) : '';
$filters[] = $this->filterBuilder->setField($field)
$filter = $this->filterBuilder->setField($field)
->setValue("%{$searchValue}%")
->setConditionType('like')
->create();
} else {
$filters[] = $this->filterBuilder->setField($field)
$filter = $this->filterBuilder->setField($field)
->setValue($value)
->setConditionType($condType)
->create();
}
}
}

$this->filterGroupBuilder->setFilters($filters);
$filterGroups[] = $this->filterGroupBuilder->create();
$this->filterGroupBuilder->setFilters([$filter]);
$filterGroups[] = $this->filterGroupBuilder->create();
}
}
return $filterGroups;
}
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/SalesGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ type Customer {
}

input CustomerOrdersFilterInput @doc(description: "Identifies the filter to use for filtering orders.") {
order_date: FilterRangeTypeInput @doc(description: "Filters by order created_at time.")
status: FilterEqualTypeInput @doc(description: "Filters by order status.")
number: FilterStringTypeInput @doc(description: "Filters by order number.")
grand_total: FilterRangeTypeInput @doc(description: "Filters by order base grand total value.")
}

input CustomerOrderSortInput @doc(description: "CustomerOrderSortInput specifies the field to use for sorting search results and indicates whether the results are sorted in ascending or descending order.") {
Expand Down