Last active
November 13, 2015 13:41
-
-
Save aaronroberson/a26f85400a3e8818a834 to your computer and use it in GitHub Desktop.
Revisions
-
aaronroberson revised this gist
Jul 16, 2014 . 1 changed file with 7 additions and 2 deletions.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 @@ -8,6 +8,11 @@ // Private items object var items = {}; // Update cookies function updateItemsCookie() { } // Angular factories return service objects return { @@ -37,14 +42,14 @@ // 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() { -
aaronroberson revised this gist
Jul 13, 2014 . 2 changed files with 33 additions and 0 deletions.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 @@ <button class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i> Add to cart</button> 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,32 @@ (function(angular) { "use strict"; var app = angular.module('Swagwise'); // Inject the CartService app.directive('addCartButton', function() { return { // E for Element // A for Attribute // C for Class restrict: 'E', scope: { // 3 types of bindings for scope properties // @ which is a string // & which is a one-way binding // = which is two-way binding }, replace: true, templateUrl: 'templates/add-cart-button.html', link: function(scope, elem, attr) { scope.addItem = function(item) { // Pass the item into the addItem method of the CartService }; } }; }); })(window.angular); -
aaronroberson revised this gist
Jul 13, 2014 . 1 changed file with 11 additions and 7 deletions.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 @@ -14,23 +14,27 @@ }; $scope.getItemCount = function() { // Return the item count from the CartService }; $scope.getCartSubtotal = function() { // Return the subtotal using the getCartSubtotal method of the CartService }; $scope.getCartTotal = function() { // Return the cart total using the getCartTotal methode of the CartService }; $scope.removeItem = function(id) { // Pass the item id into the removeItem method of the CartService }; $scope.emptyCart = function() { // Invoke the emptyCart method of the CartService } $scope.checkout = function() { // Invoke the checkout method of the CartService }; }); -
aaronroberson created this gist
Jul 13, 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,38 @@ (function(angular) { "use strict"; var app = angular.module('Swagwise'); // Inject in the CartService app.controller('CartController', function($scope) { // Set the items on the scope to the items in the CartService using the getItems method $scope.items = {}; $scope.addItem = function(item) { // Pass the item into the addItem method of the CartService }; $scope.getItemCount = function() { // return the item count from the CartService }; $scope.removeItem = function(id) { // Pass the item id into the removeItem method of the CartService }; $scope.getCartSubtotal = function() { // return the subtotal using the getCartSubtotal method of the CartService }; $scope.getCartTotal = function() { // Return the cart total using the getCartTotal methode of the CartService }; $scope.checkout = function() { // Call the checkout method of the CartService }; }); })(window.angular); 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,87 @@ (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 = {}; // 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 this.updateItemsCookie(); }, removeItem: function(id) { // Removes an item from the items object // Update cookie this.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); 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,30 @@ (function(angular) { "use strict"; var app = angular.module('Swagwise'); // Inject in the CartService app.directive('miniCart', function() { return { // Create an isolated scope scope: { }, restrict: 'E', replace: true, templateUrl: 'templates/mini-cart.html', link: function(scope, elem, attr) { scope.getCartSubtotal = function() { // Returns subtotal from CartService }; scope.getItemCount = function() { //Returns the item count from the CartService }; } }; }); })(window.angular); 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,8 @@ <!-- Use ng-show to show if the items have been added to the cart --> <div class="row"> <div class="col-sm-4 col-sm-offset-8 text-right"> <!-- Display the subtotal followed by the number of items in the cart --> <i class="glyphicon glyphicon-shopping-cart"></i> Subtotal: - items <a class="btn btn-success" ui-sref="cart" role="button">view cart</a> </div> </div>