3

I have install Magento 2.1.3 with Porto Theme.

In category page, Few sub category display proper with products count and Faw doesn't appare/display but it has product.

I tried to disable all custom modules and tried to disable Porto Theme but not display other sub-categories.

Following file from vendor/magento/module-catalog-search/Model/Layer/Filter/Category.php

protected function _getItemsData()
{
    /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
    $productCollection = $this->getLayer()->getProductCollection();
    $optionsFacetedData = $productCollection->getFacetedData('category');
    $category = $this->dataProvider->getCategory();
    $categories = $category->getChildrenCategories();

    $collectionSize = $productCollection->getSize();

    if ($category->getIsActive()) {
        foreach ($categories as $category) {
            if ($category->getIsActive()
                && isset($optionsFacetedData[$category->getId()])
                && $this->isOptionReducesResults($optionsFacetedData[$category->getId()]['count'], $collectionSize)
            ) {
                $this->itemDataBuilder->addItemData(
                    $this->escaper->escapeHtml($category->getName()),
                    $category->getId(),
                    $optionsFacetedData[$category->getId()]['count']
                );
            }
        }
    }

I debug above code and found that, $this->isOptionReducesResults($optionsFacetedData[$category->getId()]['count'], $collectionSize) getting blank so that sub-categories not showing.

  • Use Flat Catalog Category to No set and clear cache after check – user68116 Jun 6 '18 at 19:55
1

Current behaviour implemented in a way, that isOptionReducesResults function checks whether specific Layered Navigation filter reduces the number of results in result set. And if the Specific filter doesn't lead to narrowing down result set - Magento wouldn't show it.

For example, there are three colors: red, green, blue we have 5 configurable products in the result set. 5 of them have red variations, 3 of them green and 1 - blue.

Our LN filters would look like:

  • green - (3)
  • blue - (1)

*red wouldn't be shown because all the products have this colour variation. And if we will provide filter red - (5), the user could potentially infinitely apply this filter without narrowing down result set.

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.