(function () { 'use strict'; angular .module('LyncPix.ShoppingCartModule') .controller('ShoppingCartTopMenuController', ShoppingCartTopMenuController); /** @ngInject */ function ShoppingCartTopMenuController($log, $rootScope, ShoppingCart, Currency) { var vm = this; var UGUID = '38A5B679-B290-48C0-A828-36C8F6727D15'; $log.debug('ShoppingCartTopMenuController Activated'); activate(); function activate() { vm.shoppingCartTotalPrice = 0; loadShoppingCart(); loadCurrency(); vm.remove = remove; } function loadShoppingCart() { ShoppingCart.getAll(UGUID) .then(function (shoppingCart) { vm.shoppingCart = shoppingCart; vm.shoppingCartTotalPrice = vm.shoppingCart.reduce(function (prev, cur) { return Number(prev) + Number(cur.totalPrice) * Number(cur.count); }, 0); }); } function loadCurrency() { Currency.get(undefined, UGUID) .then(function (currency) { vm.currency = currency; }); } function remove(item) { ShoppingCart.remove(item.id, UGUID) .then(function (shoppingCart) { $rootScope.$emit('ShoppingCartRefreshed', true); }); } vm.goToCart = function () { location.href = '?g=' + UGUID + '&cart=1'; } $rootScope.$on('ShoppingCartRefreshed', function () { loadShoppingCart(); }); } })();