Skip to content

Product list toolbar may not be configured properly depends on layout customization #41121

Description

@ryansunxl

Summary

product_list_toolbar is being used in both Magento\LayeredNavigation\Block\Navigation::configureToolbarBlock() and Magento\Catalog\Block\Product\ListProduct::configureToolbar(), but are implemented differently.
ListProduct block fully configures toolbar with all options, while Navigation simply sets product collection on the toolbar.

The problem is toolbar would cache some of the options and depends on which block gets to configure the toolbar first, we gets different result on the search page. When ListProduct is rendered first, it would defaults to sorting by relevance, which works as expected, when Navigation is rendered first, it would defaults to position, and that default value is cached in

$this->setData('_current_grid_order', $order);
and later be used to render the product list, causing the sorting of the search result wrong.

This can be replicated by creating a custom layout 2columns-left.xml with content below

Examples

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <move element="div.sidebar.main" destination="columns" before="main"/>
</layout>

Proposed solution

Add a reset method in Toolbar block and call it before all configureToolbar methods.
Or if performance is a concern and for better architecture, decouple toolbar configuration, configure product collection on service level and have all blocks honor the collection options, which is a big endeavor and could break backward compatibility.

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

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions