отображение ненужных цен за кг
This commit is contained in:
@@ -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