1

I have a catalog_category_view.xml and I try to change the toolbar.

<referenceBlock name="category.products.list">
    <action method="setDefaultListPerPage">
        <argument name="limit" xsi:type="string">20</argument>
    </action>
    <action method="setDefaultGridPerPage">
        <argument name="limit" xsi:type="string">20</argument>
    </action>
    <action method="addPagerLimit">
        <argument name="mode" xsi:type="string">list</argument>
        <argument name="limit" xsi:type="string">2</argument>
    </action>
</referenceBlock>

But it does not work.

1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Magento\Catalog\Block\Product\ListProduct\Interceptor::addPagerLimit

By default, Magento has:

<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"/>
        <!-- The following code shows how to set your own pager increments -->
        <!--
            <action method="setDefaultListPerPage">
            <argument name="limit" xsi:type="string">4</argument>
        </action>
        <action method="setDefaultGridPerPage">
            <argument name="limit" xsi:type="string">3</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">list</argument>
            <argument name="limit" xsi:type="string">2</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">list</argument>
            <argument name="limit" xsi:type="string">4</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">list</argument>
            <argument name="limit" xsi:type="string">6</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">list</argument>
            <argument name="limit" xsi:type="string">8</argument>
        </action>
        <action method="addPagerLimit" translate="label">
            <argument name="mode" xsi:type="string">list</argument>
            <argument name="limit" xsi:type="string">all</argument>
            <argument name="label" xsi:type="string">All</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">grid</argument>
            <argument name="limit" xsi:type="string">3</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">grid</argument>
            <argument name="limit" xsi:type="string">6</argument>
        </action>
        <action method="addPagerLimit">
            <argument name="mode" xsi:type="string">grid</argument>
            <argument name="limit" xsi:type="string">9</argument>
        </action>
        <action method="addPagerLimit" translate="label">
            <argument name="mode" xsi:type="string">grid</argument>
            <argument name="limit" xsi:type="string">all</argument>
            <argument name="label" xsi:type="string">All</argument>
        </action>
        -->
    </block>
    <action method="setToolbarBlockName">
        <argument name="name" xsi:type="string">product_list_toolbar</argument>
    </action>
</block>

How I can change configuration?

1

Now I found solution for change numbers from admin panel.

Go to Stores -> Configuration -> Catalog -> Catalog -> Storefront.

https://www.mageplaza.com/kb/how-to-configure-product-listings-magento-2.html

0

The reason you're getting that error is likely because you're calling the action on the wrong block type.

In the example that they give you, they're calling the action methods on the block:

<block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">

Try changing your referenceBlock name from category.products.list to product_list_toolbar.

  • Yes, I know about it. Same result: 1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Magento\Catalog\Block\Product\ProductList\Toolbar::addPagerLimit – Mykhailo Shatilov Nov 8 '16 at 19:44
  • github.com/magento/magento2/issues/1404 here you find solution – PG Sutariya Nov 29 '16 at 5:46
  • What is a toolbar, Can anyone explain – Jaisa Dec 21 '17 at 5:58
  • @Sri The toolbar in this instance refers to the block on the product list page that has the "Sort By" dropdown. – heraldo Jan 12 '18 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.