Magento2 - 具有分层导航的定制产品系列

kas*_*spi 9 magento2

我正在尝试使用自定义产品列表在自定义页面上显示分层导航块.

现在我有自定义控制器,xml布局和产品列表模板.

  1. 我需要在xml布局中插入什么来显示分层导航块?

<referenceContainer name="sidebar.main"> <!-- ??? --> </referenceContainer>

  1. 如何设置自定义产品集合(按属性过滤,例如'book'== 1)并在自定义页面上使用它(带分层导航)(例如带有作者过滤器的书籍列表)?

Tom*_*omS 1

您需要的 XML 可以在 Magento/LayeredNavigation/view/frontend/layout/catalog_category_view_type_layered.xml 中找到

您需要添加到 ReferenceContainer 的代码片段是:

<block class="Magento\LayeredNavigation\Block\Navigation\Category" name="catalog.leftnav" before="-" template="Magento_LayeredNavigation::layer/view.phtml">
            <block class="Magento\LayeredNavigation\Block\Navigation\State" name="catalog.navigation.state" as="state" />
            <block class="Magento\LayeredNavigation\Block\Navigation\FilterRenderer" name="catalog.navigation.renderer" as="renderer" template="Magento_LayeredNavigation::layer/filter.phtml"/>
</block>
Run Code Online (Sandbox Code Playgroud)

如果您想设置默认过滤器,我建议使用插件来修改“Magento\LayeredNavigation\Block\Navigation\FilterRenderer”的渲染方法。