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
Summary
product_list_toolbaris being used in bothMagento\LayeredNavigation\Block\Navigation::configureToolbarBlock()andMagento\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 toposition, and that default value is cached inmagento2/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php
Line 291 in 8b67e8e
This can be replicated by creating a custom layout 2columns-left.xml with content below
Examples
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