ShoppingCartPageController.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. app.controller('ShoppingCartPageController',['$scope','$window','$timeout',function($scope,$window,$timeout){
  2. var firebaseShoppingCart = firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('shoppingCart');
  3. $scope.shoppingCartItems = {};
  4. firebaseShoppingCart.on('value',function(snap){
  5. $scope.shoppingCartItems = snap.val();
  6. })
  7. // funcitons
  8. $scope.totalPrice = function(){
  9. $scope.total = 0;
  10. angular.forEach($scope.shoppingCartItems,function(item){
  11. $scope.total += item.overallPrice;
  12. })
  13. return $scope.total;
  14. }
  15. $scope.removeItem = function(i){
  16. // var shoppingCartFooter = document.querySelector('shopping-cart-page .items-footer');
  17. // var shoppingCartItem = document.querySelector('.shopping-cart-page .item');
  18. // var shoppingCartItemHeight = $window.getComputedStyle(shoppingCartItem, null).getPropertyValue('height');
  19. // shoppingCartFooter.style.transform = 'translateY(-'+shoppingCartItemHeight+')!important';
  20. // var shoppingCartFooterJQ = angular.element(document.querySelector('.shopping-cart-page .items-footer'));
  21. // shoppingCartFooterJQ.addClass('shopping-cart-footer-animate');
  22. // $timeout(function(){
  23. // shoppingCartFooterJQ.removeClass('shopping-cart-footer-animate');
  24. // },1000)
  25. var keys = Object.keys($scope.shoppingCartItems);
  26. delete $scope.shoppingCartItems[keys[i]];
  27. firebaseShoppingCart.set($scope.shoppingCartItems);
  28. }
  29. $scope.orderSuccess = false;
  30. $scope.checkOut = function(){
  31. firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('userDiets').set($scope.shoppingCartItems);
  32. firebaseShoppingCart.set({});
  33. $scope.orderSuccess = true;
  34. }
  35. }])