Exemplo n.º 1
0
        /// <summary>
        /// Get a list of identifier of compared products
        /// </summary>
        /// <returns>List of identifier</returns>
        protected async Task <List <int> > GetComparedProductIds()
        {
            //var httpContext = _httpContextAccessor.HttpContext;
            //if (httpContext?.Request == null)
            //    return new List<int>();

            //try to get cookie
            var cookieName       = $"{NopCookieDefaults.Prefix}{NopCookieDefaults.ComparedProductsCookie}";
            var productIdsCookie = await _jsService.GetCookie(cookieName);

            if (string.IsNullOrEmpty(productIdsCookie))
            {
                return(new List <int>());
            }

            //if (!httpContext.Request.Cookies.TryGetValue(cookieName, out var productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))
            //    return new List<int>();

            //get array of string product identifiers from cookie
            var productIds = productIdsCookie.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            //return list of int product identifiers
            return(productIds.Select(int.Parse).Distinct().ToList());
        }