There is a way to exclude from the count, in the layered navigation, child product that have the filter attribute? For example: I have a product A with attribute region set to "tuscany", and I have also a bundle B which contains the product A, but the bundle doesn't have the region attribute set. What I get in layered navigation for region filter "tuscany" is 2, but I don't want to include in the count the bundle's child items.
1 Answer
I have found a solution: Ive created a plugin on the indexer
<type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer">
<plugin name="excludeBundleFromCount" type="Vendor\FilteredNavigation\Plugin\Indexer\AbstractIndexer"/>
</type>
and the class:
namespace Vendor\FilteredNavigation\Plugin\Indexer;
class AbstractIndexer
{
public function aroundGetRelationsByParent(
\Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $subject,
\Closure $proceed,
$parentIds
) {
return [];
}
}
so all the save on bundle item doesn't create an index entry for the attribute.
Not the beatiful and elegant way but it does its job.