Skip to content

Category Page Sorting does not work if a custom block uses Magento\Catalog\Block\Product\ListProduct.php  #27401

Description

@arptg

Preconditions (*)

  1. Magento2.3.4
  2. Magento 2.4-develop

Steps to reproduce (*)

  1. Add a custom block which uses or extends Magento\Catalog\Block\Product\ListProduct.php.
  2. For the template get all the products using $block->getLoadedProductCollection();
  • layout - catalog_category_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Catalog\Block\Product\ListProduct" name="product.detail.sorttest" template="Vendor_Module::schema.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>
  • contents of the block file.
<?php $products = $block->getLoadedProductCollection();
echo "already here"; ?>
<?php  if($products->count()) : ?>
    <?php foreach($products as $product): ?>
        <div> <?php echo $product->getId(); ?> </div>
    <?php endforeach; ?>
<?php endif; ?>

Expected result (*)

  1. Product Sorting in category page should work.

Actual result (*)

  1. Product Sort does not work.
    Peek 2021-01-05 13-55

This used to work on Magento 2.1.10 .

I am using the given method to get all the products currently visible in the category page. Can anyone suggest any other method instead ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P4No current plan to fix. Fixing can be deferred as a logical part of more important work.Progress: doneReported on 2.3.4Indicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itstale issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions