Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static partial class CacheKey
/// <summary>
/// Compare products cookie name
/// </summary>
public static string PRODUCTS_COMPARE_COOKIE_NAME => "Grand.CompareProducts";
public static string PRODUCTS_COMPARE_COOKIE_NAME => "Grand.CompareProduct";

/// <summary>
/// Key for caching
Expand Down
1 change: 0 additions & 1 deletion src/Web/Grand.Web/Components/Footer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private async Task<FooterModel> PrepareFooter()
PinterestLink = _storeInformationSettings.PinterestLink,
BlogEnabled = _blogSettings.Enabled,
KnowledgebaseEnabled = _knowledgebaseSettings.Enabled,
CompareProductsEnabled = _catalogSettings.CompareProductsEnabled,
NewsEnabled = _newsSettings.Enabled,
RecentlyViewedProductsEnabled = _catalogSettings.RecentlyViewedProductsEnabled,
RecommendedProductsEnabled = _catalogSettings.RecommendedProductsEnabled,
Expand Down
108 changes: 3 additions & 105 deletions src/Web/Grand.Web/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,106 +874,14 @@ await _mediator.Send(new SendProductAskQuestionMessageCommand() {
protected virtual List<string> GetComparedProductIds()
{
//try to get cookie
if (!HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out string productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))
if (!HttpContext.Request.Cookies.TryGetValue(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, out var productIdsCookie) || string.IsNullOrEmpty(productIdsCookie))
return new List<string>();

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

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

protected virtual void AddCompareProductsCookie(IEnumerable<string> comparedProductIds)
{
//delete current cookie if exists
HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);

//create cookie value
var comparedProductIdsCookie = string.Join(",", comparedProductIds);

//create cookie options
var cookieOptions = new CookieOptions {
Expires = DateTime.UtcNow.AddHours(CommonHelper.CookieAuthExpires),
HttpOnly = true
};
//add cookie
HttpContext.Response.Cookies.Append(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME, comparedProductIdsCookie, cookieOptions);
}

[HttpPost]
public virtual async Task<IActionResult> AddProductToCompareList(string productId)
{
var product = await _productService.GetProductById(productId);
if (product == null || !product.Published)
return Json(new
{
success = false,
comparemessage = "No product found with the specified ID"
});

if (product.ProductTypeId == ProductType.Auction || product.ProductTypeId == ProductType.Reservation)
return Json(new
{
success = false,
comparemessage = _translationService.GetResource("Products.ProductCantAddToCompareList")
});

if (!_catalogSettings.CompareProductsEnabled)
return Json(new
{
success = false,
comparemessage = "Product comparison is disabled"
});

//get list of compared product identifiers
var comparedProductIds = GetComparedProductIds();

//whether product identifier to add already exist
if (!comparedProductIds.Contains(productId))
comparedProductIds.Insert(0, productId);

//limit list based on the allowed number of products to be compared
comparedProductIds = comparedProductIds.Take(_catalogSettings.CompareProductsNumber).ToList();

//set cookie
AddCompareProductsCookie(comparedProductIds);

//activity log
_ = _customerActivityService.InsertActivity("PublicStore.AddToCompareList", productId,
_workContext.CurrentCustomer, HttpContext.Connection?.RemoteIpAddress?.ToString(),
_translationService.GetResource("ActivityLog.PublicStore.AddToCompareList"), product.Name);

return Json(new
{
success = true,
comparemessage = string.Format(_translationService.GetResource("Products.ProductHasBeenAddedToCompareList.Link"), Url.RouteUrl("CompareProducts"))
});
}

public virtual IActionResult RemoveProductFromCompareList(string productId)
{
var product = _productService.GetProductById(productId);
if (product == null)
return RedirectToRoute("HomePage");

if (!_catalogSettings.CompareProductsEnabled)
return RedirectToRoute("HomePage");

//get list of compared product identifiers
var comparedProductIds = GetComparedProductIds();

//whether product identifier to remove exists
if (!comparedProductIds.Contains(productId))
return RedirectToRoute("CompareProducts");

//it exists, so remove it from list
comparedProductIds.Remove(productId);

//set cookie
AddCompareProductsCookie(comparedProductIds); ;

return RedirectToRoute("CompareProducts");
return productIds.Select(productId => productId).Distinct().Take(10).ToList();
}

public virtual async Task<IActionResult> CompareProducts()
Expand Down Expand Up @@ -1008,16 +916,6 @@ public virtual async Task<IActionResult> CompareProducts()
return View(model);

}

