EmicoEcommerce/Magento2Tweakwise

View on GitHub
view/frontend/templates/product/layered/default.phtml

Summary

Maintainability
Test Coverage
<?php
/**
 * Tweakwise (https://www.tweakwise.com/) - All Rights Reserved
 *
 * @copyright Copyright (c) 2017-2022 Tweakwise.com B.V. (https://www.tweakwise.com)
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
use Tweakwise\Magento2Tweakwise\Block\LayeredNavigation\RenderLayered\DefaultRenderer;

/**
 * @var $block DefaultRenderer
 * phpcs:disable Magento2.Security.XssTemplate.FoundUnescaped
 */

$hasHiddenItems = $block->hasHiddenItems();
$hasAlternateSortOrder = $block->hasAlternateSortOrder();
$showCheckBox = $block->showCheckbox();
$prefix = $block->getItemPrefix();
$postfix = $block->getItemPostfix();
$shouldDisplayProductCountLayer = $block->shouldDisplayProductCountOnLayer();

?>
<div data-mage-init='<?=$block->getJsSortConfig()?>'>
    <?php if ($block->isSearchable()): ?>
        <input data-max-visible="<?=  $block->getMaxItemsShown()?>" type="text" class="tw_filtersearch js-skip-submit" name="tw_filtersearch" placeholder="<?= $block->getSearchPlaceholder(); ?>" >
        <div style="display: none" class="search_no_results"><?= $block->getSearchNoResultsText(); ?></div>
    <?php endif; ?>
    <ol class="items">
        <?php foreach ($block->getItems() as $index => $item): ?>
            <li class="item<?=$block->itemDefaultHidden($item) ? ' default-hidden' : ''?>"
                <?php if ($hasHiddenItems && $hasAlternateSortOrder):?>
                    data-alternate-sort="<?=$item->getAlternateSortOrder();?>"
                    data-original-sort="<?=$index;?>"
                <?php endif;?>
            >
                <a <?=$block->renderAnchorHtmlTagAttributes($item);?>>
                    <?php $cssId = $item->getCssId();?>
                    <?php if ($showCheckBox): ?>
                        <input id="<?=$cssId?>"
                               name="<?=$item->getFilter()->getFacet()->getFacetSettings()->getUrlKey()?>[]"
                               type="checkbox" <?=($item->isSelected() ? 'checked="checked"' : '')?>
                               value="<?=$escaper->escapeHtmlAttr($item->getLabel())?>"
                        >

                        <label for="<?=$cssId?>">
                            <?=$prefix . $escaper->escapeHtml($item->getLabel()) . $postfix?>
                        </label>
                    <?php else: ?>
                        <?=$prefix . $escaper->escapeHtml($item->getLabel()) . $postfix?>
                    <?php endif; ?>

                    <?php if ($shouldDisplayProductCountLayer): ?>
                        <span class="count">
                            <?=htmlentities($item->getCount())?>
                            <span class="filter-count-label">
                                <?php if ($item->getCount() === 1):?>
                                    <?=__('item')?>
                                <?php else:?>
                                    <?=__('items')?>
                                <?php endif;?>
                            </span>
                        </span>
                    <?php endif; ?>
                </a>
            </li>
        <?php endforeach; ?>
    </ol>

    <?php if ($hasHiddenItems): ?>
        <a class="more-items"><?=__($block->getMoreItemText())?></a>
        <a class="less-items default-hidden"><?=__($block->getLessItemText())?></a>
    <?php endif; ?>
</div>