Esempio n. 1
0
        public async Task <IActionResult> MergeCarts([FromBody] MergeCartModel model)
        {
            var settings = new JsonSerializerSettings();

            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            var user = await _userManager.GetUserAsync(User);

            //cannot transfer cart if there is no user
            if (user == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            //getting the visitor id of the anonymous cart
            CookieHelper helper       = new CookieHelper(_accessor);
            string       oldVisitorId = helper.GetOldVisitorId();

            var result = _orderService.TransformCart(oldVisitorId, user.Id, model.DeleteOld);

            //the old cart has been transfered and deleted, deleting the old visitor id
            helper.DeleteOldVisitorId();

            return(Json(result, settings));
        }