Files
shop10/src/views/product.ejs
T

88 lines
4.7 KiB
Plaintext
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.
<%- include('partials/layout-start') %>
<article class="product-detail">
<div class="product-detail__media">
<% if (product.image_url) { %>
<img src="<%= product.image_url %>" alt="<%= product.name %>" class="product-detail__image">
<% } else { %>
<div class="card__placeholder product-detail__image">Нет фото</div>
<% } %>
</div>
<div class="product-detail__info">
<% if (product.category_name) { %>
<a href="/?category=<%= product.category_slug %>" class="card__category"><%= product.category_name %></a>
<% } %>
<h1><%= product.name %></h1>
<p class="product-detail__price"><%= formatPrice(product.price_cents) %></p>
<p class="product-detail__desc"><%= product.description %></p>
<p class="product-detail__stock">В наличии: <strong><%= product.stock %></strong> шт.</p>
<% if (error) { %><p class="alert alert--error"><%= error %></p><% } %>
<% if (notifySuccess) { %><p class="alert alert--success"><%= notifySuccess %></p><% } %>
<% if (notifyError) { %><p class="alert alert--error"><%= notifyError %></p><% } %>
<% if (reserved) { %><p class="alert alert--success">Товар успешно забронирован. Подробности на почте и в личном кабинете.</p><% } %>
<% if (userReservation) { %>
<p class="alert alert--success">
У вас активная бронь: <%= userReservation.quantity %> шт. до <%= new Date(userReservation.expires_at).toLocaleString('ru-RU') %>.
<a href="/account?tab=reservations">Мои бронирования</a>
</p>
<% } %>
<% if (product.stock > 0) { %>
<form action="/cart/add" method="post" class="product-detail__form">
<input type="hidden" name="product_id" value="<%= product.id %>">
<label class="label">
Количество
<input type="number" name="quantity" value="1" min="1" max="<%= product.stock %>" class="input input--qty">
</label>
<input type="hidden" name="redirect" value="/cart">
<button type="submit" class="btn btn--primary btn--lg">Добавить в корзину</button>
</form>
<% if (user && !userReservation) { %>
<form action="/reservations" method="post" class="product-detail__form">
<input type="hidden" name="product_id" value="<%= product.id %>">
<input type="hidden" name="slug" value="<%= product.slug %>">
<label class="label">
Бронь (48 ч)
<input type="number" name="quantity" value="1" min="1" max="<%= product.stock %>" class="input input--qty">
</label>
<button type="submit" class="btn btn--ghost btn--lg">Забронировать</button>
</form>
<% } else if (!user) { %>
<p class="muted">Для бронирования <a href="/login">войдите</a> в аккаунт.</p>
<% } %>
<% } else { %>
<p class="alert alert--warn">Нет в наличии</p>
<% if (typeof cookieConsent !== 'undefined' && !cookieConsent) { %>
<p class="muted">Примите cookies, чтобы подписаться на уведомление о поступлении.</p>
<% } else if (stockAlertSubscribed) { %>
<p class="stock-notify stock-notify--done">
Вы подписаны на уведомление<% if (notifyEmail) { %> — письмо придёт на <strong><%= notifyEmail %></strong><% } %>.
</p>
<% } else { %>
<section class="stock-notify card">
<h2 class="stock-notify__title">Сообщить о поступлении</h2>
<p class="muted stock-notify__hint">Будьте среди первых, кто узнает, когда товар снова появится в наличии.</p>
<form action="/product/<%= product.slug %>/notify-stock" method="post" class="form stock-notify__form">
<% if (user && notifyEmail) { %>
<p class="muted">Уведомление отправим на <strong><%= notifyEmail %></strong></p>
<input type="hidden" name="email" value="<%= notifyEmail %>">
<% } else { %>
<label class="label">
Email
<input type="email" name="email" class="input" required autocomplete="email" placeholder="you@example.com" value="<%= notifyEmail || '' %>">
</label>
<% } %>
<button type="submit" class="btn btn--primary">Подписаться</button>
</form>
</section>
<% } %>
<% } %>
<a href="/" class="link-back">← Назад в каталог</a>
</div>
</article>
<%- include('partials/layout-end') %>