public virtual IActionResult ClearCompareList()
{
if (!_catalogSettings.CompareProductsEnabled)
return RedirectToRoute("HomePage");

HttpContext.Response.Cookies.Delete(CacheKey.PRODUCTS_COMPARE_COOKIE_NAME);

return RedirectToRoute("CompareProducts");
}
#endregion

#region Calendar
Expand Down
15 changes: 0 additions & 15 deletions src/Web/Grand.Web/Endpoints/EndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,11 @@ private void RegisterProductRoute(IEndpointRouteBuilder endpointRouteBuilder, st
pattern + "productreviews/{productId}",
new { controller = "Product", action = "ProductReviews" });

//comparing products
endpointRouteBuilder.MapControllerRoute("AddProductToCompare",
pattern + "compareproducts/add/{productId?}",
new { controller = "Product", action = "AddProductToCompareList" });

//set review helpfulness (AJAX link)
endpointRouteBuilder.MapControllerRoute("SetProductReviewHelpfulness",
pattern + "setproductreviewhelpfulness",
new { controller = "Product", action = "SetProductReviewHelpfulness" });

//comparing products
endpointRouteBuilder.MapControllerRoute("RemoveProductFromCompareList",
pattern + "compareproducts/remove/{productId}",
new { controller = "Product", action = "RemoveProductFromCompareList" });

endpointRouteBuilder.MapControllerRoute("ClearCompareList",
pattern + "clearcomparelist/",
new { controller = "Product", action = "ClearCompareList" });


//product attributes with "upload file" type
endpointRouteBuilder.MapControllerRoute("UploadFileProductAttribute",
pattern + "uploadfileproductattribute/{attributeId?}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ private async Task<string> PrepareRobotsTextFile()
"/checkout/shippingmethod",
"/checkout/paymentinfo",
"/checkout/paymentmethod",
"/clearcomparelist",
"/compareproducts",
"/compareproducts/add/*",
"/account/activation",
"/account/addresses",
"/account/changepassword",
Expand Down
1 change: 0 additions & 1 deletion src/Web/Grand.Web/Models/Common/FooterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public FooterModel()
public bool SitemapEnabled { get; set; }
public bool BlogEnabled { get; set; }
public bool NewsEnabled { get; set; }
public bool CompareProductsEnabled { get; set; }
public bool RecentlyViewedProductsEnabled { get; set; }
public bool RecommendedProductsEnabled { get; set; }
public bool NewProductsEnabled { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
}
@if (!Model.ProductPrice.DisableAddToCompareListButton && Model.ProductType == ProductType.SimpleProduct)
{
<button v-b-tooltip.hover.bottom title="@Loc["ShoppingCart.AddToCompareList"]" class="btn btn-secondary" onclick="AxiosCart.addproducttocomparelist('@addtocomparelink');return false;">
<button v-b-tooltip.hover.bottom title="@Loc["ShoppingCart.AddToCompareList"]" class="btn btn-secondary" onclick="AxiosCart.addproducttocomparelist('@Model.Id', '@string.Format(Loc["Products.ProductHasBeenAddedToCompareList.Link"], Url.RouteUrl("CompareProducts"))')">
<span class="sr-only">AddToCompareList</span>
<b-icon icon="shuffle"></b-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
</template>
</template>
<template v-if="!Model.ProductPrice.DisableAddToCompareListButton && Model.ProductType == 0">
<button v-b-tooltip.hover.bottom title="@Loc["ShoppingCart.AddToCompareList"]" class="btn btn-secondary" :onclick="'AxiosCart.addproducttocomparelist(`@Url.RouteUrl("AddProductToCompare")/' + Model.Id + '`);return false;'">
<button v-b-tooltip.hover.bottom title="@Loc["ShoppingCart.AddToCompareList"]" class="btn btn-secondary" :onclick="'AxiosCart.addproducttocomparelist(`'+ Model.Id +'`, `@string.Format(Loc["Products.ProductHasBeenAddedToCompareList.Link"], Url.RouteUrl("CompareProducts"))`)'">
<span class="sr-only">AddToCompareList</span>
<b-icon icon="shuffle"></b-icon>
</button>
Expand Down
Loading