отображение ненужных цен за кг
This commit is contained in:
+101
-21
@@ -71,15 +71,17 @@ try {
|
||||
|
||||
<?php require base_path('views/partials/mega-category-menu.php'); ?>
|
||||
|
||||
<section class="price-mode-bar" aria-label="Режим отображения цен">
|
||||
<section class="price-mode-bar" aria-label="Система оплаты при получении">
|
||||
<div class="price-mode-inner">
|
||||
<span>Показывать цены:</span>
|
||||
<span>Выберите систему оплаты при получении:</span>
|
||||
<div class="price-mode-options" role="group" aria-label="Способ оплаты">
|
||||
<button type="button" class="price-mode-button is-active" data-payment-mode="cash">Наличными</button>
|
||||
<button type="button" class="price-mode-button price-mode-button-cash is-active" data-payment-mode="cash">
|
||||
<span>Наличными</span>
|
||||
<b>Выгодно от 7000р.</b>
|
||||
</button>
|
||||
<button type="button" class="price-mode-button" data-payment-mode="qr">QR-код</button>
|
||||
<button type="button" class="price-mode-button" data-payment-mode="invoice">Расчетный счет</button>
|
||||
</div>
|
||||
<small data-price-mode-note>Скидка наличными применится автоматически от суммы корзины.</small>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -245,22 +247,33 @@ try {
|
||||
const total = getCartTotal();
|
||||
|
||||
if (payment === 'invoice') {
|
||||
return { multiplier: 1.08, label: 'Оплата по расчетному счету: +8%' };
|
||||
return { multiplier: 1.08, fixedDiscount: 0, label: 'Оплата по расчетному счету: +8%' };
|
||||
}
|
||||
|
||||
if (payment === 'qr') {
|
||||
return { multiplier: 1, label: 'QR-код: базовая цена' };
|
||||
return { multiplier: 1, fixedDiscount: 0, label: 'QR-код: базовая цена' };
|
||||
}
|
||||
|
||||
if (total >= 50000) {
|
||||
return { multiplier: 0.93, label: 'Наличные: цена от 50 000р.' };
|
||||
return { multiplier: 0.93, fixedDiscount: 0, label: 'Наличные: цена от 50 000р.' };
|
||||
}
|
||||
|
||||
if (total >= 20000) {
|
||||
return { multiplier: 0.95, label: 'Наличные: цена от 20 000р.' };
|
||||
return { multiplier: 0.95, fixedDiscount: 0, label: 'Наличные: цена от 20 000р.' };
|
||||
}
|
||||
|
||||
return { multiplier: 1, label: 'Наличные: базовая цена до 20 000р.' };
|
||||
if (total >= 7000) {
|
||||
return { multiplier: 1, fixedDiscount: 300, label: 'Наличные: -300р. от 7000р.' };
|
||||
}
|
||||
|
||||
return { multiplier: 1, fixedDiscount: 0, label: 'Наличные: базовая цена до 7000р.' };
|
||||
};
|
||||
|
||||
const cartCurrentTotal = (items = getCartItems()) => {
|
||||
const mode = priceMode();
|
||||
const subtotal = Math.floor(cartBaseTotal(items) * mode.multiplier);
|
||||
|
||||
return Math.max(0, subtotal - Number(mode.fixedDiscount || 0));
|
||||
};
|
||||
|
||||
const tierValues = (base) => ({
|
||||
@@ -293,7 +306,9 @@ try {
|
||||
if (unitNode || packageNode) {
|
||||
const unitBase = Number(unitNode?.dataset.baseUnitPrice || 0);
|
||||
const packageBase = Number(packageNode?.dataset.basePackagePrice || 0);
|
||||
const base = unitBase > 0 ? unitBase : packageBase;
|
||||
const unitPriceRow = card.querySelector('[data-unit-price-row]');
|
||||
const showUnitPrice = card.dataset.showUnitPrice === '1' && !unitPriceRow?.classList.contains('is-price-placeholder');
|
||||
const base = showUnitPrice && unitBase > 0 ? unitBase : packageBase;
|
||||
|
||||
const tiers = tierValues(base);
|
||||
const tierBase = card.querySelector('[data-tier-base]');
|
||||
@@ -304,7 +319,9 @@ try {
|
||||
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 || 'шт.';
|
||||
if (tierUnitLabel) tierUnitLabel.textContent = showUnitPrice
|
||||
? (card.querySelector('[data-unit-label]')?.textContent || 'кг')
|
||||
: 'фасовку';
|
||||
}
|
||||
|
||||
};
|
||||
@@ -318,6 +335,20 @@ try {
|
||||
});
|
||||
};
|
||||
|
||||
const updateMiniCart = () => {
|
||||
const items = getCartItems();
|
||||
const count = items.reduce((sum, item) => sum + Number(item.quantity || 0), 0);
|
||||
const total = cartCurrentTotal(items);
|
||||
|
||||
document.querySelectorAll('[data-mini-cart-count]').forEach((node) => {
|
||||
node.textContent = String(count);
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-mini-cart-total]').forEach((node) => {
|
||||
node.textContent = formatRub(total);
|
||||
});
|
||||
};
|
||||
|
||||
const itemCurrentPrice = (item) => Math.floor(Number(item.basePackagePrice || 0) * priceMode().multiplier);
|
||||
|
||||
const renderCartPage = () => {
|
||||
@@ -336,7 +367,7 @@ try {
|
||||
const savingNode = cartPage.querySelector('[data-cart-saving-total]');
|
||||
const items = getCartItems();
|
||||
const baseTotal = cartBaseTotal(items);
|
||||
const currentTotal = Math.floor(baseTotal * priceMode().multiplier);
|
||||
const currentTotal = cartCurrentTotal(items);
|
||||
const savingTotal = Math.max(0, baseTotal - currentTotal);
|
||||
|
||||
if (emptyNode) {
|
||||
@@ -397,20 +428,12 @@ try {
|
||||
button.classList.toggle('is-active', button.dataset.paymentMode === payment);
|
||||
});
|
||||
|
||||
const note = document.querySelector('[data-price-mode-note]');
|
||||
if (note) {
|
||||
const total = getCartTotal();
|
||||
const mode = priceMode();
|
||||
const suffix = payment === 'cash' && total < 50000
|
||||
? (total < 20000 ? ' До цены от 20 000р. осталось ' + formatRub(20000 - total) + '.' : ' До цены от 50 000р. осталось ' + formatRub(50000 - total) + '.')
|
||||
: '';
|
||||
note.textContent = mode.label + '. Сумма корзины: ' + formatRub(total) + '.' + suffix;
|
||||
}
|
||||
};
|
||||
|
||||
const updateAllPrices = () => {
|
||||
updateModeButtons();
|
||||
updateCartCount();
|
||||
updateMiniCart();
|
||||
updateDynamicPrices(document);
|
||||
document.querySelectorAll('.product-card.price-aware').forEach(updateCardPrices);
|
||||
renderCartPage();
|
||||
@@ -427,9 +450,46 @@ try {
|
||||
},
|
||||
currentMode: priceMode,
|
||||
cartBaseTotal,
|
||||
cartCurrentTotal,
|
||||
update: updateAllPrices
|
||||
};
|
||||
|
||||
const catalogScrollKey = 'rybstock.catalogScrollY';
|
||||
const catalogMenuScrollKey = 'rybstock.catalogMenuScrollY';
|
||||
|
||||
if (window.location.pathname.startsWith('/catalog')) {
|
||||
const savedCatalogScroll = sessionStorage.getItem(catalogScrollKey);
|
||||
const savedCatalogMenuScroll = sessionStorage.getItem(catalogMenuScrollKey);
|
||||
const catalogMenu = document.querySelector('.catalog-menu-panel > .category-list');
|
||||
|
||||
if (savedCatalogScroll !== null) {
|
||||
sessionStorage.removeItem(catalogScrollKey);
|
||||
window.requestAnimationFrame(() => {
|
||||
window.scrollTo({
|
||||
top: Math.max(0, parseInt(savedCatalogScroll, 10) || 0),
|
||||
left: 0,
|
||||
behavior: 'auto'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (savedCatalogMenuScroll !== null && catalogMenu) {
|
||||
sessionStorage.removeItem(catalogMenuScrollKey);
|
||||
catalogMenu.scrollTop = Math.max(0, parseInt(savedCatalogMenuScroll, 10) || 0);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const categoryLink = event.target.closest('.catalog-menu-panel .category-list a[href^="/catalog/"]');
|
||||
|
||||
if (!categoryLink || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
sessionStorage.setItem(catalogScrollKey, String(window.scrollY));
|
||||
sessionStorage.setItem(catalogMenuScrollKey, String(categoryLink.closest('.catalog-menu-panel > .category-list')?.scrollTop || 0));
|
||||
});
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const modeButton = event.target.closest('[data-payment-mode]');
|
||||
|
||||
@@ -594,6 +654,26 @@ try {
|
||||
const unitLabelNoteNode = card.querySelector('[data-unit-label-note]');
|
||||
const oldPriceNode = card.querySelector('[data-old-package-price-display]');
|
||||
const oldUnitPriceNode = card.querySelector('[data-old-unit-price-display]');
|
||||
const unitPriceRow = card.querySelector('[data-unit-price-row]');
|
||||
const packageTierTrigger = card.querySelector('[data-package-tier-trigger]');
|
||||
const packagePriceNote = card.querySelector('[data-package-price-note]');
|
||||
const showUnitPrice = button.dataset.showUnitPrice === '1';
|
||||
|
||||
card.dataset.showUnitPrice = showUnitPrice ? '1' : '0';
|
||||
|
||||
if (unitPriceRow) {
|
||||
unitPriceRow.classList.toggle('is-price-placeholder', !showUnitPrice);
|
||||
unitPriceRow.setAttribute('aria-hidden', showUnitPrice ? 'false' : 'true');
|
||||
}
|
||||
|
||||
if (packageTierTrigger) {
|
||||
packageTierTrigger.hidden = showUnitPrice;
|
||||
}
|
||||
|
||||
if (packagePriceNote) {
|
||||
packagePriceNote.classList.toggle('is-price-placeholder', !showUnitPrice);
|
||||
packagePriceNote.setAttribute('aria-hidden', showUnitPrice ? 'false' : 'true');
|
||||
}
|
||||
|
||||
if (unitNode) {
|
||||
unitNode.textContent = button.dataset.unit || 'ед.';
|
||||
|
||||
Reference in New Issue
Block a user