AddProductToCompareList small changes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hi,

AddProductToCompareList(int productId)
        {
            var oldProductIds = GetComparedProductIds();
            var newProductIds = new List<int>();
            newProductIds.Add(productId);
            foreach (int oldProductId in oldProductIds)
                if (oldProductId != productId)
                    newProductIds.Add(oldProductId);

            var compareCookie = _httpContext.Request.Cookies.Get(COMPARE_PRODUCTS_COOKIE_NAME);
            if (compareCookie == null)
            {
                compareCookie = new HttpCookie(COMPARE_PRODUCTS_COOKIE_NAME);
                compareCookie.HttpOnly = true;
            }
            compareCookie.Values.Clear();
            int i = 1;
            foreach (int newProductId in newProductIds)
            {
                compareCookie.Values.Add("CompareProductIds", newProductId.ToString());
                if (i == _catalogSettings.CompareProductsNumber)
                    break;
                i++;
            }
            compareCookie.Expires = DateTime.Now.AddDays(10.0);
            _httpContext.Response.Cookies.Set(compareCookie);
        }


if we have empty compare list and add one product to this list we are not be able to read compareCookie on client site(JS) because of the following string.
compareCookie.HttpOnly = true;

please remove this string.
thank you in advance.
7 years ago
Hi Konstantin,

Could you please clarify how exactly you plan to use it? And why?
7 years ago
Hi Andrei!

we just want to show amount of products in compare list in header.

Issue:
we can't read compareCookie after first AJAX action with AddProductToCompareList.
Current our solution:
We override CompareProductsService.AddProductToCompareList in our plugin to figure out this issue.
Future maintenance:
we can share our js code if nopTeam wants to implement "Show amount of products in compare list in header" feature
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.