var products = []; products[211] = ["Silicone Earbud Protection Case", 14.96, "Nonstop Fitness Care", "Keep your earbuds safe with this Silicone Earbud Protection Case! Designed for durability, it may help protect against scratches, drops, and daily wear while ensuring a secure fit. A must-have accessory for keeping your earbuds in top condition on the go!", "", "X 2"]; products[212] = ["Silicone Earbud Protection Case", 19.98, "Nonstop Fitness Care", "", "", "X 3"]; products[213] = ["Silicone Earbud Protection Case", 49.96, "Nonstop Fitness Care", "", "", "X 6"]; products[214] = ["Posture Corrector", 19.96, "Nonstop Fitness Care", "Improve your posture with this comfortable and adjustable posture corrector! Designed to provide gentle support, it may help align your spine, reduce slouching, and relieve back discomfort. Perfect for daily wear to promote better posture and confidence.", "", "X 1"]; products[215] = ["Posture Corrector", 27.97, "Nonstop Fitness Care", "Maintaining good posture is essential for overall health and confidence, but modern lifestyles often make it challenging. A posture corrector may help align your shoulders and spine, reducing strain and discomfort caused by slouching or prolonged sitting. Lightweight, adjustable, and easy to use, it's the perfect solution to improve posture and boost well-being, whether you're at work, home, or on the go.", "", "X 2"]; products[216] = ["Fitness Tracker", 24.98, "Nonstop Fitness Care", "Stay on top of your health goals with this sleek fitness tracker! It may help monitor your steps, heart rate, sleep patterns, and more, providing real-time insights to keep you motivated. With a comfortable design and long battery life, it’s perfect for tracking your progress all day, every day!", "", "X 1"]; products[217] = ["Fitness Tracker", 46.86, "Nonstop Fitness Care", "A fitness tracker is your ultimate companion for achieving health goals and staying active. It monitors steps, heart rate, sleep patterns, and more, providing real-time insights to help you stay motivated and on track. Lightweight and stylish, it fits seamlessly into your lifestyle, making fitness fun and achievable every day.", "", "X 2"]; products[218] = ["Fitness Tracker", 93.72, "Nonstop Fitness Care", "A fitness tracker is your ultimate companion for achieving health goals and staying active. It monitors steps, heart rate, sleep patterns, and more, providing real-time insights to help you stay motivated and on track. Lightweight and stylish, it fits seamlessly into your lifestyle, making fitness fun and achievable every day.", "", "X 5"]; products[219] = ["Personal Blender", 39.96, "Nonstop Fitness Care", "A personal blender is perfect for creating quick, healthy smoothies and shakes on the go. It may help you create your favorite drinks in seconds. Designed for convenience, it features a portable, easy-to-clean design, making healthy choices effortless wherever you are!", "", "X 1"]; products[220] = ["Personal Blender", 65.6, "Nonstop Fitness Care", "A personal blender is perfect for creating quick, healthy smoothies and shakes on the go. Compact and powerful, it blends fruits, vegetables, and even ice in seconds, making it a great addition to any busy lifestyle. With easy cleanup and portable design, it’s ideal for fitness enthusiasts and anyone who loves convenience in the kitchen.", "", "X 2"]; products[221] = ["Personal Blender", 124.96, "Nonstop Fitness Care", "A personal blender is perfect for creating quick, healthy smoothies and shakes on the go. Compact and powerful, it blends fruits, vegetables, and even ice in seconds, making it a great addition to any busy lifestyle. With easy cleanup and portable design, it’s ideal for fitness enthusiasts and anyone who loves convenience in the kitchen.", "", "X 4"]; products[222] = ["Wireless Earbuds", 59.96, "Nonstop Fitness Care", "Experience true freedom with wireless earbuds! These sleek and comfortable earbuds may deliver high-quality sound and seamless connectivity. Perfect for music, calls, or workouts, they may offer comfort, durability, and long-lasting battery life. A perfect companion for on-the-go listening.", "", "X 1"]; products[223] = ["Wireless Earbuds", 129.96, "Nonstop Fitness Care", "Wireless earbuds deliver a seamless audio experience with crystal-clear sound and the freedom of tangle-free listening. Perfect for music, calls, or workouts, they offer comfort, durability, and long-lasting battery life. Compact and stylish, they’re the ideal companion for staying connected on the go.", "", "X 3"]; console.log(products); var orderedItems = []; var orderedTotQty = 0; var maxQty = 10; var shipRates = false; var handling = 0; var carturl = "cart.php"; //Funtion adds Items to Cart var addItem = function(itemId, Qty) { orderedTotQty = $.cookie('orderedTotQty'); if (!orderedTotQty) { orderedTotQty = 0; } Qty = parseInt(Qty); if(Qty > maxQty) { alert("Maximum " + maxQty + " of this product can be selected in a single order"); return false; } var order = $.cookie('order'); if (!order) { order = itemId + "-" + Qty; orderedItems[itemId] = Qty; } else { var itemExists = false; var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (order != "") { order += "|"; } if (prodId == itemId) { alert("Product already exist in cart"); return false; if((quantity + Qty) > maxQty) { alert("Maximum " + maxQty + " of this product can be selected in a single order"); return false; } quantity += Qty; order += prodId + "-" + quantity; itemExists = true; } else { order += prodId + "-" + quantity; } orderedItems[prodId] = quantity; } if (!itemExists) { if (order != "") { order += "|"; } order += itemId + "-" + Qty; orderedItems[itemId] = Qty; } } orderedTotQty = parseInt(orderedTotQty); orderedTotQty += Qty; $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(false, 'add', itemId); } else { $(location).attr('href', carturl); } }; //Funtion decrements Items to Cart var removeItem = function(itemId, Qty) { Qty = parseInt(Qty); var order = $.cookie('order'); if (!order) { orderedItems[itemId] = 0; refreshRow(itemId); } else { var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { quantity -= Qty; if (quantity > 0) { if (order != "") { order += "|"; } order += prodId + "-" + quantity; } itemExists = true; orderedItems[prodId] = quantity; refreshRow(itemId); } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; orderedItems[prodId] = quantity; } } } orderedTotQty -= Qty; $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(false, 'remove', itemId); } else { $(location).attr('href', carturl); } }; //Funtion sets Item quantity on the Cart var setItemQty = function(itemId, Qty) { Qty = parseInt(Qty); if(Qty > maxQty || Qty < 0) { return false; } var order = $.cookie('order'); orderedTotQty = 0; if (!order) { orderedItems[itemId] = 0; } else { var items = order.split("|"); order = ""; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { quantity = Qty; if (order != "") { order += "|"; } order += prodId + "-" + quantity; itemExists = true; } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; } orderedItems[prodId] = quantity; orderedTotQty += quantity; } } $('.cartqty').html(orderedTotQty); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/') + 1); if (filename == carturl) { showCart(false, 'set', itemId); } else { $(location).attr('href', carturl); } }; var removeRowItem = function(itemId) { var order = $.cookie('order'); if (!order) { orderedTotQty = 0; } else { var items = order.split("|"); order = ""; orderedTotQty = 0; orderedItems = null; orderedItems = new Array(); for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId == itemId) { } else { if (order != "") { order += "|"; } order += prodId + "-" + quantity; orderedTotQty += quantity; orderedItems[prodId] = quantity; } } } if($('#prow-' + itemId).length == 1) { $('#prow-' + itemId).remove(); } $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); showCart(false, 'removerow', itemId); }; //Emptying the cart var emptyCart = function() { var order = $.cookie('order'); order = ""; orderedTotQty = 0; orderedItems = null; orderedItems = new Array(); $.cookie('order', order); $.cookie('orderedTotQty', orderedTotQty); if($('[id^="prow-"]').length > 0) { $('[id^="prow-"]').each(function(){ $(this).remove(); }); } showCart(false, 'empty'); }; //Displaying the cart items & calculations function showTotalPrice() { var cartHtml = ""; var total = 0; var shipping = 0; var grand_total = 0; var sub_total = 0; var shippingType = ''; var order = $.cookie('order'); orderedTotQty = $.cookie('orderedTotQty'); if($('#shippingCountry').val() == '') { shippingType = ''; } else if($('#shippingCountry').val() == 'US') { shippingType = 'US'; } else { shippingType = 'INTERNATIONAL'; } if (!order) { orderedTotQty = 0; } else { var items = order.split("|"); if(shipRates) { shipping = shipRates * 1.0; } for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId != "" && quantity > 0) { sub_total = round((quantity * products[prodId][1]), 2); total += (quantity * products[prodId][1]); } } total = round(total, 2); } var snh = shipping + handling; //if(shipping == 0) { // snh = shipping; //} console.log(snh); grand_total = total + snh; $('#total-price').html('$ ' + total.toFixed(2)); $('#shipping-price').html('$ ' + snh.toFixed(2)); $(".tot-prc").html('$' + total.toFixed(2)); $('#grand-total').html('$ ' + grand_total.toFixed(2)); }; // Refresh row content with updated quantity / price for a product function refreshRow(pid) { pid = parseInt(pid); quantity = orderedItems[pid]; sub_total = round((quantity * products[pid][1]), 2); $('#prow-' + pid + ' .tot-price').html('$' + sub_total.toFixed(2) + ' USD'); $('#prow-' + pid + ' .qtybox').val(quantity); $('#prow-' + pid + ' .dispqty').html(quantity); } //Displaying the cart items & calculations function showCart(showFullCart, act, itm) { var cartHtml = ""; var order = $.cookie('order'); orderedTotQty = $.cookie('orderedTotQty'); if (!order) { orderedTotQty = 0; if($('[id^="prow-"]').length == 0) { $("#cartBox").html("

