Last active
August 29, 2015 14:04
-
-
Save aaronroberson/0f8e21ee45eb11e5d589 to your computer and use it in GitHub Desktop.
Revisions
-
aaronroberson revised this gist
Jul 16, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function updateItemsCookie() { // Initialize an object to be saved as the cookie var itemsCookie = {}; // Loop through the items in the cart -
aaronroberson created this gist
Jul 16, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ emptyCart: function() { // Sets items object to an empty object items = {}; // Remove the items cookie $cookieStore.remove('items'); } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ updateItemsCookie: function() { // Initialize an object to be saved as the cookie var itemsCookie = {}; // Loop through the items in the cart angular.forEach(items, function(item, key) { // Add each item to the items cookie, // using the guid as the key and the quantity as the value itemsCookie[key] = item.quantity; }); // Use the $cookieStore service to persist the itemsCookie object to the cookie named 'items' $cookieStore.put('items', itemsCookie); }