Description
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
Type
Projects
Status