magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Cannot use processFilter on product Collection

Open jaydainn opened this issue 6 months ago • 2 comments

Preconditions and environment

  • 2.4.6-p11
  • Magento 2 EE

Steps to reproduce

  1. Create a product collection using a productCollectionFactory
  2. Create Multiple Filters Using filterBuilder on different product attributes
  3. Create a filter group using a filterGroupBuilder and the previously created filters.
  4. Create a Search Criteria using SearchCriteriaBuilder with the previously created group of filters.
  5. Use the FilterProcessor Class and the process function to filter this collection using the search Criteria
  6. It will fail
{
$filters = [];
$data = "black"

    $filters[] = $this->filterBuilder
     ->setField('description')
     ->setValue($data)
     ->setConditionType('eq')
     ->create();

    $filters[] = $this->filterBuilder
     ->setField('color')
     ->setValue($data)
     ->setConditionType('eq')
     ->create();

    $filters[] = $this->filterBuilder
     ->setField('country_of_manufacture')
     ->setValue($data)
     ->setConditionType('eq')
     ->create();

    // Create a filter group with OR logic
    $filterGroup = $this->filterGroupBuilder
     ->setFilters($filters)
     ->create();

    // Build search criteria
    $searchCriteria = $this->searchCriteriaBuilder
     ->setFilterGroups([$filterGroup])
     ->create();


    $this->collection = $this->productCollectionFactory->create();
    $this->collection->addAttributeToSelect('*');

    // Apply the search criteria to the collection
    $this->filterProcessor->process($searchCriteria, $this->collection);
    $this->collection->load();
    return $this->collection->getFirstItem(); 
}

Expected result

Get the products from the collection with the correct filters.

Actual result

Cannot access offset of type string on string at /var/www/src/vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php:373

It seems that in the addAttributeToFilter function from module eav the condition parameter from the function is never used and actually replaced by the attribute array passed in the function.

Additional information

No response

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

jaydainn avatar Jun 20 '25 08:06 jaydainn

Hi @jaydainn. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar Jun 20 '25 08:06 m2-assistant[bot]

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jun 20 '25 09:06 m2-assistant[bot]

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jun 24 '25 12:06 m2-assistant[bot]

Hello @jaydainn,

Thanks for the report and collaboration!

We are able to reproduce this issue in the latest development branch i.e. 2.4-develop. In order to reproduce this issue we have created a custom module, the exact same error we are getting.

Hence confirming the issue.

Thanks

engcom-Hotel avatar Jun 25 '25 13:06 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-15018 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Jun 25 '25 13:06 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Jun 25 '25 13:06 m2-assistant[bot]