Skip to content

toolbar is not returning the selected products numbers per page

i have a problem with the functionality of the toolbar , i don’t know if it must work by default or i should implement its functionality. when i click on a number here, the page is refreshing and this appears in the url like it is working and it returns all products enter image description here

this is the code that returns products

<?php

use MagentoFrameworkAppActionAction;

?>

<section class="container-fluid two">
    <div class="all-products">



        <?php
        $_productCollection = clone $block->getLoadedProductCollection();
     



        $_helper = $this->helper(MagentoCatalogHelperOutput::class);
        ?>
        <?php if (!$_productCollection->count()) : ?>
        <div class="message info empty">
            <div><?= $block->escapeHtml(__('We can't find products matching the selection.')) ?></div>
        </div>
        <?php else : ?>
        <?= $block->getToolbarHtml() ?>
        <?= $block->getAdditionalHtml() ?>
        <?php
            if ($block->getMode() == 'grid') {
                $viewMode = 'grid';
                $image = 'category_page_grid';
                $showDescription = false;
                $templateType = MagentoCatalogBlockProductReviewRendererInterface::SHORT_VIEW;
            } else {
                $viewMode = 'list';
                $image = 'category_page_list';
                $showDescription = true;
                $templateType = MagentoCatalogBlockProductReviewRendererInterface::FULL_VIEW;
            }
            /**
             * Position for actions regarding image size changing in vde if needed
             */
            $pos = $block->getPositioned();
            ?>
        <div class="container <?= /* @noEscape */ $viewMode ?> products-<?= /* @noEscape */ $viewMode ?>">
            <?php $iterator = 1; ?>
            <div>
                <ol class='to-clear'>
                    <?php /** @var $_product MagentoCatalogModelProduct */ ?>
                    <?php foreach ($_productCollection as $_product) : ?>



                    <?= /* @noEscape */ ($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
                    <a class='product-wishlist' href="<?php echo $this->getUrl('wishlist') ?>">
                        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="black" class="bi bi-heart"
                            viewBox="0 0 16 16">
                            <path
                                d="m8 2.748-.717-.737C5.6.281 2.514.878 1.4 3.053c-.523 1.023-.641 2.5.314 4.385.92 1.815 2.834 3.989 6.286 6.357 3.452-2.368 5.365-4.542 6.286-6.357.955-1.886.838-3.362.314-4.385C13.486.878 10.4.28 8.717 2.01L8 2.748zM8 15C-7.333 4.868 3.279-3.04 7.824 1.143c.06.055.119.112.176.171a3.12 3.12 0 0 1 .176-.17C12.72-3.042 23.333 4.867 8 15z" />
                        </svg>
                    </a>
                    <div data-container="product-<?= /* @noEscape */ $viewMode ?>">
                        <?php
                                $productImage = $block->getImage($_product, $image);
                                if ($pos != null) {
                                    $position = ' style="left:' . $productImage->getWidth() . 'px;'
                                        . 'top:' . $productImage->getHeight() . 'px;"';
                                }
                                ?>
                        <?php // Product Image 
                                ?>
                        <a href="<?= $block->escapeUrl($_product->getProductUrl()) ?>" tabindex="-1">
                            <?= $productImage->toHtml() ?>
                        </a>
                        <div class="holder">
                            <?php
                                    $_productNameStripped = $block->stripTags($_product->getName(), null, true);
                                    ?>
                            <strong>
                                <a href="<?= $block->escapeUrl($_product->getProductUrl()) ?>">
                                    <?php
                                            $productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
                                            if (strlen($productName) > 32) {
                                                $productName = substr($productName, 0, 30) . "...";
                                            }
                                            echo $productName;
                                            ?>

                                </a>
                            </strong>
                            <?= $block->getReviewsSummaryHtml($_product, $templateType) ?>
                            <?= /* @noEscape */ $block->getProductPrice($_product) ?>
                            <?= $block->getProductDetailsHtml($_product) ?>

                            <div>
                                <div
                                    <?= strpos($pos, $viewMode . '-actions') ? $block->escapeHtmlAttr($position) : '' ?>>
                                    <div
                                        <?= strpos($pos, $viewMode . '-primary') ? $block->escapeHtmlAttr($position) : '' ?>>
                                        <?php if ($_product->isSaleable()) : ?>
                                        <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                        <form data-role="tocart-form"
                                            data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>"
                                            action="<?= $block->escapeUrl($postParams['action']) ?>" method="post">
                                            <input type="hidden" name="product"
                                                value="<?= /* @noEscape */ $postParams['data']['product'] ?>">
                                            <input type="hidden"
                                                name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>"
                                                value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
                                            <?= $block->getBlockHtml('formkey') ?>
                                            <button type="submit"
                                                title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
                                                class="action tocart primary colorChanged" disabled>
                                                <span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
                                            </button>
                                        </form>
                                        <?php else : ?>
                                        <?php if ($_product->isAvailable()) : ?>
                                        <div class="stock available">
                                            <span><?= $block->escapeHtml(__('In stock')) ?></span>
                                        </div>
                                        <?php else : ?>
                                        <div class="stock unavailable">
                                            <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
                                        </div>
                                        <?php endif; ?>
                                        <?php endif; ?>
                                    </div>
                                    <div class='add-to-links' data-role="add-to-links"
                                        <?= strpos($pos, $viewMode . '-secondary') ? $block->escapeHtmlAttr($position) : '' ?>>
                                        <?php if ($addToBlock = $block->getChildBlock('addto')) : ?>
                                        <?= $addToBlock->setProduct($_product)->getChildHtml() ?>
                                        <?php endif; ?>
                                    </div>
                                </div>
                                <?php if ($showDescription) : ?>
                                <div>
                                    <?= /* @noEscape */ $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                                    <a href="<?= $block->escapeUrl($_product->getProductUrl()) ?>"
                                        title="<?= /* @noEscape */ $_productNameStripped ?>"><?= $block->escapeHtml(__('Learn More')) ?></a>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <?= ($iterator == count($_productCollection) + 1) ? '</li>' : '' ?>
                    <?php endforeach; ?>
                </ol>

            </div>
        </div>
        <?= $block->getToolbarHtml() ?>
        <?php if (!$block->isRedirectToCartEnabled()) : ?>
        <script type="text/x-magento-init">
            {
            "[data-role=tocart-form], .form.map.checkout": {
                "catalogAddToCart": {
                    "product_sku": "<?= $block->escapeJs($_product->getSku()) ?>"
                }
            }
        }
        </script>
        <?php endif; ?>
        <?php endif; ?>




</section>

and this is the toolbar.phtml file

<?php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/**
 * Product list toolbar
 *
 * @var $block MagentoCatalogBlockProductProductListToolbar
 */

// phpcs:disable Magento2.Security.IncludeFile.FoundIncludeFile
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
?>
<?php if ($block->getCollection()->getSize()) : ?>
<?php $widget = $this->helper(MagentoFrameworkJsonHelperData::class)->jsonDecode($block->getWidgetOptionsJson());
    $widgetOptions = $this->helper(MagentoFrameworkJsonHelperData::class)->jsonEncode($widget['productListToolbarForm']);
    ?>
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
    <?php if ($block->isExpanded()) : ?>
    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
    <?php endif; ?>

    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>

    <?= $block->getPagerHtml() ?>

    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>

    <?php if ($block->isExpanded()) : ?>
    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
    <?php endif; ?>
</div>
<?php endif ?>

i dont know if there is something that i need to make it work in admin panel
but as i see no , it is only some configurations

<?php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/**
 * Product list toolbar
 *
 * @var $block MagentoCatalogBlockProductProductListToolbar
 */

// phpcs:disable Magento2.Security.IncludeFile.FoundIncludeFile
// phpcs:disable PSR2.Methods.FunctionCallSignature.SpaceBeforeOpenBracket
?>
<?php if ($block->getCollection()->getSize()) : ?>
<?php $widget = $this->helper(MagentoFrameworkJsonHelperData::class)->jsonDecode($block->getWidgetOptionsJson());
    $widgetOptions = $this->helper(MagentoFrameworkJsonHelperData::class)->jsonEncode($widget['productListToolbarForm']);
    ?>
<div class="toolbar toolbar-products" data-mage-init='{"productListToolbarForm":<?= /* @noEscape */ $widgetOptions ?>}'>
    <?php if ($block->isExpanded()) : ?>
    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/viewmode.phtml')) ?>
    <?php endif; ?>

    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/amount.phtml')) ?>

    <?= $block->getPagerHtml() ?>

    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/limiter.phtml')) ?>

    <?php if ($block->isExpanded()) : ?>
    <?php include($block->getTemplateFile('Magento_Catalog::product/list/toolbar/sorter.phtml')) ?>
    <?php endif; ?>
</div>
<?php endif ?>