превью относительно готово
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user