Shopping cart

Your shopping cart is empty.

€{{amount_with_comma_separator}}'; MyCustomizerCart.getMoneyFormat = () => { return MyCustomizerCart.shopMoneyFormat.match(MyCustomizerCart.moneyFormatRegex)[0]; }; MyCustomizerCart.moneyFormat = MyCustomizerCart.getMoneyFormat(); MyCustomizerCart.formatMoney = (cents, formatString) => { if (typeof cents == 'string') { cents = cents.replace('.', ''); } let value = ''; const placeholderRegex = /\{\{\s*(\w+)\s*\}\}/; function defaultOption(opt, def) { return typeof opt == 'undefined' ? def : opt; } function formatWithDelimiters(number, precision, thousands, decimal) { precision = defaultOption(precision, 2); thousands = defaultOption(thousands, ','); decimal = defaultOption(decimal, '.'); if (isNaN(number) || number == null) { return 0; } number = (number / 100.0).toFixed(precision); const parts = number.split('.'), dollars = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + thousands), cents = parts[1] ? decimal + parts[1] : ''; return dollars + cents; } switch (formatString.match(placeholderRegex)[1]) { case 'amount': value = formatWithDelimiters(cents, 2); break; case 'amount_no_decimals': value = formatWithDelimiters(cents, 0); break; case 'amount_with_comma_separator': value = formatWithDelimiters(cents, 2, '.', ','); break; case 'amount_no_decimals_with_comma_separator': value = formatWithDelimiters(cents, 0, '.', ','); break; } return formatString.replace(placeholderRegex, value); }; /** Utils **/ MyCustomizerCart.isMczrCartItem = cartItem => cartItem.properties && cartItem.properties['_mczr_designId'] != null; /** Requests */ MyCustomizerCart.cartChangeURLRegex = /\/cart\/(change|add|update|clear|)\.js/; MyCustomizerCart.cartURLRegex = /\/cart.js/; MyCustomizerCart.initializeFetchRequestsInterceptors = () => { function readResponse(response) { if (response.url.match(MyCustomizerCart.cartChangeURLRegex) != null || response.url.match(MyCustomizerCart.cartURLRegex) != null) { response.clone().json().then(body => { MyCustomizerCart.cart = body; }); } return response; } const fetch = window.fetch; window.fetchWithoutIntercept = fetch; window.fetch = function async() { if (typeof arguments[0] === 'string' && arguments[0].includes('/products/null.js')) { return fetch.apply(this, [`/products/${MyCustomizerCart.getProductHandle()}.js`, arguments[1]]); } return fetch.apply(this, arguments).then(readResponse); }; }; MyCustomizerCart.initializeXHRRequestsInterceptors = () => { const open = window.XMLHttpRequest.prototype.open; function openReplacement() { this.addEventListener('load', function () { if (this._url.match(MyCustomizerCart.cartURLRegex) != null) { MyCustomizerCart.cart = JSON.parse(this.response); } }); if (typeof arguments[1] === 'string' && arguments[1].includes('/products/null.js')) { return open.apply(this, [arguments[0], `/products/${MyCustomizerCart.getProductHandle()}.js`, arguments[2]]); } return open.apply(this, arguments); } window.XMLHttpRequest.prototype.open = openReplacement; }; MyCustomizerCart.initializeRequestsInterceptors = () => { MyCustomizerCart.initializeXHRRequestsInterceptors(); MyCustomizerCart.initializeFetchRequestsInterceptors(); }; /** DOM */ MyCustomizerCart.getProductHandle = () => { return MyCustomizerCart.cart.items.find(cartItem => cartItem.id === MyCustomizerCart.currentFocusItemId).properties._mczr_productHandle; }; MyCustomizerCart.updateCartRequest = () => { fetch('/cart.js', { method: 'GET', headers: { 'Content-Type': 'application/json' } }); }; const zeroDollarRegex = /^[$€£¥₩₹₽]0[.,]00$/; MyCustomizerCart.findZeroPricing = el => { var walkthroughNode; const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false); while (walkthroughNode = walk.nextNode()) { var nodeValue = walkthroughNode.nodeValue; if (walkthroughNode.length > 1 && /\S/.test(nodeValue)) { const content = nodeValue.trim().replace(' ', ''); if (content.match(zeroDollarRegex)) { walkthroughNode.textContent = ''; } } } }; MyCustomizerCart.ITEM = 'item'; MyCustomizerCart.CART_TOTAL_PRICE_SELECTOR = 'cart_total_price'; MyCustomizerCart.CART_ITEMS_SUBTOTAL_PRICE_SELECTOR = 'cart_items_subtotal_price'; MyCustomizerCart.ITEM_FINAL_LINE_PRICE_SELECTOR = 'item_final_line_price'; MyCustomizerCart.ITEM_FINAL_PRICE_SELECTOR = 'item_final_price'; MyCustomizerCart.ITEM_ORIGINAL_LINE_PRICE_SELECTOR = 'item_original_line_price'; MyCustomizerCart.ITEM_ORIGINAL_PRICE_SELECTOR = 'item_original_price'; MyCustomizerCart.ITEM_PRODUCT_TILE = 'item_product_title'; MyCustomizerCart.ITEM_VARIANT_TITLE = 'item_variant_title'; MyCustomizerCart.ITEM_IMAGE = 'item_image'; MyCustomizerCart.getItemSelector = (cartItem, selector) => `${selector}-${cartItem.properties._mczr_designId}`; const selectors = {}; const saveSelector = (key, selector) => selectors[key] = selector; const getSelector = key => selectors[key]; MyCustomizerCart.previousCart; MyCustomizerCart.replaceContentForAllElements = (elements, originalContent, content) => { elements.forEach(element => { const child = element.firstChild; if (child.nodeType == 3) { child.replaceWith(child.data.replace(originalContent, content)); } const descendants = Array.from(element.getElementsByTagName('*')); descendants.forEach(descendant => { const child = descendant.firstChild; if (child.nodeType == 3) { child.replaceWith(child.data.replace(originalContent, content)); } }); }); }; MyCustomizerCart.setContentForAllElements = (elements, content) => { elements.forEach(element => { if (element.childElementCount === 0) { element.innerHTML = content; return; } let child = element.firstChild; while (child) { if (child.nodeType == 3 && child.data.replace(/\s/g, '') != '') { child.replaceWith(content); } child = child.nextSibling; } }); }; MyCustomizerCart.currentFocusItemId = null; MyCustomizerCart.invalidState = false; MyCustomizerCart.updateDOMFallback = hasPriceDiscrepancy => { if (MyCustomizerCart.invalidState) { if (hasPriceDiscrepancy) { MyCustomizerCart.findZeroPricing(document.querySelector('.cart')); window.clearTimeout(MyCustomizerCart.updateCartRequest); window.setTimeout(MyCustomizerCart.updateCartRequest, 3000); } else { location.reload(); } } }; MyCustomizerCart.updateDOM = () => { if (MyCustomizerCart.cart === MyCustomizerCart.previousCart) return requestAnimationFrame(MyCustomizerCart.updateDOM); let priceDifference = 0; MyCustomizerCart.priceDiscrepancy = false; MyCustomizerCart.cart.items.forEach((cartItem, i) => { if (!MyCustomizerCart.isMczrCartItem(cartItem)) return; let itemElement = document.querySelector(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM)}"]`); if (itemElement) { saveSelector('itemElement', `.${itemElement.className.split(' ').join('.')}`); } else { itemElement = document.querySelector(`${getSelector('itemElement')}:nth-of-type(${i + 1})`); } const itemImageElement = document.querySelector(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_IMAGE)}"]`) || (itemElement ? itemElement.querySelector(`${getSelector('itemImageElement')}`) : null); if (itemImageElement) { itemImageElement.src = cartItem.properties._mczr_image; saveSelector('itemImageElement', `.${itemImageElement.className.split(' ').join('.')}`); } const variantTitleElement = document.querySelector(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_VARIANT_TITLE)}"]`); if (variantTitleElement) variantTitleElement.style.display = 'none'; if (cartItem.price === 0 && +cartItem.properties['_mczr_variantPrice'] != 0) { MyCustomizerCart.priceDiscrepancy = true; if (MyCustomizerCart.debugMode === true) alert('MyCustomizerCart: found 0$ variant'); if (itemElement) { itemElement.addEventListener('focusin', () => { currentFocusDesignId = cartItem.properties._mczr_designId; }); itemElement.addEventListener('focusout', () => { if (currentFocusDesignId === cartItem.properties._mczr_designId) currentFocusDesignId = null; }); } MyCustomizerCart.setContentForAllElements(document.querySelectorAll(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_PRODUCT_TILE)}"]`), cartItem.properties._mczr_productTitle); const discount = cartItem.final_price; const price = +cartItem.properties['_mczr_variantPrice'].replace('.', ''); const priceWithDiscount = price + discount; const totalPrice = price * cartItem.quantity; const totalPriceWithDiscounts = priceWithDiscount * cartItem.quantity; // discounts are already applied to the total cart price priceDifference = priceDifference + totalPrice; const allFinalPriceElements = document.querySelectorAll(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_FINAL_PRICE_SELECTOR)}"]`); if (allFinalPriceElements.length === 0) { MyCustomizerCart.invalidState = true; } MyCustomizerCart.replaceContentForAllElements(allFinalPriceElements, MyCustomizerCart.formatMoney(cartItem.final_price, MyCustomizerCart.moneyFormat), MyCustomizerCart.formatMoney(priceWithDiscount, MyCustomizerCart.moneyFormat)); MyCustomizerCart.replaceContentForAllElements(document.querySelectorAll(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_FINAL_LINE_PRICE_SELECTOR)}"]`), MyCustomizerCart.formatMoney(cartItem.final_line_price, MyCustomizerCart.moneyFormat), MyCustomizerCart.formatMoney(totalPriceWithDiscounts, MyCustomizerCart.moneyFormat)); MyCustomizerCart.replaceContentForAllElements(document.querySelectorAll(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_ORIGINAL_LINE_PRICE_SELECTOR)}"]`), MyCustomizerCart.formatMoney(cartItem.original_line_price, MyCustomizerCart.moneyFormat), MyCustomizerCart.formatMoney(totalPrice, MyCustomizerCart.moneyFormat)); MyCustomizerCart.replaceContentForAllElements(document.querySelectorAll(`[data-mczr="${MyCustomizerCart.getItemSelector(cartItem, MyCustomizerCart.ITEM_ORIGINAL_PRICE_SELECTOR)}"]`), MyCustomizerCart.formatMoney(cartItem.original_price, MyCustomizerCart.moneyFormat), MyCustomizerCart.formatMoney(price, MyCustomizerCart.moneyFormat)); } MyCustomizerCart.replaceContentForAllElements(document.querySelectorAll(`[data-mczr="${MyCustomizerCart.CART_TOTAL_PRICE_SELECTOR}"]`), MyCustomizerCart.formatMoney(MyCustomizerCart.cart.total_price, MyCustomizerCart.moneyFormat), MyCustomizerCart.formatMoney(priceDifference + MyCustomizerCart.cart.total_price, MyCustomizerCart.moneyFormat)); }); MyCustomizerCart.updateDOMFallback(MyCustomizerCart.priceDiscrepancy); MyCustomizerCart.previousCart = MyCustomizerCart.cart; requestAnimationFrame(MyCustomizerCart.updateDOM); }; /** Initialize */ MyCustomizerCart.updateDOM(); MyCustomizerCart.initializeRequestsInterceptors();