init
This commit is contained in:
+207
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/** @var \WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer $block */
|
||||
$priceData = $block->getPriceConfigData();
|
||||
$min = (int)$priceData['minX'];
|
||||
$max = max($min, (int)$priceData['maxX']);
|
||||
$currentMin = (int)$priceData['min'];
|
||||
$currentMax = (int)$priceData['max'];
|
||||
$currency = (string)$priceData['currency'];
|
||||
$aggregationRanges = (array)$block->getData('esun_price_step_ranges');
|
||||
$segments = [];
|
||||
$ticks = [];
|
||||
$rangeLabels = [];
|
||||
|
||||
if (!empty($aggregationRanges)) {
|
||||
foreach ($aggregationRanges as $range) {
|
||||
$from = $range['from'] === '' ? '' : (float)$range['from'];
|
||||
$to = $range['to'] === '' ? '' : (float)$range['to'];
|
||||
$count = (int)($range['count'] ?? 0);
|
||||
|
||||
if ($count <= 0 || $from === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$segments[] = [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'count' => $count,
|
||||
];
|
||||
$ticks[] = $from;
|
||||
if ($to !== '') {
|
||||
$ticks[] = $to;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fixedTicks = array_values(array_unique(array_filter([$min, 10, 15, 20, 30, $max], static function ($value) use ($min, $max) {
|
||||
return $value >= $min && $value <= $max;
|
||||
})));
|
||||
sort($fixedTicks);
|
||||
for ($index = 0, $last = count($fixedTicks) - 1; $index < $last; $index++) {
|
||||
$fromTick = $fixedTicks[$index];
|
||||
$toTick = $fixedTicks[$index + 1];
|
||||
$segments[] = [
|
||||
'from' => $fromTick,
|
||||
'to' => $toTick === $max && $max > 30 ? '' : $toTick,
|
||||
'count' => null,
|
||||
];
|
||||
}
|
||||
$ticks = $fixedTicks;
|
||||
}
|
||||
|
||||
$ticks = array_values(array_unique($ticks));
|
||||
sort($ticks);
|
||||
$tickCount = count($ticks);
|
||||
$segmentCount = count($segments);
|
||||
|
||||
foreach ($segments as $index => $segment) {
|
||||
$from = (float)$segment['from'];
|
||||
$to = $segment['to'] === '' ? '' : (float)$segment['to'];
|
||||
$isLastOpenRange = $to === '' || ($index === $segmentCount - 1 && $to > $max);
|
||||
$rangeLabels[] = [
|
||||
'label' => $isLastOpenRange
|
||||
? number_format($from, 0) . '+'
|
||||
: number_format($from, 0) . ' - ' . number_format($to, 0),
|
||||
'position' => $segmentCount > 0 ? (($index + 0.5) / $segmentCount) * 100 : 0,
|
||||
];
|
||||
}
|
||||
?>
|
||||
<div class="esun-price-step"
|
||||
data-role="esun-price-step"
|
||||
data-min="<?= $block->escapeHtmlAttr((string)$min) ?>"
|
||||
data-max="<?= $block->escapeHtmlAttr((string)$max) ?>">
|
||||
<div class="esun-price-step__segments" aria-label="<?= $block->escapeHtmlAttr(__('Price ranges')) ?>">
|
||||
<?php foreach ($segments as $index => $segment): ?>
|
||||
<?php
|
||||
$fromTick = $segment['from'];
|
||||
$toTick = $segment['to'];
|
||||
$width = 100 / max(1, $segmentCount);
|
||||
$left = $index * $width;
|
||||
$toLabel = $toTick === '' ? __('and above') : $currency . number_format((float)$toTick, 0);
|
||||
?>
|
||||
<button class="esun-price-step__segment"
|
||||
type="button"
|
||||
data-from="<?= $block->escapeHtmlAttr((string)$fromTick) ?>"
|
||||
data-to="<?= $block->escapeHtmlAttr((string)$toTick) ?>"
|
||||
data-count="<?= $block->escapeHtmlAttr((string)$segment['count']) ?>"
|
||||
style="left: <?= $block->escapeHtmlAttr((string)$left) ?>%; width: <?= $block->escapeHtmlAttr((string)$width) ?>%"
|
||||
aria-label="<?= $block->escapeHtmlAttr(__('%1 to %2', $currency . number_format((float)$fromTick, 0), $toLabel)) ?>"></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="esun-price-step__slider" id="slider-range"></div>
|
||||
<div class="esun-price-step__ticks" aria-hidden="true">
|
||||
<?php foreach ($rangeLabels as $rangeLabel): ?>
|
||||
<span class="esun-price-step__tick" style="left: <?= $block->escapeHtmlAttr((string)$rangeLabel['position']) ?>%">
|
||||
<?= $block->escapeHtml($rangeLabel['label']) ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
require([
|
||||
'jquery',
|
||||
'jquery-ui-modules/effect-slide',
|
||||
'jquery-ui-modules/mouse',
|
||||
'jquery-ui-modules/widget',
|
||||
'<?= $block->escapeJs($block->getSliderJsWidget()) ?>',
|
||||
'jqueryTouch'
|
||||
], function ($) {
|
||||
$(function () {
|
||||
var $slider = $('#slider-range'),
|
||||
$root = $slider.closest('[data-role="esun-price-step"]'),
|
||||
pricePoints = <?= /* @noEscape */ json_encode($ticks) ?>,
|
||||
minIndex = 0,
|
||||
maxIndex = pricePoints.length - 1,
|
||||
selectedPrice = getPriceParam(),
|
||||
current = selectedPrice || [pricePoints[minIndex], pricePoints[maxIndex]];
|
||||
|
||||
current = [
|
||||
nearestIndex(parseInt(current[0], 10), 'floor'),
|
||||
nearestIndex(parseInt(current[1], 10), 'ceil')
|
||||
];
|
||||
|
||||
$slider.slider({
|
||||
range: true,
|
||||
min: minIndex,
|
||||
max: maxIndex,
|
||||
step: 1,
|
||||
values: current,
|
||||
stop: function (event, ui) {
|
||||
applyPrice(pricePoints[ui.values[0]], pricePoints[ui.values[1]]);
|
||||
}
|
||||
});
|
||||
|
||||
$root.on('click', '.esun-price-step__segment', function () {
|
||||
applyPrice(parseInt($(this).data('from'), 10), String($(this).data('to') || ''));
|
||||
});
|
||||
|
||||
function nearestIndex(value, direction) {
|
||||
var fallback = direction === 'ceil' ? maxIndex : minIndex,
|
||||
i;
|
||||
|
||||
if (isNaN(value)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (direction === 'ceil') {
|
||||
for (i = 0; i < pricePoints.length; i++) {
|
||||
if (pricePoints[i] >= value) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return maxIndex;
|
||||
}
|
||||
|
||||
for (i = pricePoints.length - 1; i >= 0; i--) {
|
||||
if (pricePoints[i] <= value) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
function applyPrice(from, to) {
|
||||
var cleanLink = removeParam('price', removeParam('p', window.location.href)),
|
||||
sliderLink = cleanLink + getSeparator(cleanLink) + 'price=' + from + '-' + to;
|
||||
|
||||
window.location.href = sliderLink;
|
||||
}
|
||||
|
||||
function getSeparator(link) {
|
||||
return link.indexOf('?') !== -1 ? '&' : '?';
|
||||
}
|
||||
|
||||
function removeParam(key, url) {
|
||||
var hashParts = url.split('#'),
|
||||
regex = new RegExp('([?&])' + key + '=.*?(&|#|$)', 'i');
|
||||
|
||||
if (hashParts[0].match(regex)) {
|
||||
url = hashParts[0].replace(regex, '$1');
|
||||
url = url.replace(/([?&])$/, '');
|
||||
if (typeof hashParts[1] !== 'undefined' && hashParts[1] !== null) {
|
||||
url += '#' + hashParts[1];
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
function getPriceParam() {
|
||||
var params = parseQueryString(),
|
||||
price = params.price;
|
||||
|
||||
return price ? price.split('-') : false;
|
||||
}
|
||||
|
||||
function parseQueryString() {
|
||||
var objURL = {};
|
||||
|
||||
window.location.search.replace(new RegExp('([^?=&]+)(=([^&]*))?', 'g'), function ($0, $1, $2, $3) {
|
||||
objURL[$1] = $3;
|
||||
});
|
||||
|
||||
return objURL;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
?>
|
||||
<?php
|
||||
/**
|
||||
* Category layered navigation state
|
||||
*
|
||||
* @var $block \WeltPixel\LayeredNavigation\Block\Navigation\State
|
||||
*/
|
||||
?>
|
||||
<?php /** @var \Esun\Catalog\ViewModel\LayeredNavigation\AppliedFilterSwatch|null $appliedFilterSwatch */ ?>
|
||||
<?php $appliedFilterSwatch = $block->getData('appliedFilterSwatch') ?>
|
||||
<?php $_filters = $block->getActiveFilters() ?>
|
||||
<?php $categoryParamLabel = $block->getCategoryParamLabel() ?>
|
||||
<?php $ratingParamLabel = $block->getRatingParamLabel() ?>
|
||||
<?php if (!empty($_filters)): ?>
|
||||
<?php $hasAppliedColorSwatch = false ?>
|
||||
<div id="wp_ln_shopby" class="filter-current esun-applied-filters">
|
||||
<div class="esun-applied-filters__header">
|
||||
<strong class="block-subtitle filter-current-subtitle"
|
||||
role="heading"
|
||||
aria-level="2"
|
||||
data-count="<?= /* @noEscape */ count($_filters) ?>">
|
||||
<?= $block->escapeHtml(__('Applied filters')) ?>
|
||||
</strong>
|
||||
<a class="esun-applied-filters__clear" href="<?= $block->escapeUrl($block->getClearUrl()) ?>">
|
||||
<?= $block->escapeHtml(__('Clear all')) ?>
|
||||
</a>
|
||||
</div>
|
||||
<ol class="items esun-applied-filters__items" id="wp_ln_shopby_items">
|
||||
<?php foreach ($_filters as $_filter): ?>
|
||||
<?php
|
||||
$requestVar = $_filter->getFilter()->getRequestVar();
|
||||
$filterItemVal = is_array($_filter->getValue()) ? implode('-', $_filter->getValue()) : $_filter->getValue();
|
||||
$filterSwatch = ['color' => '', 'image' => ''];
|
||||
$isColorFilter = false;
|
||||
|
||||
if ($requestVar == $categoryParamLabel) {
|
||||
$dataAttrId = '0_' . $filterItemVal;
|
||||
$filterLabel = $block->stripTags($_filter->getLabel());
|
||||
} elseif ($requestVar == $ratingParamLabel) {
|
||||
$dataAttrId = $ratingParamLabel . '_' . $filterItemVal;
|
||||
$filterLabel = $block->getRateFilterLabel($_filter);
|
||||
} else {
|
||||
$attributeModel = $_filter->getFilter()->getAttributeModel();
|
||||
$attributeId = $attributeModel ? $attributeModel->getAttributeId() : $requestVar;
|
||||
$dataAttrId = $attributeId . '_' . $filterItemVal;
|
||||
$filterLabel = $block->stripTags($_filter->getLabel());
|
||||
if ($attributeModel
|
||||
&& $attributeModel->getAttributeCode() === 'color'
|
||||
&& $appliedFilterSwatch
|
||||
) {
|
||||
$isColorFilter = true;
|
||||
$filterSwatch = $appliedFilterSwatch->getSwatch((int) $filterItemVal);
|
||||
$hasAppliedColorSwatch = $hasAppliedColorSwatch
|
||||
|| $filterSwatch['color'] !== ''
|
||||
|| $filterSwatch['image'] !== '';
|
||||
}
|
||||
}
|
||||
|
||||
$clearLinkUrl = $_filter->getClearLinkUrl();
|
||||
$removeUrl = $clearLinkUrl ?: $_filter->getRemoveUrl();
|
||||
$currentFilterName = $block->escapeHtmlAttr(__($_filter->getName()) . ' ' . $block->stripTags($_filter->getLabel()));
|
||||
?>
|
||||
<li class="item esun-applied-filters__item<?= $isColorFilter ? ' is-color' : '' ?>"
|
||||
data-attr-id="<?= $block->escapeHtmlAttr($dataAttrId) ?>">
|
||||
<?php if ($filterSwatch['color'] !== ''): ?>
|
||||
<div class="swatch-option color esun-applied-filters__swatch"
|
||||
tabindex="-1"
|
||||
data-option-type="1"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($filterItemVal) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($filterLabel) ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value="<?= $block->escapeHtmlAttr($filterSwatch['color']) ?>"
|
||||
style="<?= $block->escapeHtmlAttr(
|
||||
'background: ' . $filterSwatch['color'] . ' no-repeat center; background-size: initial;'
|
||||
) ?>"
|
||||
aria-hidden="true"></div>
|
||||
<?php elseif ($filterSwatch['image'] !== ''): ?>
|
||||
<div class="swatch-option image esun-applied-filters__swatch"
|
||||
tabindex="-1"
|
||||
data-option-type="2"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($filterItemVal) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($filterLabel) ?>"
|
||||
data-option-tooltip-thumb="<?= $block->escapeUrl($filterSwatch['image']) ?>"
|
||||
data-option-tooltip-value=""
|
||||
style="<?= $block->escapeHtmlAttr(
|
||||
'background: url("' . $block->escapeUrl($filterSwatch['image'])
|
||||
. '") no-repeat center; background-size: initial;'
|
||||
) ?>"
|
||||
aria-hidden="true"></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!$isColorFilter): ?>
|
||||
<span class="filter-value esun-applied-filters__value"><?= $block->escapeHtml($filterLabel) ?></span>
|
||||
<?php endif; ?>
|
||||
<a class="action remove esun-applied-filters__remove"
|
||||
href="<?= $block->escapeUrl($removeUrl) ?>"
|
||||
title="<?= $block->escapeHtmlAttr(__('Remove') . ' ' . $currentFilterName) ?>"
|
||||
aria-label="<?= $block->escapeHtmlAttr(__('Remove') . ' ' . $currentFilterName) ?>">
|
||||
<span aria-hidden="true">×</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</div>
|
||||
<?php if ($hasAppliedColorSwatch): ?>
|
||||
<script>
|
||||
require(['jquery', 'Magento_Swatches/js/swatch-renderer'], function ($) {
|
||||
$('#wp_ln_shopby_items')
|
||||
.find('.esun-applied-filters__swatch[data-option-type]')
|
||||
.SwatchRendererTooltip();
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user