ShoppingCartPageController.js 1.8 KB

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