(function(angular) { "use strict"; var app = angular.module('Swagwise'); // Inject in $cookieStore, SwagService and app config app.factory('CartService', function() { // Private items object var items = {}; // Update cookies function updateItemsCookie() { } // Angular factories return service objects return { getItems: function() { // Initialize itemsCookie variable var itemsCookie; // Check if items object has been populated if(!items.length) { // Populate items object from cookie // Check if cookie exists if(itemsCookie) { // Loop through cookie and get the item by it's id // Add each item to the items object and set it's quantity } } // Return the items object return items; }, addItem: function(item) { // Checks if item already exists // If it exists, updates the quantity // If it doesn't exist, adds quantity property with value of 1 then // pushes the item onto the items array // Update cookie updateItemsCookie(); }, removeItem: function(id) { // Removes an item from the items object // Update cookie updateItemsCookie(); }, emptyCart: function() { // Re-initialize items object to an empty object items = {}; // Remove items cookie using $cookieStore }, getItemCount: function() { // Initialize total counter var total = 0; // Loop through items and increment the total by the item quantity // Returns number of items, including item quantity return total; }, getCartSubtotal: function() { // Initialize the total counter var total = 0; // Loop through the items and multiply the quantity by the item price and increment the total // Return the item quantity times item price for each item in the array return total; }, getCartTotal: function() { return this.getCartSubtotal(); }, checkout: function() { // Impliment the checkout } }; }); })(window.angular);