Files
new.rybstock.ru/views/catalog/product.php
T
2026-06-08 10:58:47 +03:00

173 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/** @var array<string, mixed> $product */
/** @var array<int, array<string, mixed>> $variants */
/** @var array<int, array<string, mixed>> $images */
$sourceMainImage = (string) ($product['main_image_path'] ?? '');
$mainImage = function_exists('optimized_image_path')
? optimized_image_path($sourceMainImage, 'detail')
: $sourceMainImage;
$cartImage = function_exists('optimized_image_path')
? optimized_image_path($sourceMainImage, 'preview')
: $sourceMainImage;
$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"
data-product-id="<?= e((string) ($product['id'] ?? '')) ?>"
data-product-name="<?= e((string) ($product['name'] ?? '')) ?>"
data-product-slug="<?= e((string) ($product['slug'] ?? '')) ?>"
data-product-image="<?= e($cartImage) ?>"
>
<div class="product-gallery panel">
<?php if ($mainImage !== ''): ?>
<img src="<?= e((string) $mainImage) ?>" alt="<?= e((string) $product['name']) ?>">
<?php else: ?>
<div class="product-image-placeholder">Рыбсток</div>
<?php endif; ?>
<?php if ($images !== []): ?>
<div class="product-thumbs">
<?php foreach ($images as $image): ?>
<?php
$thumbPath = function_exists('optimized_image_path')
? optimized_image_path((string) $image['path'], 'preview')
: (string) $image['path'];
?>
<img src="<?= e($thumbPath) ?>" alt="<?= e((string) ($image['alt'] ?: $product['name'])) ?>" loading="lazy" decoding="async">
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<article class="product-detail-main panel">
<p class="eyebrow"><?= e((string) ($product['category_name'] ?? 'Каталог')) ?></p>
<h1><?= e((string) ($product['h1'] ?: $product['name'])) ?></h1>
<?php if (!empty($product['short_description'])): ?>
<p class="product-lead"><?= e((string) $product['short_description']) ?></p>
<?php endif; ?>
<div class="product-detail-notes" aria-label="Условия заказа">
<span>Оплата при получении</span>
<span>Весовые позиции пересчитываем при сборке</span>
<span>Доставка внутри МКАД бесплатно от 5000р.</span>
</div>
<?php if ($variants !== []): ?>
<section class="variant-list product-detail-variants" aria-label="Фасовки товара">
<h2>Доступные фасовки</h2>
<?php foreach ($variants as $variant): ?>
<?php
$showUnitPrice = $showUnitPriceForVariant($variant);
$unitLabel = unit_label((string) ($variant['unit'] ?? $product['base_unit'] ?? 'кг'));
$variantName = (string) ($variant['name'] ?? '');
$packageQuantity = (float) ($variant['package_quantity'] ?? 0);
$unitPrice = $variant['price_per_unit'] ?? null;
$packagePrice = $variant['package_price'] ?? null;
$oldPackagePrice = $variant['old_package_price'] ?? null;
$oldUnitPrice = null;
if ($showUnitPrice && $oldPackagePrice !== null && $packageQuantity > 0) {
$oldUnitPrice = (float) $oldPackagePrice / $packageQuantity;
}
$tierBase = $showUnitPrice && $unitPrice !== null ? (float) $unitPrice : (float) ($packagePrice ?? 0);
$tierUnit = $showUnitPrice ? $unitLabel : 'фасовку';
?>
<div
class="variant-row"
data-variant-id="<?= e((string) ($variant['id'] ?? '')) ?>"
data-variant-name="<?= e($variantName) ?>"
data-unit="<?= e($unitLabel) ?>"
data-package-quantity="<?= e((string) ($variant['package_quantity'] ?? '')) ?>"
data-base-unit-price="<?= e((string) ($variant['price_per_unit'] ?? '')) ?>"
data-base-package-price="<?= e((string) ($variant['package_price'] ?? '')) ?>"
>
<div class="variant-row-head">
<span>Фасовка</span>
<strong><?= e($variantName) ?></strong>
</div>
<div class="variant-row-prices">
<span class="price-line<?= $showUnitPrice ? '' : ' is-price-placeholder' ?>" data-unit-price-row aria-hidden="<?= $showUnitPrice ? 'false' : 'true' ?>">
<span class="price-unit-label">Цена за <span data-unit-label><?= e($unitLabel) ?></span>:</span>
<span class="price-unit-values">
<span class="old-price" data-old-unit-price-display<?= $oldUnitPrice === null ? ' hidden' : '' ?>><?= e($oldUnitPrice === null ? '' : money_label($oldUnitPrice)) ?></span>
<b data-price-unit data-dynamic-unit-price data-base-unit-price="<?= e((string) $unitPrice) ?>"><?= e($unitPrice === null ? '' : money_label($unitPrice)) ?></b>
<button class="price-tier-trigger" type="button" aria-label="Показать варианты цены за наличный расчет">?</button>
</span>
</span>
<strong class="package-price-line">
<span class="package-price-label">За фасовку <span data-package-label-display><?= e($variantName) ?></span>:</span>
<span class="package-price-values">
<span class="old-price" data-old-package-price-display<?= $oldPackagePrice === null ? ' hidden' : '' ?>><?= e($oldPackagePrice === null ? '' : money_label($oldPackagePrice)) ?></span>
<span data-package-price data-dynamic-package-price data-base-package-price="<?= e((string) $packagePrice) ?>"><?= e($packagePrice === null ? '' : money_label($packagePrice)) ?></span>
<button class="price-tier-trigger" data-package-tier-trigger type="button" aria-label="Показать варианты цены за наличный расчет"<?= $showUnitPrice ? ' hidden' : '' ?>>?</button>
</span>
</strong>
<span class="package-price-note<?= $showUnitPrice ? '' : ' is-price-placeholder' ?>" data-package-price-note aria-hidden="<?= $showUnitPrice ? 'false' : 'true' ?>">Цена за <span data-unit-label-note><?= e($unitLabel) ?></span> x <span data-package-label-note><?= e($variantName) ?></span></span>
<div class="price-tier-popover" role="tooltip">
<strong>Варианты цены за <span data-tier-unit-label><?= e($tierUnit) ?></span> при наличном расчете:</strong>
<dl>
<div><dt>Базовая цена</dt><dd data-tier-base><?= e(money_label($tierBase)) ?></dd></div>
<div><dt>При заказе от 20 000р.</dt><dd data-tier-cash-20><?= e(money_label(floor($tierBase * 0.95))) ?></dd></div>
<div><dt>При заказе от 50 000р.</dt><dd data-tier-cash-50><?= e(money_label(floor($tierBase * 0.93))) ?></dd></div>
</dl>
</div>
</div>
<div class="product-card-actions">
<div class="quantity-stepper" data-quantity-control aria-label="Количество фасовок">
<button type="button" data-quantity-minus aria-label="Уменьшить количество">-</button>
<input data-quantity-input type="text" inputmode="numeric" value="1" aria-label="Количество">
<button type="button" data-quantity-plus aria-label="Увеличить количество">+</button>
</div>
<button class="add-to-cart-button" type="button">В корзину</button>
</div>
</div>
<?php endforeach; ?>
</section>
<?php endif; ?>
<p class="product-detail-preorder">На сайте оформляется предзаказ. Мы перезвоним, подтвердим наличие, фактический вес и удобное получение.</p>
</article>
<?php if (!empty($product['description'])): ?>
<section class="product-description panel">
<h2>Описание</h2>
<?= (string) $product['description'] ?>
</section>
<?php endif; ?>
</section>