61 lines
3.1 KiB
PHP
61 lines
3.1 KiB
PHP
@php
|
||
$favoriteIds = array_map('intval', (array) session('favorites', []));
|
||
$compareIds = array_map('intval', (array) session('compare', []));
|
||
$isFavorite = in_array($product->id, $favoriteIds, true);
|
||
$isCompared = in_array($product->id, $compareIds, true);
|
||
$cartItems = (array) session('cart', []);
|
||
$isInCart = isset($cartItems[$product->id]);
|
||
@endphp
|
||
|
||
<article class="pc-card pc-product-card">
|
||
<div class="pc-product-media">
|
||
<div class="pc-product-tools">
|
||
<form method="post" action="{{ route('favorites.toggle', $product) }}" class="pc-product-tool-form" data-preserve-scroll="true">
|
||
@csrf
|
||
<button class="pc-product-tool {{ $isFavorite ? 'is-active' : '' }}" type="submit" aria-label="Добавить в избранное" title="В избранное">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<path d="M12 20s-7-4.5-9-9c-1.2-2.7.7-6 4.2-6 2 0 3.2 1 3.8 2 0.6-1 1.8-2 3.8-2 3.5 0 5.4 3.3 4.2 6-2 4.5-9 9-9 9z"></path>
|
||
</svg>
|
||
</button>
|
||
</form>
|
||
<form method="post" action="{{ route('compare.toggle', $product) }}" class="pc-product-tool-form" data-preserve-scroll="true">
|
||
@csrf
|
||
<button class="pc-product-tool {{ $isCompared ? 'is-active' : '' }}" type="submit" aria-label="Добавить в сравнение" title="Сравнить">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<path d="M5 4h3v16H5zM16 4h3v16h-3zM10.5 8h3v12h-3z"></path>
|
||
</svg>
|
||
</button>
|
||
</form>
|
||
</div>
|
||
@if (!empty($product->image_url))
|
||
<img class="pc-product-image" src="{{ $product->image_url }}" alt="{{ $product->name }}" loading="lazy" decoding="async">
|
||
@else
|
||
<div class="pc-product-image" role="img" aria-label="{{ $product->name }}"></div>
|
||
@endif
|
||
</div>
|
||
<h3>
|
||
<a class="pc-product-link" href="{{ route('products.show', $product) }}">{{ $product->name }}</a>
|
||
</h3>
|
||
@if (!empty($product->short_description))
|
||
<p>{{ $product->short_description }}</p>
|
||
@endif
|
||
<div class="pc-product-meta">
|
||
<strong>{{ number_format($product->price, 0, '.', ' ') }} {{ config('shop.currency_symbol', '₽') }}</strong>
|
||
@if (!empty($product->old_price))
|
||
<span class="pc-product-old">{{ number_format($product->old_price, 0, '.', ' ') }} {{ config('shop.currency_symbol', '₽') }}</span>
|
||
@endif
|
||
</div>
|
||
<div class="pc-product-actions">
|
||
@if ($product->stock > 0)
|
||
<form method="post" action="{{ route('cart.add', $product) }}" data-preserve-scroll="true">
|
||
@csrf
|
||
<button class="pc-btn ghost {{ $isInCart ? 'is-active' : '' }}" type="submit">
|
||
{{ $isInCart ? 'В корзине' : 'В корзину' }}
|
||
</button>
|
||
</form>
|
||
@else
|
||
<button class="pc-btn ghost" type="button" disabled>Нет в наличии</button>
|
||
@endif
|
||
</div>
|
||
</article>
|