This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Plugin\WeltPixel;
use WeltPixel\LayeredNavigation\Helper\Data;
class ForcePriceSliderPlugin
{
public function afterGetPriceIsSliderMode(Data $subject, mixed $result): bool
{
return true;
}
public function afterCanShowPriceInput(Data $subject, mixed $result): bool
{
return false;
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Plugin\WeltPixel;
use Esun\Catalog\Model\ColorOption\HotSaleOptionProvider;
use WeltPixel\LayeredNavigation\Block\LayeredNavigation\RenderLayered;
class HotSaleColorSwatchPlugin
{
public function __construct(
private readonly HotSaleOptionProvider $hotSaleOptionProvider
) {
}
public function afterGetSwatchData(RenderLayered $subject, array $result): array
{
if (($result['attribute_code'] ?? '') !== 'color' || empty($result['options'])) {
return $result;
}
$hotSaleOptionIds = $this->hotSaleOptionProvider->getOptionIds();
if (!$hotSaleOptionIds) {
return $result;
}
$hotSaleOptionSet = array_fill_keys($hotSaleOptionIds, true);
$aggregationOptionSet = [];
foreach ($result['options'] as $optionId => $option) {
if (($option['custom_style'] ?? '') !== 'disabled') {
$aggregationOptionSet[$optionId] = true;
}
}
$availableHotSaleOptionSet = array_intersect_key($hotSaleOptionSet, $aggregationOptionSet);
$availableHotSaleOptions = array_intersect_key($result['options'], $availableHotSaleOptionSet);
if (!$availableHotSaleOptions) {
return $result;
}
$result['options'] = $availableHotSaleOptions;
$result['swatches'] = array_intersect_key($result['swatches'] ?? [], $availableHotSaleOptions);
return $result;
}
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Esun\Catalog\Plugin\WeltPixel;
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
use WeltPixel\LayeredNavigation\Block\Navigation\FilterRenderer;
class PriceStepCountsPlugin
{
public function beforeRender(FilterRenderer $subject, FilterInterface $filter): array
{
if ($filter->getRequestVar() !== 'price') {
return [$filter];
}
$collection = $filter->getLayer()->getProductCollection();
if (!method_exists($collection, 'getFacetedData')) {
$subject->setData('esun_price_step_ranges', []);
return [$filter];
}
$ranges = [];
foreach ($collection->getFacetedData('price') as $bucket) {
$count = (int)($bucket['count'] ?? 0);
if ($count <= 0) {
continue;
}
$value = (string)($bucket['value'] ?? '');
$from = $bucket['from'] ?? null;
$to = $bucket['to'] ?? null;
if (($from === null || $to === null) && str_contains($value, '_')) {
[$fromValue, $toValue] = explode('_', $value, 2);
$from = $fromValue === '*' ? null : (float)$fromValue;
$to = $toValue === '*' ? null : (float)$toValue;
}
if ($from === null && $to === null) {
continue;
}
$ranges[] = [
'from' => $from === null ? '' : (float)$from,
'to' => $to === null ? '' : (float)$to,
'count' => $count,
'value' => $value,
];
}
usort($ranges, static function (array $left, array $right): int {
return (float)$left['from'] <=> (float)$right['from'];
});
$subject->setData('esun_price_step_ranges', $ranges);
return [$filter];
}
}