You have not selected any product...

  Browse Products"); } showTotalPrice(); return false; } else { var items = order.split("|"); var total = 0; var shipping = 0; var grand_total = 0; orderedTotQty = parseInt(orderedTotQty); //console.log('showFullCart'); //console.log(showFullCart); if (typeof showFullCart === "undefined") { return false; } else if(showFullCart == false) { if ((typeof act !== "undefined") && (typeof itm !== "undefined")) { if((act == 'add' || act == 'set' || act == 'remove') && itm > 0) { refreshRow(itm); } else if(act == 'removerow' && itm > 0) { itm = parseInt(itm); } } showTotalPrice(); return false; } orderedItems = null; orderedItems = new Array(); cartHtml += "
Order Summary Price
"; cartHtml += "
Your Order QtyUnit PriceTotal
"; var total = 0; for (var i = 0; i < items.length; i = i + 1) { var position = items[i].indexOf("-"); var prodId = items[i].substring(0, position); var quantity = parseInt(items[i].substring(position + 1)); if (prodId != "" && quantity > 0) { orderedItems[prodId] = quantity; var sub_total = round((quantity * products[prodId][1]), 2); total += sub_total; cartHtml += "
" + "
" + "
" + products[prodId][4] + "
" + products[prodId][0] + ""+ products[prodId][5] +"
" + "
" + "" + ""+ "
"+ quantity +"
" + "
$" + (products[prodId][1]).toFixed(2) + "
" + "
$" + sub_total.toFixed(2) + "
" + "
" } } cartHtml += "
"; cartHtml += "
" +"
" +"
    " +"
  • Sub Total: $" + total.toFixed(2) + "
  • " +"
  • Shipping & Handling: $0.00
  • " +"
  • Total: $" + total.toFixed(2) + "
  • " +"
" +"
" +"
"; cartHtml += "
" if (cartHtml != "") { $("#cartBox").html(cartHtml); $(".cart-box").html(cartHtml); $(".tot-prc").html('$' + total.toFixed(2)); } else { $("#cartBox").html(" Loading..."); $(".cart-box").html('You have not selected any product... '); } return false; } }; var round = function(value, decimals) { return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); };