превью относительно готово
This commit is contained in:
+20
-2
@@ -287,19 +287,24 @@ try {
|
||||
|
||||
const updateCardPrices = (card) => {
|
||||
const packageNode = card.querySelector('[data-dynamic-package-price]');
|
||||
const unitNode = card.querySelector('[data-dynamic-unit-price]');
|
||||
updateDynamicPrices(card);
|
||||
|
||||
if (packageNode) {
|
||||
const base = Number(packageNode.dataset.basePackagePrice || 0);
|
||||
if (unitNode || packageNode) {
|
||||
const unitBase = Number(unitNode?.dataset.baseUnitPrice || 0);
|
||||
const packageBase = Number(packageNode?.dataset.basePackagePrice || 0);
|
||||
const base = unitBase > 0 ? unitBase : packageBase;
|
||||
|
||||
const tiers = tierValues(base);
|
||||
const tierBase = card.querySelector('[data-tier-base]');
|
||||
const tierCash20 = card.querySelector('[data-tier-cash-20]');
|
||||
const tierCash50 = card.querySelector('[data-tier-cash-50]');
|
||||
const tierUnitLabel = card.querySelector('[data-tier-unit-label]');
|
||||
|
||||
if (tierBase) tierBase.textContent = formatRub(tiers.base);
|
||||
if (tierCash20) tierCash20.textContent = formatRub(tiers.cash20);
|
||||
if (tierCash50) tierCash50.textContent = formatRub(tiers.cash50);
|
||||
if (tierUnitLabel) tierUnitLabel.textContent = card.querySelector('[data-unit-label]')?.textContent || 'шт.';
|
||||
}
|
||||
|
||||
};
|
||||
@@ -327,9 +332,12 @@ try {
|
||||
const baseTotalNode = cartPage.querySelector('[data-cart-base-total]');
|
||||
const totalNode = cartPage.querySelector('[data-cart-current-total]');
|
||||
const modeNode = cartPage.querySelector('[data-cart-current-mode]');
|
||||
const savingRow = cartPage.querySelector('[data-cart-saving-row]');
|
||||
const savingNode = cartPage.querySelector('[data-cart-saving-total]');
|
||||
const items = getCartItems();
|
||||
const baseTotal = cartBaseTotal(items);
|
||||
const currentTotal = Math.floor(baseTotal * priceMode().multiplier);
|
||||
const savingTotal = Math.max(0, baseTotal - currentTotal);
|
||||
|
||||
if (emptyNode) {
|
||||
emptyNode.hidden = items.length !== 0;
|
||||
@@ -371,6 +379,14 @@ try {
|
||||
if (modeNode) {
|
||||
modeNode.textContent = priceMode().label;
|
||||
}
|
||||
|
||||
if (savingRow) {
|
||||
savingRow.hidden = savingTotal <= 0;
|
||||
}
|
||||
|
||||
if (savingNode) {
|
||||
savingNode.textContent = formatRub(savingTotal);
|
||||
}
|
||||
};
|
||||
|
||||
const updateModeButtons = () => {
|
||||
@@ -497,8 +513,10 @@ try {
|
||||
|
||||
saveCartItems(items);
|
||||
updateAllPrices();
|
||||
addButton.classList.add('is-added');
|
||||
addButton.textContent = 'Добавлено';
|
||||
window.setTimeout(() => {
|
||||
addButton.classList.remove('is-added');
|
||||
addButton.textContent = 'В корзину';
|
||||
}, 1200);
|
||||
});
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
<dt>Текущий режим</dt>
|
||||
<dd data-cart-current-mode>Наличные</dd>
|
||||
</div>
|
||||
<div class="cart-summary-saving" data-cart-saving-row hidden>
|
||||
<dt>Ваша выгода</dt>
|
||||
<dd data-cart-saving-total>0 руб.</dd>
|
||||
</div>
|
||||
<div class="cart-summary-total">
|
||||
<dt>Сумма к расчету</dt>
|
||||
<dd data-cart-current-total>0 руб.</dd>
|
||||
|
||||
@@ -29,6 +29,8 @@ $activeOldUnitPrice = ($activeOldPackagePrice !== null && $activePackageQuantity
|
||||
if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) {
|
||||
$activeOldUnitPrice = null;
|
||||
}
|
||||
$activeTierBase = $activeUnitPrice ?? $activePackagePrice;
|
||||
$activeTierUnit = unit_label((string) ($activeVariant['unit'] ?? '')) ?: 'шт.';
|
||||
?>
|
||||
<article
|
||||
class="product-card price-aware"
|
||||
@@ -97,9 +99,12 @@ if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) {
|
||||
|
||||
<?php if ($activeVariant['price_per_unit'] !== null): ?>
|
||||
<span class="price-line">
|
||||
Цена за <span data-unit-label><?= e(unit_label((string) $activeVariant['unit'])) ?></span>:
|
||||
<span class="old-price" data-old-unit-price-display<?= $activeOldUnitPrice === null ? ' hidden' : '' ?>><?= e(money_label($activeOldUnitPrice)) ?></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 class="price-unit-label">Цена за <span data-unit-label><?= e(unit_label((string) $activeVariant['unit'])) ?></span>:</span>
|
||||
<span class="price-unit-values">
|
||||
<span class="old-price" data-old-unit-price-display<?= $activeOldUnitPrice === null ? ' hidden' : '' ?>><?= e(money_label($activeOldUnitPrice)) ?></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>
|
||||
<button class="price-tier-trigger" type="button" aria-label="Показать градацию цены">?</button>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -110,7 +115,6 @@ if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) {
|
||||
<span class="old-price" data-old-package-price-display<?= $activeOldPackagePrice === null ? ' hidden' : '' ?>><?= e(money_label($activeOldPackagePrice)) ?></span>
|
||||
<span data-package-price data-dynamic-package-price data-base-package-price="<?= e((string) $activePackagePrice) ?>"><?= e(money_label($activeVariant['package_price'])) ?></span>
|
||||
</span>
|
||||
<button class="price-tier-trigger" type="button" aria-label="Показать градацию цены">?</button>
|
||||
</strong>
|
||||
<?php if ($activeVariant['price_per_unit'] !== null): ?>
|
||||
<span class="package-price-note">Цена за <span data-unit-label-note><?= e(unit_label((string) $activeVariant['unit'])) ?></span> × <span data-package-label-note><?= e((string) $activeVariant['name']) ?></span></span>
|
||||
@@ -118,11 +122,11 @@ if ($activeOldUnitPrice !== null && $activeOldUnitPrice <= $activeUnitPrice) {
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="price-tier-popover" role="tooltip">
|
||||
<strong>Варианты цены за наличный расчет:</strong>
|
||||
<strong>Варианты цены за <span data-tier-unit-label><?= e($activeTierUnit) ?></span> при наличном расчете:</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-base><?= e(money_label($activeTierBase)) ?></dd></div>
|
||||
<div><dt>При заказе от 20 000р.</dt><dd data-tier-cash-20><?= e(money_label(floor($activeTierBase * 0.95))) ?></dd></div>
|
||||
<div><dt>При заказе от 50 000р.</dt><dd data-tier-cash-50><?= e(money_label(floor($activeTierBase * 0.93))) ?></dd></div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user