登录后保留购物车项目

时间:2018-05-06 13:00:46

标签: javascript angularjs

当我向购物车添加商品并登录时,购物车中的商品被删除。所以我想将访客的购物车商品移动到登录用户的购物篮中。 我正在使用angularjs,我正在考虑使用$ window.localStorage()

情形:

  • 将重复添加到购物车
  • 登录或注册
  • 购物车将为空

这是我的功能

        Auth.$onAuthStateChanged(function (currentUser) {
        if(currentUser) {
            firebase.database().ref('users/' + 
            currentUser.uid).once('value').then(function (loggedUser) {
                $scope.$apply(function () {
                    $scope.user_type = loggedUser.val().user_type;
                });
            });
        }
    });

   $scope.$on('getAuth', function () {
        DashboardService.getOrders().then(function (orders) {
            model.length = orders.length;
            $scope.$apply()
        });
    });


    $scope.$on('OrdersUpdate', function (event, args) {
        model.length = DashboardService.allOrders.length;
    });


    function signOut() {
        DashboardService.allOrders = [];
       // $state.go('home-page');
        Auth.$signOut();
       $window.localStorage.clear();
        $location.path('/');
    }

0 个答案:

没有答案