سؤال

I want to display all my store products on one page, with a side menu to 'filter' on the available categories. Basicly the same view as a single categorie product list, but then with all products (of Default Category) and all main categories on the side bar. I've been searching the internet for two days and haven't found any (working) solution.

I'm using Magento 2.1, with a premium paid theme (Porto).

I've tried creating a page with this code as content:

{{block type="catalog/product_list" name="all.products.list" alias="products_list" category_id="2" template="catalog/product/list.phtml"}}

and adding XML in the design field.

<reference name="content">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>3</category_id></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name>
</action>
</block>
</reference>

However, the XML gets rejected and the content code doesn't show any products.

Is this such a 'hard' thing to do? I would expect Magento just having an overview of all products somewhere, but I can't seem to find it.

هل كانت مفيدة؟

المحلول

First thing you are using the Magento 1 code that will not work on Magneto2.

Add these xml and try it.

<referenceContainer name="content">
<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                    <container name="category.product.list.additional" as="additional" />
                    <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                        <block class="Magento\Framework\View\Element\Template" as="default"/>
                    </block>
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                        <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                               name="category.product.addto.compare" as="compare"
                               template="Magento_Catalog::product/list/addto/compare.phtml"/>
                    </block>
                    <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                        <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>


                    </block>
                    <action method="setToolbarBlockName">
                        <argument name="name" xsi:type="string">product_list_toolbar</argument>
                    </action>
                </block>
        </referenceContainer>


    <referenceContainer name="sidebar.main">
        <block class="Magento\LayeredNavigation\Block\Navigation\Category" name="catalog.leftnav" before="-" template="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="layer/filter.phtml"/>
        </block>
    </referenceContainer>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top