Menu
Your Cart

Δωρεάν μεταφορικά για την Ηπειρωτική Ελλάδα σε παραγγελίες προϊόντων PAKOWORLD αξίας άνω των 169€

Φωτιστικά

/* ------------------------------------------------------------------ Multiple-of-minimum quantity "jump" (front-end UX only). The backend OCMOD still enforces multiples server-side, so this is purely cosmetic: it makes the product-page quantity field snap to valid multiples and makes +/- buttons jump by the minimum. Works on the PRODUCT PAGE, where OpenCart pre-fills the quantity input with the product's minimum (so we can read the step reliably, independent of the theme/version). Cart-page quantities are handled server-side by the backend OCMOD. ------------------------------------------------------------------ */ (function () { function getStep(input) { return parseInt(input.getAttribute('data-mmq-step') || '0', 10); } function snapUp(input) { var step = getStep(input); if (step < 2) return; var v = parseInt(input.value, 10); if (isNaN(v) || v < step) { v = step; } else if (v % step !== 0) { v = Math.ceil(v / step) * step; } input.value = v; } function init(input) { if (input.getAttribute('data-mmq-init')) return; input.setAttribute('data-mmq-init', '1'); // OpenCart pre-fills the product-page quantity with the minimum. var step = parseInt(input.value, 10); if (isNaN(step) || step < 2) return; // minimum 1 -> nothing to do input.setAttribute('data-mmq-step', step); input.setAttribute('min', step); input.setAttribute('step', step); input.addEventListener('blur', function () { snapUp(input); }); input.addEventListener('change', function () { snapUp(input); }); } function scan() { // Exact name="quantity" = product page only (cart uses quantity[cart_id]). var list = document.querySelectorAll('input[name="quantity"]'); for (var i = 0; i < list.length; i++) init(list[i]); } // +/- buttons: detect whether the value went up or down after any click, // then snap to the next / previous valid multiple. Selector-independent. document.addEventListener('click', function () { var list = document.querySelectorAll('input[data-mmq-step]'); for (var i = 0; i < list.length; i++) { (function (input) { var step = getStep(input); var before = parseInt(input.value, 10); setTimeout(function () { var after = parseInt(input.value, 10); if (isNaN(after) || after === before) return; if (after > before) { var up = Math.ceil(after / step) * step; if (up <= before) up = before + step; input.value = up; } else { var dn = Math.floor(after / step) * step; if (dn < step) dn = step; input.value = dn; } }, 0); })(list[i]); } }, true); // Final safety: snap right before add-to-cart. document.addEventListener('click', function (e) { var node = e.target; while (node && node !== document) { if (node.id && node.id.indexOf('button-cart') === 0) { var list = document.querySelectorAll('input[data-mmq-step]'); for (var i = 0; i < list.length; i++) snapUp(list[i]); break; } node = node.parentNode; } }, true); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', scan); } else { scan(); } // Journal sometimes swaps product content via AJAX; re-scan on DOM changes. if (window.MutationObserver) { new MutationObserver(scan).observe(document.documentElement, { childList: true, subtree: true }); } })();