84 lines
4.8 KiB
PHP
84 lines
4.8 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
/** @var array<string, mixed> $product */
|
||
$variants = $product['preview_variants'] ?? [];
|
||
$activeVariant = $variants[0] ?? [
|
||
'name' => $product['variant_name'] ?? '',
|
||
'unit' => $product['unit'] ?? '',
|
||
'price_per_unit' => $product['price_per_unit'] ?? null,
|
||
'package_price' => $product['package_price'] ?? null,
|
||
'old_package_price' => $product['old_package_price'] ?? null,
|
||
];
|
||
$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'];
|
||
?>
|
||
<article
|
||
class="product-card price-aware"
|
||
id="<?= e($cardId) ?>"
|
||
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((string) ($product['main_image_path'] ?? '')) ?>"
|
||
>
|
||
<?php if (!empty($product['main_image_path'])): ?>
|
||
<a class="product-card-image" href="/product/<?= e($product['slug']) ?>" aria-label="<?= e($product['name']) ?>">
|
||
<img src="<?= e((string) $product['main_image_path']) ?>" alt="<?= e((string) $product['name']) ?>">
|
||
</a>
|
||
<?php endif; ?>
|
||
|
||
<p class="product-category"><?= e($product['category_display_name'] ?? $product['category_name'] ?? 'Каталог') ?></p>
|
||
<h3><a href="/product/<?= e($product['slug']) ?>"><?= e($product['name']) ?></a></h3>
|
||
|
||
<?php if ($activeVariant['price_per_unit'] !== null): ?>
|
||
<span class="price-line">Цена за <span data-unit-label><?= e(unit_label((string) $activeVariant['unit'])) ?></span>: <b data-price-unit data-dynamic-unit-price data-base-unit-price="<?= e((string) $activeUnitPrice) ?>"><?= e(money_label($activeVariant['price_per_unit'])) ?></b></span>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($activeVariant['package_price'] !== null): ?>
|
||
<strong class="package-price-line">
|
||
<span class="old-price" data-old-price<?= empty($activeVariant['old_package_price']) ? ' hidden' : '' ?>><?= e(money_label($activeVariant['old_package_price'] ?? null)) ?></span>
|
||
За упаковку: <span data-package-price data-dynamic-package-price data-base-package-price="<?= e((string) $activePackagePrice) ?>"><?= e(money_label($activeVariant['package_price'])) ?></span>
|
||
<button class="price-tier-trigger" type="button" aria-label="Показать градацию цены">?</button>
|
||
</strong>
|
||
<?php endif; ?>
|
||
|
||
<div class="price-tier-popover" role="tooltip">
|
||
<strong>Варианты цены</strong>
|
||
<dl>
|
||
<div><dt>Базовая цена</dt><dd data-tier-base><?= e(money_label($activePackagePrice)) ?></dd></div>
|
||
<div><dt>Цена при сумме заказа от 20 000р. наличными</dt><dd data-tier-cash-20><?= e(money_label(floor($activePackagePrice * 0.95))) ?></dd></div>
|
||
<div><dt>Цена при сумме заказа от 50 000р. наличными</dt><dd data-tier-cash-50><?= e(money_label(floor($activePackagePrice * 0.93))) ?></dd></div>
|
||
<div><dt>Оплата по расчетному счету</dt><dd data-tier-invoice><?= e(money_label(floor($activePackagePrice * 1.08))) ?></dd></div>
|
||
</dl>
|
||
</div>
|
||
|
||
<?php if ($variants !== []): ?>
|
||
<div class="variant-choice" aria-label="Выбор фасовки">
|
||
<span>Фасовка:</span>
|
||
<div class="variant-choice-list">
|
||
<?php foreach ($variants as $index => $variant): ?>
|
||
<button
|
||
class="variant-choice-button<?= $index === 0 ? ' is-active' : '' ?>"
|
||
type="button"
|
||
data-card="<?= e($cardId) ?>"
|
||
data-variant-id="<?= e((string) ($variant['id'] ?? $index)) ?>"
|
||
data-variant-name="<?= e((string) ($variant['name'] ?? '')) ?>"
|
||
data-unit="<?= e(unit_label((string) $variant['unit'])) ?>"
|
||
data-base-unit-price="<?= e((string) ($variant['price_per_unit'] ?? '')) ?>"
|
||
data-base-package-price="<?= e((string) ($variant['package_price'] ?? '')) ?>"
|
||
data-price-unit="<?= e(money_label($variant['price_per_unit'])) ?>"
|
||
data-package-price="<?= e(money_label($variant['package_price'])) ?>"
|
||
data-old-price="<?= e(money_label($variant['old_package_price'] ?? null)) ?>"
|
||
>
|
||
<?= e((string) $variant['name']) ?>
|
||
</button>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<button class="add-to-cart-button" type="button">В корзину</button>
|
||
</article>
|