Skip to content

Cannot use processFilter on product Collection #40014

Open
@jaydainn

Description

@jaydainn

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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.6Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions