Skip to content

Breaking BC changes in the product list block #32268

Closed
@tzyganu

Description

@tzyganu

Summary (*)

The \Magento\Catalog\Block\Product\ListProduct::getLoadedProductCollection is breaking BC (feel free to challenge it) in the 2.4 version.
In 2.4 the method looks like this:

    public function getLoadedProductCollection()
    {
        $collection = $this->_getProductCollection();

        $categoryId = $this->getLayer()->getCurrentCategory()->getId();
        foreach ($collection as $product) {
            $product->setData('category_id', $categoryId);
        }

        return $collection;
    }

In 2.3 and before it looked like this:

    public function getLoadedProductCollection()
    {
        return $this->_getProductCollection();
    }

The collection iteration inside the method in 2.4 causes the collection to load the db data so any after plugin or around plugin that calls the original method and tries to affect the collection does nothing to it in 2.4.

Examples (*)

Let's consider this plugin.

public function afterGetLoadedProductCollection(
    \Magento\Catalog\Block\Product\ListProduct $subject, 
    \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
) {
    return $collection->addAttributeToFilter('some_attribute_code', 'some_value');
}

In 2.3 and before, this would cause the product list to filter only products that have the value some_value for the attribute with code some_attribute_code (beside the default filters).
In 2.4 this filter has no effect because the collection is already loaded when adding the filter.

Proposed solution

Move the assign operation of category ids to products to the _beforeToHtml method in the same class after

        if (!$collection->isLoaded()) {
            $collection->load();
        }

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users with no 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

Labels

Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: ready for confirmationPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.Severity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions