0

I have create custom filter by brand but issue duplicate layered navigation Magento 2.4.0

This xml code comment layered navigation work perfectly Anyone advance thanks for help.

catalog_category_view.xml

    <!-- <referenceContainer name="content">            
        <block class="Magento\LayeredNavigation\Block\Navigation\Category" name="category.brand.list" template="Magento_Catalog::category/brands.phtml" after="-"/>
    </referenceContainer> -->

Magento_Catalog/templates/category/brands.phtml

<?php 
$filters = $block->getFilters();
$brandHelper = $this->helper(Amasty\ShopbyBrand\Helper\Data::class);
$optionHelper = $this->helper(Amasty\ShopbyBase\Helper\OptionSetting::class);
$attrHelper = $this->helper(Vendorname\AttributeIsFeatured\Helper\Data::class);
$brandAttributeCode = $brandHelper->getBrandAttributeCode();
?>
   <div id="filter-by-brand">
       <h2 class="primary-c text-center margin-top-medium margin-bottom-small title">Filter by 
Brand</h2>
    <?php foreach ($filters as $key => $filter) : ?>
    <?php if($filter->getRequestVar() == $brandAttributeCode): ?>
        <div class="row justify-content-center items" attribute-code="<?= /** @noEscape */ __($filter->getRequestVar()) ?>">
            <?php $i = 1; ?>
            <?php foreach ($filter->getItems() as $item) : ?>
                <?php if($i < 5): ?>
                    <div class="col-6 col-md-3 margin-top-medium item">
                        <?php $img = $optionHelper->getSettingByValue($item->getValue(), 'attr_'.$filter->getRequestVar(), $attrHelper->getStore()->getId())->getImage() ?>
                            <a class="brand-bg-image" href="<?= /** @noEscape */ $block->escapeUrl($item->getUrl()) ?>" title="<?= /** @noEscape */ $item->getLabel() ?>"   <?php echo $img ? 'style="background-image:url('.$attrHelper->getBrandImage($img).')"' : 'style=""' ?> >
                            </a>
                    </div>
                <?php endif; ?>
                <?php $i++ ?>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
<?php endforeach; ?>
<div class="row justify-content-center" id="all-brands-main">
    <div class="text-center col-md-4" id="all-brands-wrapper">
        <a class="all-brands-link btn custom btn-block" href="<?= $brandHelper->getAllBrandsUrl() ?>">View All brands ></a>
    </div>
</div>

Your Answer

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

Browse other questions tagged or ask your own question.