|
1 |
| -zenergyApp.controller("cartPageController", ["$scope", "$resource", "$uibModal", "$location", "tokenService", function ($scope, $resource, $uibModal, $location, tokenService) { |
| 1 | +zenergyApp.controller("cartPageController", ["$scope", "$resource", "$uibModal", "$location", "tokenService", "$route", function ($scope, $resource, $uibModal, $location, tokenService, $route) { |
2 | 2 |
|
3 | 3 | if ($scope.isAuthanticated()) {
|
4 | 4 |
|
|
8 | 8 | method: 'PUT' // this method issues a PUT request
|
9 | 9 | },
|
10 | 10 | removeFromBasket: {
|
11 |
| - method: 'DELETE', isArray: true |
| 11 | + method: 'DELETE', isArray: true |
12 | 12 | }
|
13 | 13 | });
|
14 | 14 |
|
15 |
| - $scope.cartContents = CartContents.query({userId : tokenService.getUserId()}, function () { |
| 15 | + $scope.cartContents = CartContents.query({ userId: tokenService.getUserId() }, function () { |
16 | 16 | console.log($scope.cartContents);
|
17 | 17 | });
|
18 | 18 |
|
|
21 | 21 | for (var i = 0; i < $scope.cartContents.length; i++) {
|
22 | 22 | var c = $scope.cartContents[i];
|
23 | 23 | if ($scope.isMember())
|
24 |
| - total += ((c.product.productPrice -((c.product.productPrice * c.product.memberReduction) / 100)) * c.productQuantity); |
| 24 | + total += ((c.product.productPrice - ((c.product.productPrice * c.product.memberReduction) / 100)) * c.productQuantity); |
25 | 25 | else
|
26 | 26 | total += (c.product.productPrice * c.productQuantity);
|
27 | 27 | }
|
|
36 | 36 | });
|
37 | 37 | };
|
38 | 38 |
|
39 |
| - $scope.setQuantity = function(c,i) |
40 |
| - { |
| 39 | + $scope.setQuantity = function (c, i) { |
41 | 40 | c.productQuantity = c.productQuantity + i;
|
42 |
| - c.$update({ userId: c.userId }, |
| 41 | + c.$update({ userId: c.userId }, |
43 | 42 | function (response) {
|
44 | 43 | },
|
45 | 44 | function (response) {
|
|
48 | 47 | }
|
49 | 48 |
|
50 | 49 | $scope.proceed = function () {
|
51 |
| - var BasketValidation = $resource('api/users/'+tokenService.getUserId()+'/basket/validate', {}, { |
| 50 | + var BasketValidation = $resource('api/users/' + tokenService.getUserId() + '/basket/validate', {}, { |
52 | 51 | update: {
|
53 | 52 | method: 'PUT' // this method issues a PUT request
|
54 | 53 | }
|
55 | 54 | });
|
56 | 55 |
|
57 |
| - BasketValidation.update({}); |
| 56 | + BasketValidation.update({}, |
| 57 | + function (response) { |
| 58 | + $route.reload(); |
| 59 | + }, |
| 60 | + function (response) { |
| 61 | + }); |
58 | 62 | };
|
59 | 63 |
|
60 | 64 |
|
61 | 65 |
|
62 | 66 | }
|
63 | 67 | else
|
64 |
| - $location.path("/") |
| 68 | + $location.path("/"); |
65 | 69 | }]);
|
0 commit comments