Question

I am using Magento 2.3.3 in my project and I want to display the selected categories, product attributes individually with Remove option in Filters sections as shown below so that the user can clear one item at a time.

Category 1 X

Category 2 X

Expected Result

At present, it is showing as

Category 1, Category 2 X

Products list page filter items

and when the user clicks on the remove icon, both the items are cleared from the list.

Please suggest how to modify the code from the link app/code/Codazon/AjaxLayeredNavPro/view/frontend/templates/layer/state.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Category layered navigation state
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation\State
 */
?>
<?php $_filters = $block->getActiveFilters() ?>
<?php if (!empty($_filters)): ?>
<div class="filter-current" data-mage-init='{"collapsible":{"openedState": "active", "collapsible": true, "active": false }}'>
    <strong class="block-subtitle filter-current-subtitle"
            role="heading"
            aria-level="2"
            data-count="<?= count($_filters) ?>"><?= /* @escapeNotVerified */ __('Filters') ?></strong>
    <ol class="items">
        <?php foreach ($_filters as $_filter): ?>
            <?php
            $label = $_filter->getLabel();
            **if (is_array($label)) {
                $label = implode(', ', $label);
            }**
            ?>
            <li class="item">
                <span class="filter-label"><?= $block->escapeHtml(__($_filter->getName())) ?></span>
                <span class="filter-value"><?= /* @escapeNotVerified */ $block->stripTags($label) ?></span>
                <?php
                $clearLinkUrl = $_filter->getClearLinkUrl();
                $currentFilterName = $block->escapeHtml(__($_filter->getName())) . " " . $block->stripTags($label);
                if ($clearLinkUrl):
                    ?>
                    <a class="action previous" href="<?= /* @escapeNotVerified */ $_filter->getRemoveUrl() ?>"
                       title="<?= /* @escapeNotVerified */ __('Previous') ?>">
                        <span><?= /* @escapeNotVerified */ __('Previous') ?></span>
                    </a>
                    <a class="action remove"
                       title="<?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?>"
                       href="<?= /* @escapeNotVerified */ $clearLinkUrl ?>">
                        <span><?= $block->escapeHtml($_filter->getFilter()->getClearLinkText()) ?></span>
                    </a>
                <?php else: ?>
                    <a class="action remove" href="<?= /* @escapeNotVerified */ $_filter->getRemoveUrl() ?>"
                       title="<?= /* @escapeNotVerified */ $block->escapeHtml(__('Remove')) . " " . $currentFilterName ?>">
                        <span><?= /* @escapeNotVerified */ __('Remove This Item') ?></span>
                    </a>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ol>
</div>
<?php endif; ?>

Bolded code is the logic which is used to display the items list in one line.

Please do needful by providing the solution. Thanks in Advance.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top