From a86715436c00bb6cc35cf7ccac94c5c7da6991ee Mon Sep 17 00:00:00 2001 From: Connor L Jackson Date: Mon, 28 Nov 2016 17:36:51 -0500 Subject: [PATCH] Implementing orders --- html/javascript/shoppingCart.js | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 html/javascript/shoppingCart.js diff --git a/html/javascript/shoppingCart.js b/html/javascript/shoppingCart.js new file mode 100644 index 0000000..75f631e --- /dev/null +++ b/html/javascript/shoppingCart.js @@ -0,0 +1,88 @@ +var dev1 = { + id: 1, + name:"George", + description:"George is probably the coolest iPhone to exist. Ever. Point blank, period.", + hardware:"iphone", + software:"apple", +}; + +var dev2 = { + id: 2, + name:"Greyson", + description:"Greyson is pretty cool.. I guess.", + hardware:"iphone", + software:"apple", +}; + +var dev3 = { + id: 3, + name:"Linkin Park", + description:'"The hardest part of ending is starting again."', + hardware:"ipad", + software:"apple", +}; + +var dev4 = { + id: 4, + name:"Abercrombie", + description:"To all the people that hated me in high school, I have the prettiest clothes you all wear now!!", + hardware:"ipad", + software:"apple", +}; + +var dev5 = { + id: 5, + name:"Hulk", + description:"Go ahead and HULK SMASH! this awesome computer stick into your USB.", + hardware:"computerStick", + software:"intel", +}; + +var dev6 = { + id: 6, + name:"Captain America", + description:'"Make America Great Again. Wait, thats someone else.."', + hardware:"computerStick", + software:"intel", +}; + +var devices = [dev1, dev2, dev3, dev4, dev5, dev6]; + +function getCartItems(){ + //initiate array for them + var cart = new Array; + //get them from local storage + var cart_str = localStorage.getItem('cart'); + //if there is at least one object already we need to convert it from JSON to string + if (cart_str !== null) { + cart = JSON.parse(cart_str); + } + return cart; +} + +function show(){ + var cart = getCartItems(); + var html = ''; + if(cart.length !== 0){ + for(var i = 0; i < cart.length; i++){ + var id = cart[i]; //this gets the id value from the cart + for(int j = 0; j < devices.length; j++){ //iterate device list + if(devices[j].id === id){ //match the id's + html += '
' + devices[j].name + '
'; //create listing of all the devices + break; //break out of loop when we match + } + } + } + } + else{ + html += 'Shopping cart is empty.'; + } + + document.getElementById('shoppingContainer').innerHTML = html; //adds what we just generated to the webpage + + var checkboxes = document.getElementsByClassName('deviceCheckbox'); //get all the checkboxes we just placed! + for(int i = 0; i < checkboxes.length; i++){ + checkboxes[i].addEventListener('click',addToSelected); //when we click on a checkbox, it should add that item to the selected local storage + } + +} \ No newline at end of file