Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Minor changes with compare products

supportd19085fd8693
diff --git a/src/Web/Grand.Web/Controllers/ProductController.cs b/src/Web/Grand.Web/Controllers/ProductController.cs
index e031ac0e9..66365ac9f 100644
--- a/src/Web/Grand.Web/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web/Controllers/ProductController.cs
@@ -799,9 +799,7 @@ namespace Grand.Web.Controllers
return Content("");
var model = await _mediator.Send(new GetCompareProducts { PictureProductThumbSize = mediaSettings.MiniCartThumbPictureSize });
-
- return View(model);
-
+ return Json(model);
}
diff --git a/src/Web/Grand.Web/Views/Product/CompareProducts.cshtml b/src/Web/Grand.Web/Views/Product/CompareProducts.cshtml
index cafffe011..290588d8d 100644
--- a/src/Web/Grand.Web/Views/Product/CompareProducts.cshtml
+++ b/src/Web/Grand.Web/Views/Product/CompareProducts.cshtml
@@ -22,15 +22,15 @@
<div class="page compare-products-page">
<h2 class="text-center generalTitle">@Loc["Products.Compare.Title"]</h2>
<template v-if="compareproducts !== null && compareproducts.Products.length > 0">
- <a class="btn btn-danger mb-3" @@click="removeFromCompareList(); getCompareList('@Url.RouteUrl("CompareProducts")')">@Loc["Products.Compare.Clear"]</a>
+ <a class="btn btn-danger mb-3" @@click="removeFromCompareList(); ">@Loc["Products.Compare.Clear"]</a>
<div class="table-responsive">
<table class="table table-hover compare-products-table table-bordered">
<tbody>
<tr class="remove-product">
<td class="empty">&nbsp;</td>
- <template v-for="product in compareproducts.Products">
+ <template v-for="(product, key) in compareproducts.Products">
<td class="same-width">
- <button type="button" title="@Loc["Common.Remove"]" class="btn btn-sm btn-link remove-button d-flex align-items-center justify-content-center" @@click="removeFromCompareList(product.Id); getCompareList('@Url.RouteUrl("CompareProducts")')">
+ <button type="button" title="@Loc["Common.Remove"]" class="btn btn-sm btn-link remove-button d-flex align-items-center justify-content-center" @@click="removeFromCompareList(product, key);">
<b-icon icon="trash" variant="danger" aria-hidden="true"></b-icon>
</button>
</td>
diff --git a/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml b/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
index 02d1b550c..98caad362 100644
--- a/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
+++ b/src/Web/Grand.Web/Views/Shared/Partials/SidebarCompareProducts.cshtml
@@ -30,7 +30,7 @@
<div class="price"><span>@Loc["Wishlist.Mini.UnitPrice"]:</span> <strong>{{product.ProductPrice.Price}}</strong></div>
</div>
<div>
- <a class="deleteitem" @@click="removeFromCompareList(product.Id); getCompareList('@Url.RouteUrl("CompareProducts")'); ">
+ <a class="deleteitem" @@click="removeFromCompareList(product.Id); getCompareList('@Url.RouteUrl("SidebarCompareProducts")'); ">
<b-icon icon="trash" variant="danger"></b-icon>
</a>
</div>
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/app.js b/src/Web/Grand.Web/wwwroot/theme/script/app.js
index fcf2a687a..e9627dbe2 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/app.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/app.js
@@ -270,8 +270,7 @@ var vm = new Vue({
data: null,
headers: {
'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-Response-View': 'Json'
+ 'Content-Type': 'application/json'
},
showLoader: false
}).then(response => (
@@ -309,8 +308,7 @@ var vm = new Vue({
data: null,
headers: {
'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-Response-View': 'Json'
+ 'Content-Type': 'application/json'
},
showLoader: false
}).then(response => {
@@ -318,14 +316,15 @@ var vm = new Vue({
this.compareproducts = response.data
})
},
- removeFromCompareList: function (id) {
- if (id !== undefined) {
+ removeFromCompareList: function (product, index) {
+ if (product !== undefined) {
const compareList = AxiosCart.getCookie('Grand.CompareProduct');
- const newCompareList = compareList.replace(id, '');
-
+ const newCompareList = compareList.replace(product.Id, '');
AxiosCart.setCookie('Grand.CompareProduct', newCompareList);
+ vm.compareproducts.Products.splice(index, 1);
} else {
AxiosCart.setCookie('Grand.CompareProduct', '');
+ vm.compareproducts.Products.splice(0);
}
this.updateCompareProductsQty();
},