отображение ненужных цен за кг
This commit is contained in:
@@ -7,6 +7,31 @@ declare(strict_types=1);
|
||||
/** @var array<int, array<string, mixed>> $images */
|
||||
|
||||
$mainImage = $product['main_image_path'] ?? '';
|
||||
$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;
|
||||
};
|
||||
?>
|
||||
<section
|
||||
class="product-detail price-aware"
|
||||
@@ -43,6 +68,7 @@ $mainImage = $product['main_image_path'] ?? '';
|
||||
<section class="variant-list" aria-label="Фасовки товара">
|
||||
<h2>Фасовки</h2>
|
||||
<?php foreach ($variants as $variant): ?>
|
||||
<?php $showUnitPrice = $showUnitPriceForVariant($variant); ?>
|
||||
<div
|
||||
class="variant-row"
|
||||
data-variant-id="<?= e((string) ($variant['id'] ?? '')) ?>"
|
||||
@@ -52,11 +78,12 @@ $mainImage = $product['main_image_path'] ?? '';
|
||||
>
|
||||
<strong><?= e((string) $variant['name']) ?></strong>
|
||||
<span>
|
||||
<?php if ($variant['price_per_unit'] !== null): ?>
|
||||
<?php if ($showUnitPrice): ?>
|
||||
<span data-dynamic-unit-price data-base-unit-price="<?= e((string) $variant['price_per_unit']) ?>"><?= e(money_label($variant['price_per_unit'])) ?></span> / <?= e(unit_label((string) $variant['unit'])) ?>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
<b>
|
||||
<small>За фасовку <?= e((string) $variant['name']) ?></small>
|
||||
<?php if (!empty($variant['old_package_price'])): ?>
|
||||
<span class="old-price"><?= e(money_label($variant['old_package_price'])) ?></span>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user