отображение ненужных цен за кг
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (!function_exists('category_tree_icon')) {
|
||||
function category_tree_icon(string $name): string
|
||||
{
|
||||
$lowerName = mb_strtolower($name);
|
||||
|
||||
return match (true) {
|
||||
str_contains($lowerName, 'рыб') => 'fish',
|
||||
str_contains($lowerName, 'морепроду') => 'shrimp',
|
||||
str_contains($lowerName, 'икра') => 'caviar',
|
||||
str_contains($lowerName, 'мяс') => 'meat',
|
||||
str_contains($lowerName, 'сыр') => 'cheese',
|
||||
str_contains($lowerName, 'полуфаб') => 'box',
|
||||
str_contains($lowerName, 'овощ') || str_contains($lowerName, 'фрукт') || str_contains($lowerName, 'ягод') || str_contains($lowerName, 'гриб') => 'leaf',
|
||||
str_contains($lowerName, 'бакале') => 'jar',
|
||||
str_contains($lowerName, 'молоч') => 'milk',
|
||||
default => 'grid',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('category_tree_icon_svg')) {
|
||||
function category_tree_icon_svg(string $icon): string
|
||||
{
|
||||
return match ($icon) {
|
||||
'fish' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12c3.2-4.2 7.1-6.2 11.6-6 2.3.1 4.2 1.1 5.8 3l1.6-1.5v9L20.4 15c-1.6 1.9-3.6 2.9-5.8 3-4.5.2-8.4-1.8-11.6-6Z"/><path d="M7.5 12h.1"/><path d="M14 7.5c-1.4 1.2-2.1 2.7-2.1 4.5s.7 3.3 2.1 4.5"/></svg>',
|
||||
'shrimp' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18.5 7.5c-2.8-2.3-7.5-1.6-10.2.9-2.7 2.4-2.8 6-.3 8.1 2.3 2 6 1.9 8.2-.2 1.6-1.5 1.8-3.8.4-5.2-1.2-1.2-3.3-1.3-4.7-.2"/><path d="M19 8l2-2"/><path d="M18.8 8.2l2.4.8"/><path d="M8.8 16.8 7 19"/><path d="M11.4 17.7 10.5 20"/><path d="M14 17.2l.3 2.4"/></svg>',
|
||||
'leaf' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20 4c-7.8.1-12.8 3-15 8.6C3.7 16 6 20 9.8 20c5.7 0 9.2-5.6 10.2-16Z"/><path d="M5 19c3.2-4.4 7.2-7.5 12-9.2"/></svg>',
|
||||
'caviar' => '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="8" cy="8" r="2.4"/><circle cx="15.5" cy="7.5" r="2"/><circle cx="12" cy="14" r="2.5"/><circle cx="6.8" cy="16.2" r="1.8"/><circle cx="17.5" cy="16.5" r="2.1"/></svg>',
|
||||
'jar' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8 3h8"/><path d="M9 6h6"/><path d="M7 9c0-1.7 1.4-3 3-3h4c1.7 0 3 1.3 3 3v9c0 1.7-1.3 3-3 3h-4c-1.6 0-3-1.3-3-3V9Z"/><path d="M7 13h10"/></svg>',
|
||||
'box' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m4 8 8-4 8 4-8 4-8-4Z"/><path d="M4 8v8l8 4 8-4V8"/><path d="M12 12v8"/></svg>',
|
||||
'meat' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.5 15.5c-2.8-3.9.5-9.1 5.6-9.6 4.1-.4 7.9 1.9 8.7 5.2.8 3.5-2.1 6.8-6.2 7.2-3.4.4-6.3-.7-8.1-2.8Z"/><circle cx="11" cy="12" r="2.4"/></svg>',
|
||||
'cheese' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 16 19 7v10H4v-1Z"/><path d="M4 16v3h15v-2"/><circle cx="14.5" cy="13" r="1"/><circle cx="17" cy="10.5" r=".8"/><circle cx="9.5" cy="15" r=".8"/></svg>',
|
||||
'milk' => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 3h6v4l2 3v10H7V10l2-3V3Z"/><path d="M9 7h6"/><path d="M7 13h10"/></svg>',
|
||||
default => '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 5h6v6H5z"/><path d="M13 5h6v6h-6z"/><path d="M5 13h6v6H5z"/><path d="M13 13h6v6h-6z"/></svg>',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ declare(strict_types=1);
|
||||
/** @var int $depth */
|
||||
/** @var string $currentSlug */
|
||||
|
||||
require_once __DIR__ . '/category-icons.php';
|
||||
|
||||
if (!function_exists('category_tree_has_current')) {
|
||||
/**
|
||||
* @param array<string, mixed> $category
|
||||
@@ -35,10 +37,14 @@ if (!function_exists('category_tree_has_current')) {
|
||||
<?php $isCurrent = ($currentSlug ?? '') === $category['slug']; ?>
|
||||
<?php $hasChildren = !empty($category['children']); ?>
|
||||
<?php $shouldOpen = category_tree_has_current($category, $currentSlug ?? ''); ?>
|
||||
<li class="<?= $isCurrent ? 'is-current' : '' ?>">
|
||||
<?php $iconName = $depth === 0 ? category_tree_icon((string) $category['name']) : ''; ?>
|
||||
<li class="<?= $isCurrent ? 'is-current' : '' ?><?= $hasChildren ? ' has-children' : '' ?>">
|
||||
<?php if ($hasChildren): ?>
|
||||
<details class="category-details" <?= $shouldOpen ? 'open' : '' ?>>
|
||||
<summary>
|
||||
<?php if ($depth === 0): ?>
|
||||
<span class="category-icon is-<?= e($iconName) ?>" aria-hidden="true"><?= category_tree_icon_svg($iconName) ?></span>
|
||||
<?php endif; ?>
|
||||
<a class="<?= $isCurrent ? 'is-current-link' : '' ?>" href="/catalog/<?= e($category['slug']) ?>"><?= e($category['name']) ?></a>
|
||||
</summary>
|
||||
<?php
|
||||
@@ -51,7 +57,12 @@ if (!function_exists('category_tree_has_current')) {
|
||||
?>
|
||||
</details>
|
||||
<?php else: ?>
|
||||
<a href="/catalog/<?= e($category['slug']) ?>"><?= e($category['name']) ?></a>
|
||||
<a href="/catalog/<?= e($category['slug']) ?>">
|
||||
<?php if ($depth === 0): ?>
|
||||
<span class="category-icon is-<?= e($iconName) ?>" aria-hidden="true"><?= category_tree_icon_svg($iconName) ?></span>
|
||||
<?php endif; ?>
|
||||
<span><?= e($category['name']) ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
/** @var array<int, array<string, mixed>> $megaCategories */
|
||||
|
||||
require_once __DIR__ . '/category-icons.php';
|
||||
|
||||
if (!function_exists('render_mega_category_children')) {
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $children
|
||||
@@ -30,8 +32,12 @@ if (!function_exists('render_mega_category_children')) {
|
||||
<nav class="category-mega-bar" aria-label="Категории товаров">
|
||||
<div class="category-mega-inner">
|
||||
<?php foreach ($megaCategories as $category): ?>
|
||||
<?php $iconName = category_tree_icon((string) $category['name']); ?>
|
||||
<div class="mega-item">
|
||||
<a class="mega-root" href="/catalog/<?= e((string) $category['slug']) ?>"><?= e((string) $category['name']) ?></a>
|
||||
<a class="mega-root" href="/catalog/<?= e((string) $category['slug']) ?>">
|
||||
<span class="mega-category-icon category-icon is-<?= e($iconName) ?>" aria-hidden="true"><?= category_tree_icon_svg($iconName) ?></span>
|
||||
<span><?= e((string) $category['name']) ?></span>
|
||||
</a>
|
||||
<?php render_mega_category_children($category['children'] ?? []); ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -12,6 +12,31 @@ $activeVariant = $variants[0] ?? [
|
||||
'package_quantity' => $product['package_quantity'] ?? 0,
|
||||
'old_package_price' => $product['old_package_price'] ?? null,
|
||||
];
|
||||
$showUnitPriceForVariant = static function (array $variant) use ($product): bool {
|
||||
if (function_exists('product_should_show_unit_price')) {
|
||||
return product_should_show_unit_price($product, $variant);
|
||||
}
|
||||
|
||||
$unit = (string) ($variant['unit'] ?? $product['base_unit'] ?? '');
|
||||
if (!in_array($unit, ['kg', 'кг'], true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($variant['price_per_unit'] ?? null) === null || (float) $variant['price_per_unit'] <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$packageQuantity = (float) ($variant['package_quantity'] ?? 0);
|
||||
if ($packageQuantity < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lower = static function (string $value): string {
|
||||
return function_exists('mb_strtolower') ? mb_strtolower($value, 'UTF-8') : strtolower($value);
|
||||
};
|
||||
|
||||
return preg_match('/(^|[\s,.;])\d+(?:[.,]\d+)?\s*(мл|шт)\.?($|[\s,.;])/u', $lower((string) ($variant['name'] ?? ''))) !== 1;
|
||||
};
|
||||
$cardId = 'product-card-' . (int) ($product['id'] ?? 0);
|
||||
$activePackagePrice = (float) ($activeVariant['package_price'] ?? 0);
|
||||
$activeUnitPrice = $activeVariant['price_per_unit'] === null ? null : (float) $activeVariant['price_per_unit'];
|
||||
@@ -29,8 +54,9 @@ $activeOldUnitPrice = ($activeOldPackagePrice !== null && $activePackageQuantity
|
||||
if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) {
|
||||
$activeOldUnitPrice = null;
|
||||
}
|
||||
$activeTierBase = $activeUnitPrice ?? $activePackagePrice;
|
||||
$activeTierUnit = unit_label((string) ($activeVariant['unit'] ?? '')) ?: 'шт.';
|
||||
$activeShowsUnitPrice = $showUnitPriceForVariant($activeVariant);
|
||||
$activeTierBase = $activeShowsUnitPrice ? ($activeUnitPrice ?? $activePackagePrice) : $activePackagePrice;
|
||||
$activeTierUnit = $activeShowsUnitPrice ? unit_label((string) ($activeVariant['unit'] ?? '')) : 'фасовку';
|
||||
$isPublished = (int) ($product['is_published'] ?? 1) === 1;
|
||||
$isAvailable = (int) ($product['is_available'] ?? 1) === 1;
|
||||
$isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
@@ -42,6 +68,7 @@ $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
data-product-name="<?= e((string) ($product['name'] ?? '')) ?>"
|
||||
data-product-slug="<?= e((string) ($product['slug'] ?? '')) ?>"
|
||||
data-product-image="<?= e((string) ($product['main_image_path'] ?? '')) ?>"
|
||||
data-show-unit-price="<?= $activeShowsUnitPrice ? '1' : '0' ?>"
|
||||
>
|
||||
<?php if (!$isPurchasable): ?>
|
||||
<span class="product-unavailable-badge"><?= !$isPublished ? 'Ожидается поступление' : 'Нет в наличии' ?></span>
|
||||
@@ -95,6 +122,7 @@ $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
if ($variantOldUnitPrice !== null && $variantOldUnitPrice <= $variantUnitPrice) {
|
||||
$variantOldUnitPrice = null;
|
||||
}
|
||||
$variantShowsUnitPrice = $showUnitPriceForVariant($variant);
|
||||
?>
|
||||
<button
|
||||
class="variant-choice-button<?= $index === 0 ? ' is-active' : '' ?>"
|
||||
@@ -110,6 +138,7 @@ $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
data-variant-unit-price-label="<?= e(money_label($variant['price_per_unit'])) ?>"
|
||||
data-variant-package-price-label="<?= e(money_label($variant['package_price'])) ?>"
|
||||
data-old-price="<?= e($variantOldPackagePrice === null ? '' : money_label($variantOldPackagePrice)) ?>"
|
||||
data-show-unit-price="<?= $variantShowsUnitPrice ? '1' : '0' ?>"
|
||||
>
|
||||
<?= e((string) $variant['name']) ?>
|
||||
</button>
|
||||
@@ -118,8 +147,8 @@ $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($isPurchasable && $activeVariant['price_per_unit'] !== null): ?>
|
||||
<span class="price-line">
|
||||
<?php if ($isPurchasable): ?>
|
||||
<span class="price-line<?= $activeShowsUnitPrice ? '' : ' is-price-placeholder' ?>" data-unit-price-row aria-hidden="<?= $activeShowsUnitPrice ? 'false' : 'true' ?>">
|
||||
<span class="price-unit-label">Цена за <span data-unit-label><?= e(unit_label((string) $activeVariant['unit'])) ?></span>:</span>
|
||||
<span class="price-unit-values">
|
||||
<span class="old-price" data-old-unit-price-display<?= $activeOldUnitPrice === null ? ' hidden' : '' ?>><?= e(money_label($activeOldUnitPrice)) ?></span>
|
||||
@@ -137,13 +166,11 @@ $isPurchasable = $isPublished && $isAvailable && $activePackagePrice > 0;
|
||||
<span class="package-price-values">
|
||||
<span class="old-price" data-old-package-price-display<?= $activeOldPackagePrice === null ? ' hidden' : '' ?>><?= e(money_label($activeOldPackagePrice)) ?></span>
|
||||
<span data-package-price data-dynamic-package-price data-base-package-price="<?= e((string) $activePackagePrice) ?>"><?= e(money_label($activeVariant['package_price'])) ?></span>
|
||||
<?php if ($activeVariant['price_per_unit'] === null): ?>
|
||||
<button class="price-tier-trigger" type="button" aria-label="Показать градацию цены">?</button>
|
||||
<?php endif; ?>
|
||||
<button class="price-tier-trigger" data-package-tier-trigger type="button" aria-label="Показать градацию цены"<?= $activeShowsUnitPrice ? ' hidden' : '' ?>>?</button>
|
||||
</span>
|
||||
</strong>
|
||||
<?php if ($activeVariant['price_per_unit'] !== null): ?>
|
||||
<span class="package-price-note">Цена за <span data-unit-label-note><?= e(unit_label((string) $activeVariant['unit'])) ?></span> × <span data-package-label-note><?= e((string) $activeVariant['name']) ?></span></span>
|
||||
<?php if ($isPurchasable): ?>
|
||||
<span class="package-price-note<?= $activeShowsUnitPrice ? '' : ' is-price-placeholder' ?>" data-package-price-note aria-hidden="<?= $activeShowsUnitPrice ? 'false' : 'true' ?>">Цена за <span data-unit-label-note><?= e(unit_label((string) $activeVariant['unit'])) ?></span> × <span data-package-label-note><?= e((string) $activeVariant['name']) ?></span></span>
|
||||
<?php endif; ?>
|
||||
<?php elseif (!$isPurchasable): ?>
|
||||
<div class="product-card-unavailable-note">Цену уточним после поступления товара.</div>
|
||||
|
||||
Reference in New Issue
Block a user