(function () { try { var nativeFetch = window.fetch; var isUpdatingCart = false; window.fetch = function (...args) { try { if (typeof args[0] === 'string' && (args[0].includes("/cart/change") || args[0].includes("/cart.js")|| args[0].includes("/cart/add") || args[0].includes("/cart/update"))) { if (!isUpdatingCart) { isUpdatingCart = true; setTimeout(async function () { await setDateTimeInCart(); isUpdatingCart = false; }, 1000); } } } catch (err) { // console.error("Error in intercepting fetch:", err); } return nativeFetch.apply(window, args); } } catch (e) { // console.error("Error in overriding fetch:", e); } async function setDateTimeInCart() { try { const response = await fetch('/cart/update.js', { method: "POST", headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/json' }, body: JSON.stringify({ attributes: { Discountly_dateTime:`${globalFields.Storetime()},${Shopify.shop}`, discountPosId:`online` } }) }); if (!response.ok) { throw new Error(`Error: ${response.statusText}`); } const data = await response.json(); displayTiers.DisplayTiersFn() setTimeout(async function () { displayTiers.DisplayTiersFn() }, 1200); // console.log('Cart updated successfully:', data); } catch (error) { // console.error('Failed to update cart:', error); } } // Add event listener for page load to update the cart attribute window.addEventListener('load', async () => { await setDateTimeInCart(); }); })(); (function() { let originalOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url, async, user, password) { if (url.includes("change") || url.includes("/cart/add")) { setTimeout(displayTiers.DisplayTiersFn, 2500); setTimeout(displayTiers.DisplayTiersFn, 3500); setTimeout(displayTiers.DisplayTiersFn, 4500); } return originalOpen.apply(this, arguments); }; })();