added checkbox Hide NC price (Purchase price)

This commit is contained in:
Mihael Magdić
2026-07-30 16:20:29 +02:00
parent b77d26da0f
commit 5d63d7d78d

View File

@@ -2,6 +2,15 @@
* Price Display Toggle Template * Price Display Toggle Template
* Module: B2bpayments * Module: B2bpayments
*} *}
{if $is_admin == '1'}
<div class="nc-display-switcher">
<label class="form-check-label">
<input type="checkbox" id="ncDisplayToggle" />
{l s='Isključi NC' d='Modules.B2bpayments.ShopBreadcrumb'}
</label>
</div>
{/if}
<div class="price-display-switcher"> <div class="price-display-switcher">
<div id="price-display-switcher" class="payments-selection"> <div id="price-display-switcher" class="payments-selection">
<select id="priceDisplayToggle" name="price_display_preference" class="custom-select"> <select id="priceDisplayToggle" name="price_display_preference" class="custom-select">
@@ -135,4 +144,77 @@
}, 100); }, 100);
}); });
</script> </script>
<script>
// --- NC handling ---
(function() {
const STORAGE_KEY = 'ncHidePreference'; // Pohranjujemo je li NC skriven
/**
* Primjenjuje vidljivost NC elemenata.
* @param {boolean} hideNc - Ako je true, sakrij NC. Ako je false, prikaži NC.
*/
function applyNcVisibility(hideNc) {
const ncElements = document.querySelectorAll('.ncrender');
ncElements.forEach(el => {
el.style.display = hideNc ? 'none' : '';
});
}
function saveNcPreference(hideNc) {
try {
localStorage.setItem(STORAGE_KEY, hideNc ? 'true' : 'false');
} catch (e) {
console.error('NC Toggle: LocalStorage greška', e);
}
}
function loadNcPreference() {
try {
// DEFAULT: Vraćamo false (nije skriveno -> prikazano je)
const saved = localStorage.getItem(STORAGE_KEY);
return saved === 'true';
} catch (e) {
return false;
}
}
function refreshNcState() {
const isHidden = loadNcPreference();
applyNcVisibility(isHidden);
}
document.addEventListener('DOMContentLoaded', () => {
const ncCheckbox = document.getElementById('ncDisplayToggle');
const isHidden = loadNcPreference();
// 1. Postavi stanje checkboxa (označen ako je skriveno) i primijeni vidljivost
if (ncCheckbox) {
ncCheckbox.checked = isHidden;
ncCheckbox.addEventListener('change', (e) => {
const hideNc = e.target.checked;
saveNcPreference(hideNc);
applyNcVisibility(hideNc);
});
}
// Primijeni na početnom učitavanju
applyNcVisibility(isHidden);
// 2. PrestaShop AJAX listeneri
let attempts = 0;
const psCheck = setInterval(() => {
if (typeof prestashop !== 'undefined' && prestashop.on) {
clearInterval(psCheck);
prestashop.on('updatedProduct', () => setTimeout(refreshNcState, 50));
prestashop.on('updateProductList', () => setTimeout(refreshNcState, 50));
} else if (attempts > 50) {
clearInterval(psCheck);
}
attempts++;
}, 100);
});
})();
</script>
{/literal} {/literal}