var Webflow = Webflow || []; Webflow.push(function () { var TAB_ID_FOUNDERS = 0; var TAB_ID_ELITE = 1; var TAB_ID_CARBON = 2; // var PROD_TITLES = ['Founders Series', 'Carbon Elite', 'Carbon Series']; var PRODUCTS_URLS = { 0b0000: 'https://getcarbon.myshopify.com/cart/33684157038636:1', 0b0001: 'https://getcarbon.myshopify.com/cart/33684157038636:1,33684498841644:1', 0b0010: 'https://getcarbon.myshopify.com/cart/33684157038636:1,33684542947372:1', 0b0011: 'https://getcarbon.myshopify.com/cart/33684157038636:1,33684498841644:1,33684542947372:1', // Carbon Elite 0b0100: 'https://getcarbon.myshopify.com/cart/33684174667820:1', 0b0101: 'https://getcarbon.myshopify.com/cart/33684579221548:1', 0b0110: 'https://getcarbon.myshopify.com/cart/33684574568492:1', 0b0111: 'https://getcarbon.myshopify.com/cart/33684563197996:1', // Carbon Series 0b1000: 'https://getcarbon.myshopify.com/cart/33684582727724:1', 0b1001: 'https://getcarbon.myshopify.com/cart/33684611989548:1', 0b1010: 'https://getcarbon.myshopify.com/cart/33684609826860:1', 0b1011: 'https://getcarbon.myshopify.com/cart/33684599275564:1', }; // Carbon Founder's Edition // - Carbon Founders edition 5049101942828 // https://getcarbon.myshopify.com/cart/33684157038636:1 // - 10 pack sensors 5049244713004 // https://getcarbon.myshopify.com/cart/33684498841644:1 // - Milled aluminum stand 5049269977132 // https://getcarbon.myshopify.com/cart/33684542947372:1 // Carbon Elite // - Carbon Elite Deposit 5049108856876 // https://getcarbon.myshopify.com/cart/33684174667820:1 // - Carbon Elite Deposit +10 pack sensors 5049285443628 // https://getcarbon.myshopify.com/cart/33684579221548:1 // - Carbon Elite Deposit +Aluminum Stand 5049283674156 // https://getcarbon.myshopify.com/cart/33684574568492:1 // - Carbon Elite Deposit +10 pack sensors +Aluminum Stand 5049279741996 // https://getcarbon.myshopify.com/cart/33684563197996:1 // Carbon Series // - Carbon Base Series Deposit 5049287802924 // https://getcarbon.myshopify.com/cart/33684582727724:1 // - Carbon Base Series Deposit +10 pack sensors 5049299042348 // https://getcarbon.myshopify.com/cart/33684611989548:1 // - Carbon Base Series Deposit +Aluminum Stand 5049297469484 // https://getcarbon.myshopify.com/cart/33684609826860:1 // - Carbon Base Series Deposit +10 pack sensors +Aluminum Stand 5049294028844 // https://getcarbon.myshopify.com/cart/33684599275564:1 var PREODER_END_DATE = new Date('05/01/2020'); var PRODUCT_PRICE_BASE = 1890; var PRICE_10_PACK = 100; var PRICE_ALU_STAND = 250; var SERIES_INFO_DATA = [ { shippingDate: 'Shipping September 2020', basePrice: PRODUCT_PRICE_BASE, payNow: 0 }, { shippingDate: 'Shipping December 2020', basePrice: PRODUCT_PRICE_BASE, payNow: 500 }, { shippingDate: 'Shipping January 2021', basePrice: PRODUCT_PRICE_BASE, payNow: 250 }, ]; initCountdown(); initForm(); // ***************************************** Events setup ************************************************ var checkBoxes; var tabButtons; var currentTab; var billBlock, personalInfoBlock; var errorMessage; function initForm() { billBlock = $('.preorder-block----bill'); personalInfoBlock = $('.personal-info-form-block'); checkBoxes = billBlock.find('.checkbox-field input[type="checkbox"]'); checkBoxes.on('change', function () { var cb = $(this); console.log(cb.attr('id'), ' : ', cb[0].checked); updateTotal(); }); tabButtons = $('.tabs-menu > *'); tabButtons.on('mouseup', function (e) { var id = parseInt($(this).attr('id').split('-').pop(), 10); console.log('Tab ID: ', id); currentTab = id; updateTotal(); }); errorMessage = $('.error-message'); $('.button-grey').on('click', onFormSubmit); // set init state currentTab = TAB_ID_FOUNDERS; updateTotal(); } function onFormSubmit() { var errors = validateForm(); // console.log(errors); personalInfoBlock.find('.has-error').removeClass('has-error'); errorMessage.hide(); var errNum = 0; for (var key in errors) { if (errors.hasOwnProperty(key)) { personalInfoBlock.find('#' + key).addClass('has-error'); errorMessage.text(errors[key]); errorMessage.show(); errNum++; break; } } if (errNum == 0) { $('.button-grey').addClass('disabled').off(); $('.button-grey .button-red-label').text('please wait ...'); personalInfoBlock.css('pointerEvents', 'none'); sendData(); } } function sendData() { var data = { 'checkout[email]': personalInfoBlock.find('#email').val(), 'checkout[billing_address][first_name]': personalInfoBlock.find('#fname').val(), 'checkout[billing_address][last_name]': personalInfoBlock.find('#lname').val(), // 'carbonId': personalInfoBlock.find('#carbonId').val(), 'checkout[billing_address][phone]': personalInfoBlock.find('#phone').val(), }; var dataOut = []; for (var key in data) { if (data.hasOwnProperty(key)) { // dataOut.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key])); dataOut.push(key + '=' + encodeURIComponent(data[key])); } } var productUrl = getProductUrl(); var url = productUrl + '?' + dataOut.join('&'); console.log(url); // window.location = url; } function getProductUrl() { var is10Pack = billBlock.find('#option10Pack')[0].checked << 0; var isAluStand = billBlock.find('#optionAluStand')[0].checked << 1; var isProd = currentTab << 2; var num = isProd | is10Pack | isAluStand; // console.log('is10Pack: ', is10Pack, ' | ', 'isAluStand: ', isAluStand); // console.log('num: ' + num); console.log('RES: ' + PRODUCTS_URLS[num]); return PRODUCTS_URLS[num]; } function validateForm() { var constraints = { fname: { presence: true, format: { pattern: "[^.,\/#!$%\^&\*;:{}=`~()_]+", flags: "i", message: "^First Name must be a valid name" } }, lname: { presence: true, format: { pattern: "[^.,\/#!$%\^&\*;:{}=`~()_]+", flags: "i", message: "^Last Name must be a valid name" } }, carbonId: { format: { pattern: "[a-z0-9]+", flags: "i", message: "^Can only contain a-z and 0-9" } }, phone: { format: { pattern: "[0-9\- \(\)]+", flags: "i", message: "^Can only contain numbers, spaces, dashes and brackets" } }, email: { email: { message: "^Doesn't look like a valid email" } } }; return validate({ fname: personalInfoBlock.find('#fname').val(), lname: personalInfoBlock.find('#lname').val(), email: personalInfoBlock.find('#email').val(), // carbonId: personalInfoBlock.find('#carbonId').val(), phone: personalInfoBlock.find('#phone').val(), }, constraints); } function updateTotal() { var seriesInfo = SERIES_INFO_DATA[currentTab]; var price = seriesInfo.basePrice; if (billBlock.find('#option10Pack')[0].checked) price += PRICE_10_PACK; if (billBlock.find('#optionAluStand')[0].checked) price += PRICE_ALU_STAND; billBlock.find('#txtShippingDate').text(seriesInfo.shippingDate); billBlock.find('#txtProductPrice').text('$ ' + seriesInfo.basePrice); billBlock.find('#txtValueTotal').text('$ ' + price); billBlock.find('#txtValueDue').text('$ ' + (seriesInfo.payNow || price)); } function initCountdown() { var txtEndsDate = $('#txtEndsDate'); var timerId = countdown(PREODER_END_DATE, function (ts) { txtEndsDate.html(ts.toHTML()); }, countdown.DAYS | countdown.HOURS | countdown.MINUTES ); } });