0

I'm facing a strange issue which I couldn't point out where am I wrong. The issue is, when I navigate to any category page, the total result of product is showing as 1 though the category having many products.

But when I search the product via search bar, I'm getting the correct result of product counts.

Could anyone please help me to sort out this issue?

Code:

<?php
/**
 * Product list toolbar
 *
 * @var $block \Magento\Catalog\Block\Product\ProductList\Toolbar
 */
use Magento\Catalog\Model\Product\ProductList\Toolbar;
?>
<p class="toolbar-amount total-result" id="toolbar-amount">
    <?php if ($block->getLastPageNum() > 1): ?>
        <?php /* @escapeNotVerified */ echo __('Items %1-%2 of %3',
            '<span class="toolbar-number">' . $block->getFirstNum() . '</span>',
            '<span class="toolbar-number">' . $block->getLastNum() . '</span>',
            '<span class="toolbar-number">' . $block->getTotalNum() . '</span>') ?>
    <?php elseif ($block->getTotalNum() == 1): ?>
        <?php /* @escapeNotVerified */ echo __('%1 Total Result',
           '<span class="toolbar-number">' . $block->getTotalNum() . '</span>') ?>
    <?php else: ?>
        <?php /* @escapeNotVerified */ echo __('%1 Total Result',
            '<span class="toolbar-number">' . $block->getTotalNum() . '</span>') ?>
    <?php endif; ?>
</p>

1 Answer 1

1

I saw this happen when a group by statement is added to the product collection.
If this is the case, you can create an after plugin for the product collection that looks like this

public function afterGetSelectCountSql(
    \Magento\Catalog\Model\ResourceModel\Product\Collection $subject
    \Magento\Framework\DB\Select $select;
) {
    $select->reset('group');
    return $select;
}
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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