Skip to content

#33387: fix GraphQl products query layered navigation category child #33547

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

Conversation

korovitskyi
Copy link
Collaborator

Description (*)

It was investigated the category grid page -> category filters. There we check the category filter by current category ID and children.
In the same way, was added a point to \Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search to modify the aggregation category by searchable category ID. As for me, it is the best point, as we must know if request queries have been filtered by category_id and know ID value(s).
Reopen by #33520.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes GraphQl products query layered navigation filters return incorrect child categories list #33387

Manual testing scenarios (*)

Send request and the count of categories should be 4:

query { 
  products(filter: {category_id: {eq: "21"}}) {
    aggregations {
      attribute_code
      count
      label
      options { 
        count
        label
        value 
      } 
    }
  } 
}
query { 
  products(filter: {category_id: {in: ["21"]}}) {
    aggregations {
      attribute_code
      count
      label
      options { 
        count
        label
        value 
      } 
    }
  } 
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jul 21, 2021

Hi @korovitskyi. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jul 21, 2021
@magento-engcom-team magento-engcom-team added Component: CatalogGraphQl Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Jul 21, 2021
Copy link
Contributor

@andrewbess andrewbess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
Thank you for your contribution.
Could you please add some fixes?
Thank you in advance

Comment on lines 80 to 83
* @param array $categoryFilter
* @param Bucket[] $bucketList
*
* @return Aggregation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
Could you please merge tags to the common block?
Remove redundant line.

Suggested change
* @param array $categoryFilter
* @param Bucket[] $bucketList
*
* @return Aggregation
* @param array $categoryFilter
* @param Bucket[] $bucketList
* @return Aggregation

if (!$searchableCategoryValue || empty($values)) {
return $this->aggregationFactory->create([self::BUCKETS => $bucketList]);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove redundant line

Comment on lines 113 to 120

$resolvedCategoryBucket = $this->bucketFactory->create(
[
'name' => self::CATEGORY_BUCKET,
'values' => $resolvedValues
]
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove redundant lines

Suggested change
$resolvedCategoryBucket = $this->bucketFactory->create(
[
'name' => self::CATEGORY_BUCKET,
'values' => $resolvedValues
]
);
$resolvedCategoryBucket = $this->bucketFactory->create(
[
'name' => self::CATEGORY_BUCKET,
'values' => $resolvedValues
]
);

Comment on lines 129 to 134
* @param int $searchableCategoryId
* @param AggregationValueInterface[] $aggregationValues
*
* @return AggregationValueInterface[]
*
* @throws NoSuchEntityException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
Could you please merge tags to the common block?
Remove redundant lines.

Suggested change
* @param int $searchableCategoryId
* @param AggregationValueInterface[] $aggregationValues
*
* @return AggregationValueInterface[]
*
* @throws NoSuchEntityException
* @param int $searchableCategoryId
* @param AggregationValueInterface[] $aggregationValues
* @return AggregationValueInterface[]
* @throws NoSuchEntityException

*/
private function getValidCategories(int $searchableCategoryId, array $aggregationValues): array
{
$stareId = (int) $this->storeManager->getStore()->getId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
Perhaps this is typo ($stareId should be named $storeId)

Comment on lines 155 to 159
if (!in_array($childCategoryId, $validChildIdList) ||
in_array($childCategoryId, $this->resolvedChildrenIds)
) {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
Could you please fix it according to PSR-12 requirements and examples https://www.php-fig.org/psr/psr-12/ (see p.5.1)

Suggested change
if (!in_array($childCategoryId, $validChildIdList) ||
in_array($childCategoryId, $this->resolvedChildrenIds)
) {
continue;
}
if (
!in_array($childCategoryId, $validChildIdList)
||. in_array($childCategoryId, $this->resolvedChildrenIds)
) {
continue;
}

}

/**
* Check is valid searchable category children.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
This method not only checks, but returns list of categories, right?
This summary can confuse.
Could you please fix it?

@@ -84,6 +91,7 @@ public function __construct(
$this->fieldSelection = $fieldSelection;
$this->productsProvider = $productsProvider;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->resolveCategoryAggregation = $resolveCategoryAggregation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @korovitskyi
These changes are backward incompatible.
Could you please fix it.

Comment on lines 102 to 109
* @param array $args
* @param ResolveInfo $info
* @param ContextInterface $context
*
* @return SearchResult
*
* @throws GraphQlInputException
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param array $args
* @param ResolveInfo $info
* @param ContextInterface $context
*
* @return SearchResult
*
* @throws GraphQlInputException
*/
* @param array $args
* @param ResolveInfo $info
* @param ContextInterface $context
* @return SearchResult
* @throws GraphQlInputException
*/

@korovitskyi
Copy link
Collaborator Author

Hi, @andrewbess .
Changes were added.
Thank you for the review.

@Den4ik Den4ik self-assigned this Aug 6, 2021
@Den4ik Den4ik self-requested a review August 6, 2021 11:56
@engcom-Charlie
Copy link
Contributor

Hi @korovitskyi,

Thanks for your contribution!

As per your comment, you have implemented the review changes so moving it for review.

@m2-assistant
Copy link

m2-assistant bot commented Oct 26, 2021

Hi @korovitskyi, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: CatalogGraphQl Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQl products query layered navigation filters return incorrect child categories list
5 participants