var product_images_swiper; $( document ).ready(function() { // Navigation open/close $('.nav-button').on('click', function () { if ($('.animated-icon').hasClass('open')) { $('.animated-icon').removeClass('open'); $('nav').animate({opacity: 0}, 300); setTimeout(function(){ $('nav').removeClass('display'); }, 300); } else { $('.animated-icon').addClass('open'); $('nav').addClass('display'); $('nav').animate({opacity: 1}, 300); } }); // Initialise the carousels var home_swiper_desktop; if (home_swiper_desktop != undefined) { home_swiper_desktop.destroy(); } home_swiper_desktop = new Swiper('#home-swiper-desktop', { autoplay: { delay: 5000, }, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true }); var home_swiper_mobile; if (home_swiper_mobile != undefined) { home_swiper_mobile.destroy(); } home_swiper_mobile = new Swiper('#home-swiper-mobile', { autoplay: { delay: 5000, }, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true }); // var product_images_swiper; if (product_images_swiper != undefined) { product_images_swiper.destroy(); } product_images_swiper = new Swiper('#product-images-swiper', { autoplay: false, effect: 'slide', loop: true, noSwiping: false, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true, watchOverflow: true }); var checkout_swiper; if (checkout_swiper != undefined) { checkout_swiper.destroy(); } checkout_swiper = new Swiper('#checkout-swiper', { autoplay: false, effect: 'slide', loop: false, noSwiping: true, noSwipingClass: 'no-swiping', // navigation: { // nextEl: '.swiper-button-next', // prevEl: '.swiper-button-prev', // }, pagination: { el: '.swiper-pagination', }, observer: true, observeParents: true, watchOverflow: true, preventClicks: false, preventClicksPropagation: false }); // Set click actions $('.qty-minus').unbind('click'); $('.qty-plus').unbind('click'); $('.qty-minus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) > 1) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) - 1); } }); $('.qty-plus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) < $('#num-in-stock').val()) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) + 1); } }); $(".go-to-checkout-1").click(function() { calculateBagTotals(); setTimeout(function(){ window.location.href='checkout.php'; }, 2000); }); $(".go-to-checkout-2").click(function() { checkout_swiper.slideTo(1); }); $(".go-to-checkout-3").click(function() { if ($('#ShoppingBagString').val().indexOf('|') > 0) { checkout_swiper.slideTo(2); sendOrder(); } else { alert('Your shopping bag is empty.'); } }); // Set enter press actions $("#DiscountAmount").on('keyup', function (e) { if (e.keyCode === 13) { $("#DiscountAmountButton").click(); } }); $("#DiscountPercentage").on('keyup', function (e) { if (e.keyCode === 13) { $("#DiscountPercentageButton").click(); } }); // Set correct product attributes as name $('.attribute.active').click(); // Initialise bag totals calculateBagTotals(); }); function formatPrice(price) { price = String(price).replace(',',''); if (price >= 0) { is_negative = ''; price = parseFloat(price); } else { is_negative = '-'; price = parseFloat(price*-1); } return is_negative + document.getElementById('DefaultCurrencySymbol').value + price.toFixed(2).replace(/./g, function(c, i, a) { return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c; }); } function changeTab(evt, tabs, tabid) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName(tabs + " tabcontent"); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tablinks = document.getElementsByClassName(tabs + " tablinks"); for (i = 0; i < tablinks.length; i++) { tablinks[i].className = tablinks[i].className.replace(" active", ""); } document.getElementById(tabid).style.display = "block"; evt.currentTarget.className += " active"; } var attributes_string = ''; function updateSelectedOption(product_id, attribute_type, attribute) { $('.attribute' + '.' + attribute_type).removeClass('active'); $('.attribute' + '.' + attribute_type + '.' + attribute).addClass('active'); // Find all selected attributes attributes_string = ''; $(".attribute-type").each(function(){ attribute_type = $(this).attr('data-value'); attributes_string = attributes_string + '"'+attribute_type+'":'; // Loop through all attributes and find what is selected $(".attribute-type-"+$(this).attr('data-value')+".active").each(function(){ attribute = $(this).attr('data-value'); attributes_string = attributes_string + '"'+attribute+'",'; if (attribute_type == 'colour') { select_image_attribute = attribute; } }); }); // Find matching data in product options json $.each(JSON.parse(eval('product_options_'+product_id)), function(key, value) { if (JSON.stringify(value).search(attributes_string) > 0) { $('#product_form_'+product_id+'_ProductOptionID').val(value.product_option_id); if (value.sale_price > ' ') { $('#product_form_'+product_id+'_Price').val(value.sale_price); $('#Price'+product_id).html('' + formatPrice(value.price) + ' ' + formatPrice(value.sale_price) + ''+' (excl. VAT)'); } else { $('#product_form_'+product_id+'_Price').val(value.price); $('#Price'+product_id).html(formatPrice(value.price)+' (excl. VAT)'); } if (parseFloat(value.tot_in_stock) > 0) { $('#add-to-bag').removeAttr('disabled'); $('#add-to-bag').html('ADD TO BAG'); $('#availability').html('In Stock'); $('#num-in-stock').val(value.tot_in_stock); $('.qty-display').html('1'); } else { $('#add-to-bag').attr('disabled', 'disabled'); $('#add-to-bag').html('OUT OF STOCK'); $('#availability').html('Out of Stock'); $('#num-in-stock').val(0); } if (parseFloat($('.qty-display').html()) > $('#num-in-stock').val()) { $('.qty-display').html($('#num-in-stock').val()); } } }); $('.qty-plus').unbind('click'); $('.qty-plus').click(function() { if (parseInt($(this).parent().find('.qty-display').html()) < $('#num-in-stock').val()) { $(this).parent().find('.qty-display').html(parseInt($(this).parent().find('.qty-display').html()) + 1); } }); // Select approprate image var x = 1; $("#product-images-swiper .swiper-slide").each(function(){ if (!$(this).hasClass('swiper-slide-duplicate')) { if ($(this).hasClass(select_image_attribute)) { product_images_swiper.slideTo(x); $('#product_form_'+product_id+'_ProductImageName').val($(this).find('img').attr('src')); return false; } x = x + 1; } }); } function addToBag(productOptionId, secondaryGroupName, productOptionName, productImageName, quantity, price) { shoppingBagLineRef = createShoppingBagLineRef(); attributes_json = JSON.parse('{'+attributes_string+' "none": "none"}'); for (attribute in attributes_json) { if (attribute != 'none') { productOptionName = productOptionName + ' / ' + attributes_json[attribute]; } } $("#shopping-bag-no-items").fadeOut(10); $('#shopping-bag-list').fadeIn(); $(".shopping-bag-link").click(); $("#shopping-bag-list").append('\ '); $('.shopping-bag-list-row:last').fadeIn(1500); calculateBagTotals('addToBag'); } function removeFromBag(shoppingBagLineRef) { $('#shopping-bag-select-method').fadeOut(); $('#shopping-bag-bottom').fadeIn(function(){ if (countShoppingBagRows() == 1) { $('#shopping-bag-bottom').fadeOut(); } $('#row-'+shoppingBagLineRef).animate({ height: 0, opacity: 0 }, function(){ $('#row-'+shoppingBagLineRef).remove(); calculateBagTotals('removeFromBag'); }); }); } var total_quantity = 0; var total_subprice = 0; var total_discount = 0; var total_shipping = 0; var total_tax = 0; var total_price = 0; var shipping_id = ''; var shopping_bag_string = ''; var discount_codes = ['','156713f6f57c38a7492899f9e5132aef|1|15.00','156713f6f57c38a7492899f9e5132aef|1|15.00','156713f6f57c38a7492899f9e5132aef|1|10.00','1f9dc8dc4a31d123e3e3e974cedced71|1|15.00','1f9dc8dc4a31d123e3e3e974cedced71|1|15.00','1f9dc8dc4a31d123e3e3e974cedced71|1|10.00','85ea40602ba28df420f7fba9d3d00e72|1|15.00','85ea40602ba28df420f7fba9d3d00e72|1|15.00','85ea40602ba28df420f7fba9d3d00e72|1|10.00','da4b2d948d34fb55a9ea5622c306bfad|1|15.00','da4b2d948d34fb55a9ea5622c306bfad|1|15.00','da4b2d948d34fb55a9ea5622c306bfad|1|10.00','e769ae9749a0077873f72febc3168c62|1|15.00','e769ae9749a0077873f72febc3168c62|1|15.00','e769ae9749a0077873f72febc3168c62|1|10.00','165bd2d812ac7a8406e3247205b14745|1|15.00','165bd2d812ac7a8406e3247205b14745|1|15.00','165bd2d812ac7a8406e3247205b14745|1|10.00','92932e230190731c32b0feaaa2ee7cf0|1|10.00','c0a0253cdf4358bf4ff88de53dcf98b5|1|15.00']; function setDiscount(discount_code) { var discount_code = arguments[0] !== undefined ? arguments[0] : ''; $('#discount-code-error').fadeOut(10); discount_code_md5 = md5(discount_code); discount_matched = 0; for (x=0; x total_subprice) { discount = total_subprice; } discount = parseFloat(discount); discount = discount.toFixed(2); } } return discount; } function setShipping(id, country, amount) { var shipping = 0; shipping = parseFloat(amount); if (shipping <= ' ') { shipping = 0; } $('#TotalShipping').val(shipping); $('#ShippingID').val(id); shipping_id = id; $("#shipping-country").html(country.replace(' ',' ')); calculateBagTotals(); $('#shopping-bag-shipping-modal').fadeOut(400); } function calculateBagTotals(action) { action = arguments[0] !== undefined ? arguments[0] : ''; total_quantity = 0; total_subprice = 0; total_discount = 0; total_shipping = 0; total_tax = 0; total_price = 0; shipping_id = 241; discount_code = ''; shopping_bag_string = ''; // Shopping bag lines $('.shopping-bag-list-row').each(function(){ row_quantity = parseFloat($(this).find('.quantity').html()); row_price = parseFloat($(this).find('.price').html().replace(',','').replace(document.getElementById('DefaultCurrencySymbol').value,'')); total_quantity = total_quantity + row_quantity; if ($(this).hasClass('return')) { total_subprice = total_subprice - (row_price * row_quantity); shopping_bag_string = shopping_bag_string + ',' + row_quantity + '|' + parseFloat($(this).find('.productOptionId').html().replace(',','')) + '|1'; } else { total_subprice = total_subprice + (row_price * row_quantity); shopping_bag_string = shopping_bag_string + ',' + row_quantity + '|' + parseFloat($(this).find('.productOptionId').html().replace(',','')) + '|0'; } }); if (total_quantity) { $("#shopping-bag-subtotal").html(formatPrice(total_subprice)); $("#shopping-bag-subtotal-line").fadeIn(10); total_price = total_subprice; } else { $('#TotalDiscount').val('0'); } // Discount line if (parseFloat($('#OrderItemTypeIDs').val()) == 4) { discount_code = $('#DiscountCode').val(); total_discount = calculateDiscount(); if (total_discount > 0.00) { $("#shopping-bag-discount").html(''+formatPrice(total_discount)+''); total_price = total_price - total_discount; } else { $("#shopping-bag-discount").html('enter discount code'); } $("#shopping-bag-discount-line").fadeIn(10); } // Shipping line if (parseFloat($('#OrderItemTypeIDs').val()) == 4) { total_shipping = parseFloat($('#TotalShipping').val()); shipping_id = parseFloat($('#ShippingID').val()); // Free shipping over £800 if (total_price >= 800) { $("#shopping-bag-shipping").html(formatPrice(0)); } else { $("#shopping-bag-shipping").html(formatPrice(total_shipping)); total_price = total_price + total_shipping; } $("#shopping-bag-shipping-line").fadeIn(10); } // Tax line if (parseFloat($('#OrderItemTypeIDs').val()) == 4) { add_tax_shipping_ids = ',2,3,6,12,16,17,22,23,29,35,59,62,63,64,74,79,80,86,87,90,103,104,109,112,124,129,130,131,133,139,147,148,150,158,168,179,180,184,194,198,203,204,211,218,219,239,241,246,'; if (add_tax_shipping_ids.indexOf(','+shipping_id+',') >= 0) { total_tax = parseFloat(((total_subprice / 100) * 12).toFixed(2)); } // total_tax = parseFloat(((total_subprice / 100) * 12).toFixed(2)); if (total_tax > 0) { $("#shopping-bag-tax").html(formatPrice(total_tax)); $("#shopping-bag-tax-line").fadeIn(10); total_price = total_price + total_tax; } else { $("#shopping-bag-tax-line").fadeOut(10); } } // Total line if (total_quantity) { $("#shopping-bag-total").html(formatPrice(total_price)); $("#shopping-bag-total-line").fadeIn(10); $("#total-to-pay").html(formatPrice(total_price)); $("#StripeFormAmount").val(total_price); } // Create shopping bag string shopping_bag_string = total_discount+','+shipping_id+','+total_shipping+'@'+shopping_bag_string; // Update the shopping bag $('#ShoppingBagString').val(shopping_bag_string); if ($('.checkout').length) { $('#ShoppingBagString').val(shopping_bag_string); } saveShoppingBag(action); // Show & hide shopping bag & icon $(".shopping-bag-quantity").html(total_quantity); if (total_quantity) { $("#shopping-bag-no-items").fadeOut(); $("#shopping-bag-bottom").fadeIn(1500); $(".shopping-bag-icon").removeClass("empty").addClass("full"); } else { $("#shopping-bag-no-items").delay(400).fadeIn(); $("#shopping-bag-bottom").fadeOut(1500); $(".shopping-bag-icon").removeClass("full").addClass("empty"); } $(".show-discount-modal").click(function() { $('#shopping-bag-discount-modal').fadeIn(400); return false; }); $(".show-shipping-modal").click(function() { $('#shopping-bag-shipping-modal').fadeIn(400); return false; }); } function saveShoppingBag(action) { action = arguments[0] !== undefined ? arguments[0] : ''; var data = { ShoppingBagList: $("#shopping-bag-list").html().trim(), DiscountCode: discount_code, TotalDiscount: total_discount, TotalShipping: total_shipping, ShippingID: shipping_id, ShoppingBagString: shopping_bag_string }; $.ajax({url: "inc/inc_shopping-bag.php?action="+action, type: "POST", async: true, data: data}); } function createShoppingBagLineRef() { var length = 4, charset = "abcdefghijklmnopqrstuvwxyz1234567890", retVal = ""; for (var i = 0, n = charset.length; i < length; ++i) { retVal += charset.charAt(Math.floor(Math.random() * n)); } return retVal; } function countShoppingBagRows() { var total_rows = 0; $('.shopping-bag-list-row').each(function(){ total_rows = total_rows + 1; }); return total_rows; } function clearShoppingBag() { $('.shopping-bag-list-row').fadeOut(); $('#TotalDiscount').val('0'); $('#TotalShipping').val('10'); $('#ShippingID').val('1'); $("#shopping-bag-bottom").fadeOut(function(){ $('.shopping-bag-list-row').remove(); calculateBagTotals(); }); } function sendOrder() { $('#confirm-status').fadeOut(); $('#confirm-circle').fadeOut(); $('#confirm-exit').fadeOut(); $('#confirm-try-again').fadeOut(); setTimeout(function(){ $('#confirm-status').html('Sending order. '); $('#confirm-status').fadeIn(); $('#confirm-circle').fadeIn(); }, 500); var order_success = false; var data = { ShoppingBagString: document.shopping_bag_form.ShoppingBagString.value, OrderItemTypeID: 1, CustomerID: 0, CustomerFirstName: document.customer_form.FirstName.value, CustomerLastName: document.customer_form.LastName.value, CustomerEmail: document.customer_form.Email.value, CustomerTel: '', CustomerAddress1: '', CustomerAddress1: '', CustomerAddress2: '', CustomerAddress3: '', CustomerAddress4: '', CustomerPostcode: '', CustomerCountry: '', DeliveryFirstName: '', DeliveryLastName: '', DeliveryAddress1: '', DeliveryAddress1: '', DeliveryAddress2: '', DeliveryAddress3: '', DeliveryAddress4: '', DeliveryPostcode: '', DeliveryCountry: '', DiscountCode: $('#DiscountCode').val(), PaymentTypeID: document.payment_form.PaymentTypeID.value, PaymentRef: document.payment_form.PaymentRef.value, CreatedByUserID: $('#UserID').val(), CreatedByDeviceID: $('#DeviceID').val(), UUID: $('#UUID').val() }; return $.ajax({url: "order.php", type: "POST", async: true, data: data, success: function(result) { if (result == 'success') { order_success = true; completeOrder(); } else { order_success = false; failOrder(); } }, failure: function(result) { console.log(result.ErrorDescription); order_success = false; }}); } function completeOrder() { $('#confirm-exit').fadeOut(); $('#confirm-try-again').fadeOut(); setTimeout(function(){ $('#confirm-status').html('Sale submitted successfully. '); $('.circle-loader').toggleClass('load-complete'); $('.checkmark').toggle(); }, 500); setTimeout(function(){ $('#confirm-exit').fadeIn(); }, 1500); // if (document.customer_form.email.value > ' ') { // $('#email-confirmation').html(document.customer_form.email.value); // } else { // $('#email-confirmation-line').fadeOut(10); // } clearShoppingBag(); } function failOrder() { $('#confirm-status').fadeOut(); $('#confirm-circle').fadeOut(); $('#confirm-exit').fadeOut(); $('#confirm-try-again').fadeOut(); setTimeout(function(){ $('#confirm-status').html('There was a problem sending this order. '); $('#confirm-status').fadeIn(); $('#confirm-try-again').fadeIn(); }, 500); }