Vinoteca: wine shop on 1C-Bitrix (module, template, components, pages)
This commit is contained in:
commit
0590195880
593 files changed
+27942
No files matched your search
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Bitrix\Main\Context;
|
||||
use Bitrix\Main\Localization\Loc;
|
||||
use Jinove\Vinoteca\Checkout;
|
||||
use Jinove\Vinoteca\Money;
|
||||
|
||||
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
|
||||
die();
|
||||
}
|
||||
|
||||
Loc::loadMessages(__FILE__);
|
||||
|
||||
class JinoveOrderDoneComponent extends CBitrixComponent
|
||||
{
|
||||
public function executeComponent(): array
|
||||
{
|
||||
global $APPLICATION;
|
||||
$APPLICATION->SetPageProperty("vino_alternates", "N");
|
||||
$APPLICATION->SetPageProperty("vino_schema", "N");
|
||||
$APPLICATION->SetPageProperty("robots", "noindex, nofollow");
|
||||
$query = Context::getCurrent()->getRequest()->getQueryList()->toArray();
|
||||
$order = Checkout::find((int)($query["id"] ?? 0), (string)($query["hash"] ?? ""));
|
||||
$state = "missing";
|
||||
$data = [];
|
||||
if ($order !== null && !$order->isCanceled()) {
|
||||
$method = Checkout::methodOf($order);
|
||||
if ($method !== "cash" && ($query["cancel"] ?? "") !== "Y") {
|
||||
Checkout::finishPayment($order, $query);
|
||||
$order = \Bitrix\Sale\Order::load($order->getId());
|
||||
}
|
||||
$payment = $order->getPaymentCollection()->current();
|
||||
$state = $method !== "cash" ? ($payment !== null && $payment->isPaid() ? "paid" : "pending") : "cash";
|
||||
$properties = [];
|
||||
foreach ($order->getPropertyCollection() as $property) {
|
||||
$properties[(string)$property->getField("CODE")] = (string)$property->getValue();
|
||||
}
|
||||
$items = [];
|
||||
foreach ($order->getBasket() as $item) {
|
||||
$items[] = [
|
||||
"name" => (string)$item->getField("NAME"),
|
||||
"quantity" => (int)$item->getQuantity(),
|
||||
"sum" => Money::format((float)$item->getFinalPrice(), (string)$item->getCurrency()),
|
||||
];
|
||||
}
|
||||
$data = [
|
||||
"ID" => (int)$order->getId(),
|
||||
"HASH" => (string)$order->getHash(),
|
||||
"NUMBER" => (string)$order->getField("ACCOUNT_NUMBER"),
|
||||
"TOTAL" => Money::format((float)$order->getPrice(), (string)$order->getCurrency()),
|
||||
"NAME" => $properties["NAME"] ?? "",
|
||||
"PHONE" => $properties["PHONE"] ?? "",
|
||||
"EMAIL" => $properties["EMAIL"] ?? "",
|
||||
"METHOD" => $payment !== null ? (string)Loc::getMessage("VINO_PAY_" . strtoupper($method)) : "",
|
||||
"ITEMS" => $items,
|
||||
"CANCELLED" => ($query["cancel"] ?? "") === "Y",
|
||||
];
|
||||
}
|
||||
$title = (string)Loc::getMessage("VINO_DONE_TITLE_" . strtoupper($state));
|
||||
$APPLICATION->SetTitle($title);
|
||||
$APPLICATION->SetPageProperty("title", $title . " | Vinoteca");
|
||||
$APPLICATION->SetPageProperty("description", (string)Loc::getMessage("VINO_DONE_DESCRIPTION"));
|
||||
$this->arResult = ["STATE" => $state, "TITLE" => $title, "ORDER" => $data, "CATALOG_URL" => SITE_DIR . "catalog/", "AUTOPAY" => ($query["autopay"] ?? "") === "Y", "PAY_FAILED" => ($query["pay"] ?? "") === "failed"];
|
||||
$this->includeComponentTemplate();
|
||||
|
||||
return $this->arResult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_TITLE_MISSING"] = "Order not found";
|
||||
$MESS["VINO_DONE_TITLE_CASH"] = "Order placed";
|
||||
$MESS["VINO_DONE_TITLE_PAID"] = "Order paid";
|
||||
$MESS["VINO_DONE_TITLE_PENDING"] = "Complete your payment";
|
||||
$MESS["VINO_DONE_DESCRIPTION"] = "Order status at Vinoteca.";
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_TITLE_MISSING"] = "Nie znaleziono zamówienia";
|
||||
$MESS["VINO_DONE_TITLE_CASH"] = "Zamówienie złożone";
|
||||
$MESS["VINO_DONE_TITLE_PAID"] = "Zamówienie opłacone";
|
||||
$MESS["VINO_DONE_TITLE_PENDING"] = "Dokończenie płatności";
|
||||
$MESS["VINO_DONE_DESCRIPTION"] = "Status zamówienia w Vinoteca.";
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_TITLE_MISSING"] = "Заказ не найден";
|
||||
$MESS["VINO_DONE_TITLE_CASH"] = "Заказ оформлен";
|
||||
$MESS["VINO_DONE_TITLE_PAID"] = "Заказ оплачен";
|
||||
$MESS["VINO_DONE_TITLE_PENDING"] = "Завершение оплаты";
|
||||
$MESS["VINO_DONE_DESCRIPTION"] = "Статус заказа в винотеке Vinoteca.";
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_NUMBER"] = "Order number";
|
||||
$MESS["VINO_DONE_LEAD_CASH"] = "Your order has been received. Pay on pickup by card or cash. Collect it from the warehouse at 251 Krasnaya St.";
|
||||
$MESS["VINO_DONE_LEAD_PAID"] = "Thank you, the payment went through. Collect the order from the warehouse at 251 Krasnaya St.";
|
||||
$MESS["VINO_DONE_LEAD_PENDING"] = "The order was created, but the payment is not completed. You can finish it now.";
|
||||
$MESS["VINO_DONE_LEAD_CANCEL"] = "The payment was cancelled. The order is saved and can be paid now.";
|
||||
$MESS["VINO_DONE_LEAD_MISSING"] = "Check the link or open the catalogue.";
|
||||
$MESS["VINO_DONE_PAY"] = "Pay now";
|
||||
$MESS["VINO_DONE_PAY_FAIL"] = "Could not open the payment. Please try again.";
|
||||
$MESS["VINO_DONE_DEMO"] = "This is a demo site: orders are not fulfilled, payment is in test mode.";
|
||||
$MESS["VINO_DONE_ITEMS"] = "Order items";
|
||||
$MESS["VINO_DONE_TOTAL"] = "Total";
|
||||
$MESS["VINO_DONE_CONTACTS"] = "Contact details";
|
||||
$MESS["VINO_DONE_PAYMENT"] = "Payment";
|
||||
$MESS["VINO_DONE_PICKUP"] = "Collection";
|
||||
$MESS["VINO_DONE_PICKUP_TEXT"] = "Pickup from the warehouse at 251 Krasnaya St.";
|
||||
$MESS["VINO_DONE_TO_CATALOG"] = "Browse the catalogue";
|
||||
$MESS["VINO_DONE_BUSY"] = "Redirecting to payment…";
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_NUMBER"] = "Numer zamówienia";
|
||||
$MESS["VINO_DONE_LEAD_CASH"] = "Zamówienie zostało przyjęte. Płatność przy odbiorze: kartą lub gotówką. Odbierz je z magazynu przy ul. Krasnej 251.";
|
||||
$MESS["VINO_DONE_LEAD_PAID"] = "Dziękujemy, płatność przeszła. Odbierz zamówienie z magazynu przy ul. Krasnej 251.";
|
||||
$MESS["VINO_DONE_LEAD_PENDING"] = "Zamówienie zostało utworzone, ale płatność nie została zakończona. Możesz ją dokończyć teraz.";
|
||||
$MESS["VINO_DONE_LEAD_CANCEL"] = "Płatność została anulowana. Zamówienie jest zapisane, możesz je teraz opłacić.";
|
||||
$MESS["VINO_DONE_LEAD_MISSING"] = "Sprawdź link lub otwórz katalog.";
|
||||
$MESS["VINO_DONE_PAY"] = "Zapłać";
|
||||
$MESS["VINO_DONE_PAY_FAIL"] = "Nie udało się otworzyć płatności. Spróbuj ponownie.";
|
||||
$MESS["VINO_DONE_DEMO"] = "To strona demonstracyjna: zamówienia nie są realizowane, płatność w trybie testowym.";
|
||||
$MESS["VINO_DONE_ITEMS"] = "Skład zamówienia";
|
||||
$MESS["VINO_DONE_TOTAL"] = "Razem";
|
||||
$MESS["VINO_DONE_CONTACTS"] = "Dane kontaktowe";
|
||||
$MESS["VINO_DONE_PAYMENT"] = "Płatność";
|
||||
$MESS["VINO_DONE_PICKUP"] = "Odbiór";
|
||||
$MESS["VINO_DONE_PICKUP_TEXT"] = "Odbiór osobisty z magazynu przy ul. Krasnej 251";
|
||||
$MESS["VINO_DONE_TO_CATALOG"] = "Przejdź do katalogu";
|
||||
$MESS["VINO_DONE_BUSY"] = "Przechodzimy do płatności…";
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
$MESS["VINO_DONE_NUMBER"] = "Номер заказа";
|
||||
$MESS["VINO_DONE_LEAD_CASH"] = "Заказ принят. Оплата при получении: картой или наличными. Заберите его со склада на ул. Красной, 251.";
|
||||
$MESS["VINO_DONE_LEAD_PAID"] = "Спасибо, оплата прошла. Заберите заказ со склада на ул. Красной, 251.";
|
||||
$MESS["VINO_DONE_LEAD_PENDING"] = "Заказ создан, но оплата не завершена. Завершить её можно сейчас.";
|
||||
$MESS["VINO_DONE_LEAD_CANCEL"] = "Оплата была отменена. Заказ сохранён, оплатить его можно сейчас.";
|
||||
$MESS["VINO_DONE_LEAD_MISSING"] = "Проверьте ссылку или откройте каталог.";
|
||||
$MESS["VINO_DONE_PAY"] = "Оплатить";
|
||||
$MESS["VINO_DONE_PAY_FAIL"] = "Не получилось открыть оплату. Попробуйте ещё раз.";
|
||||
$MESS["VINO_DONE_DEMO"] = "Сайт демонстрационный: заказы не выполняются, оплата в тестовом режиме.";
|
||||
$MESS["VINO_DONE_ITEMS"] = "Состав заказа";
|
||||
$MESS["VINO_DONE_TOTAL"] = "Итого";
|
||||
$MESS["VINO_DONE_CONTACTS"] = "Контакты";
|
||||
$MESS["VINO_DONE_PAYMENT"] = "Оплата";
|
||||
$MESS["VINO_DONE_PICKUP"] = "Получение";
|
||||
$MESS["VINO_DONE_PICKUP_TEXT"] = "Самовывоз со склада на ул. Красной, 251";
|
||||
$MESS["VINO_DONE_TO_CATALOG"] = "Перейти в каталог";
|
||||
$MESS["VINO_DONE_BUSY"] = "Переходим к оплате…";
|
||||
@@ -0,0 +1,69 @@
|
||||
(function () {
|
||||
var root = document.querySelector('[data-done]');
|
||||
if (!root || !window.BX || !BX.ajax || !BX.ajax.runAction) return;
|
||||
var button = root.querySelector('[data-done-pay]');
|
||||
if (!button) return;
|
||||
var error = root.querySelector('[data-done-error]');
|
||||
|
||||
function busy(on) {
|
||||
button.disabled = on;
|
||||
if (!window.VinoBusy) return;
|
||||
if (on) VinoBusy.show(root.getAttribute('data-text-busy'));
|
||||
else VinoBusy.hide();
|
||||
}
|
||||
|
||||
function fail() {
|
||||
busy(false);
|
||||
error.textContent = root.getAttribute('data-text-fail');
|
||||
error.hidden = false;
|
||||
}
|
||||
|
||||
function openWidget(widget) {
|
||||
var start = function () {
|
||||
if (!window.halyk || !halyk.pay) return fail();
|
||||
halyk.pay(widget.payment);
|
||||
busy(false);
|
||||
};
|
||||
if (window.halyk && halyk.pay) return start();
|
||||
var script = document.createElement('script');
|
||||
script.src = widget.script;
|
||||
script.onload = start;
|
||||
script.onerror = fail;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
function pay() {
|
||||
busy(true);
|
||||
error.hidden = true;
|
||||
BX.ajax.runAction('jinove:vinoteca.order.pay', {
|
||||
data: {
|
||||
id: root.getAttribute('data-id'),
|
||||
hash: root.getAttribute('data-hash'),
|
||||
base: root.getAttribute('data-base') || '/'
|
||||
}
|
||||
}).then(function (res) {
|
||||
var data = res && res.data;
|
||||
if (data && data.redirect) {
|
||||
window.location.href = data.redirect;
|
||||
return;
|
||||
}
|
||||
if (data && data.widget) {
|
||||
openWidget(data.widget);
|
||||
return;
|
||||
}
|
||||
throw new Error('pay');
|
||||
}).catch(fail);
|
||||
}
|
||||
|
||||
window.addEventListener('pageshow', function (e) {
|
||||
if (e.persisted) busy(false);
|
||||
});
|
||||
|
||||
button.addEventListener('click', pay);
|
||||
if (root.hasAttribute('data-autopay')) {
|
||||
var address = new URL(window.location.href);
|
||||
address.searchParams.delete('autopay');
|
||||
window.history.replaceState(null, '', address.pathname + address.search + address.hash);
|
||||
pay();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,130 @@
|
||||
.vino-done {
|
||||
padding: var(--space-10) var(--gutter) var(--space-section);
|
||||
}
|
||||
.vino-done__inner {
|
||||
display: grid;
|
||||
gap: var(--space-6);
|
||||
justify-items: start;
|
||||
max-width: var(--container);
|
||||
margin: 0 auto;
|
||||
}
|
||||
.vino-done__lead {
|
||||
max-width: 640px;
|
||||
margin: 0;
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--text-17);
|
||||
line-height: var(--leading-text);
|
||||
}
|
||||
.vino-done__number {
|
||||
margin: 0;
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--text-15);
|
||||
}
|
||||
.vino-done__number-value {
|
||||
color: var(--color-accent);
|
||||
font-family: var(--font-serif);
|
||||
font-size: var(--fs-h4);
|
||||
font-weight: 500;
|
||||
font-variant-numeric: lining-nums;
|
||||
}
|
||||
.vino-done__pay {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
justify-items: start;
|
||||
}
|
||||
.vino-done__error {
|
||||
min-height: calc(var(--text-15) * 1.45);
|
||||
margin: 0;
|
||||
color: var(--color-danger-soft);
|
||||
font-size: var(--text-15);
|
||||
}
|
||||
.vino-done__error[hidden] {
|
||||
display: block;
|
||||
visibility: hidden;
|
||||
}
|
||||
.vino-done__grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
|
||||
gap: var(--space-grid-base);
|
||||
align-items: start;
|
||||
width: 100%;
|
||||
}
|
||||
.vino-done__card {
|
||||
margin: 0;
|
||||
padding: var(--space-card);
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
.vino-done__title {
|
||||
margin: 0 0 var(--space-4);
|
||||
font-family: var(--font-serif);
|
||||
font-size: var(--fs-h4);
|
||||
font-weight: 400;
|
||||
line-height: var(--leading-title);
|
||||
}
|
||||
.vino-done__items {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.vino-done__item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-4);
|
||||
font-size: var(--text-15);
|
||||
}
|
||||
.vino-done__item-qty {
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.vino-done__item-sum {
|
||||
color: var(--color-accent);
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.vino-done__total {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-4);
|
||||
margin: var(--space-4) 0 0;
|
||||
padding-top: var(--space-4);
|
||||
border-top: 1px solid var(--color-line);
|
||||
font-size: var(--text-19);
|
||||
font-weight: 600;
|
||||
}
|
||||
.vino-done__facts {
|
||||
display: grid;
|
||||
gap: var(--space-5);
|
||||
}
|
||||
.vino-done__fact {
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
.vino-done__fact-term {
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--text-13);
|
||||
}
|
||||
.vino-done__fact-value {
|
||||
margin: 0;
|
||||
font-size: var(--text-15);
|
||||
line-height: var(--leading-text);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.vino-done__demo {
|
||||
margin: 0;
|
||||
color: var(--color-text-faint);
|
||||
font-size: var(--text-13);
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.vino-done__grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.vino-done {
|
||||
padding-top: var(--space-6);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
use Bitrix\Main\Localization\Loc;
|
||||
|
||||
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
|
||||
die();
|
||||
}
|
||||
|
||||
Loc::loadMessages(__FILE__);
|
||||
$state = $arResult["STATE"];
|
||||
$order = $arResult["ORDER"];
|
||||
$text = static fn(string $key): string => htmlspecialcharsbx((string)Loc::getMessage($key));
|
||||
$lead = $state === "pending" && !empty($order["CANCELLED"]) ? "VINO_DONE_LEAD_CANCEL" : "VINO_DONE_LEAD_" . strtoupper($state);
|
||||
?>
|
||||
<section class="vino-razdel-hero">
|
||||
<div class="vino-wrap">
|
||||
<?php \Jinove\Vinoteca\Breadcrumbs::show(array(array($arResult["TITLE"]))); ?>
|
||||
<h1 class="vino-razdel-hero__title"><?= htmlspecialcharsbx($arResult["TITLE"]) ?></h1>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="vino-done" data-done data-base="<?= htmlspecialcharsbx(SITE_DIR) ?>" data-text-fail="<?= $text("VINO_DONE_PAY_FAIL") ?>" data-text-busy="<?= $text("VINO_DONE_BUSY") ?>"<?= $state === "pending" && $arResult["AUTOPAY"] ? " data-autopay" : "" ?><?= $state !== "missing" ? ' data-id="' . (int)$order["ID"] . '" data-hash="' . htmlspecialcharsbx($order["HASH"]) . '"' : "" ?>>
|
||||
<div class="vino-done__inner">
|
||||
<p class="vino-done__lead"><?= $text($lead) ?></p>
|
||||
<?php if ($state === "missing"): ?>
|
||||
<a class="vino-btn" href="<?= htmlspecialcharsbx($arResult["CATALOG_URL"]) ?>"><?= $text("VINO_DONE_TO_CATALOG") ?></a>
|
||||
<?php else: ?>
|
||||
<p class="vino-done__number"><?= $text("VINO_DONE_NUMBER") ?>: <b class="vino-done__number-value"><?= htmlspecialcharsbx($order["NUMBER"]) ?></b></p>
|
||||
<?php if ($state === "pending"): ?>
|
||||
<div class="vino-done__pay">
|
||||
<button class="vino-btn" type="button" data-done-pay><?= $text("VINO_DONE_PAY") ?></button>
|
||||
<p class="vino-done__error" role="alert" data-done-error<?= $arResult["PAY_FAILED"] ? "" : " hidden" ?>><?= $arResult["PAY_FAILED"] ? $text("VINO_DONE_PAY_FAIL") : "" ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="vino-done__grid">
|
||||
<div class="vino-done__card">
|
||||
<h2 class="vino-done__title"><?= $text("VINO_DONE_ITEMS") ?></h2>
|
||||
<ul class="vino-done__items">
|
||||
<?php foreach ($order["ITEMS"] as $item): ?>
|
||||
<li class="vino-done__item"><span class="vino-done__item-name"><?= htmlspecialcharsbx($item["name"]) ?> <span class="vino-done__item-qty">× <?= (int)$item["quantity"] ?></span></span><span class="vino-done__item-sum"><?= htmlspecialcharsbx($item["sum"]) ?></span></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<p class="vino-done__total"><span><?= $text("VINO_DONE_TOTAL") ?></span><span><?= htmlspecialcharsbx($order["TOTAL"]) ?></span></p>
|
||||
</div>
|
||||
<dl class="vino-done__card vino-done__facts">
|
||||
<div class="vino-done__fact"><dt class="vino-done__fact-term"><?= $text("VINO_DONE_CONTACTS") ?></dt><dd class="vino-done__fact-value"><?= htmlspecialcharsbx($order["NAME"]) ?><br><?= htmlspecialcharsbx($order["PHONE"]) ?><br><?= htmlspecialcharsbx($order["EMAIL"]) ?></dd></div>
|
||||
<div class="vino-done__fact"><dt class="vino-done__fact-term"><?= $text("VINO_DONE_PICKUP") ?></dt><dd class="vino-done__fact-value"><?= $text("VINO_DONE_PICKUP_TEXT") ?></dd></div>
|
||||
<div class="vino-done__fact"><dt class="vino-done__fact-term"><?= $text("VINO_DONE_PAYMENT") ?></dt><dd class="vino-done__fact-value"><?= htmlspecialcharsbx($order["METHOD"]) ?></dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
<p class="vino-done__demo"><?= $text("VINO_DONE_DEMO") ?></p>
|
||||
<a class="vino-btn vino-btn--outline" href="<?= htmlspecialcharsbx($arResult["CATALOG_URL"]) ?>"><?= $text("VINO_DONE_TO_CATALOG") ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
Reference in new issue
Block a user