Last active
August 29, 2015 14:04
-
-
Save aaronroberson/0f8e21ee45eb11e5d589 to your computer and use it in GitHub Desktop.
Geekwise2 Day 8 - Shopping Cart Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emptyCart: function() { | |
// Sets items object to an empty object | |
items = {}; | |
// Remove the items cookie | |
$cookieStore.remove('items'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getItems: function() { | |
// Initialize the itemsCookie variable | |
var itemsCookie; | |
// Check if cart is empty | |
if(!items.length) { | |
// Get the items cookie | |
itemsCookie = $cookieStore.get('items'); | |
// Check if the item cookie exists | |
if(itemsCookie) { | |
// Loop through the items in the cookie | |
angular.forEach(itemsCookie, function(item, key) { | |
// Get the product details from the ProductService using the guid | |
SwagService.get({id: key)}.then(function(response){ | |
var product = response.data; | |
// Update the quantity to the quantity saved in the cookie | |
product.quantity = item; | |
// Add the product to the cart items object using the guid as the key | |
items[product.guid] = product; | |
}); | |
}); | |
} | |
} | |
// Returns items object | |
return items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment