From cfeea9a5a22a1fb8f17a9697ea5474025f6c5275 Mon Sep 17 00:00:00 2001 From: Lurvy Date: Wed, 3 Aug 2022 23:26:24 +0800 Subject: [PATCH 1/3] Fixed the product changed warning when save product after modified attribute combination --- ...Attributes.TabAttributeCombinations.cshtml | 57 +++++++++++++------ .../Controllers/ProductController.cs | 3 +- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.ProductAttributes.TabAttributeCombinations.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.ProductAttributes.TabAttributeCombinations.cshtml index 66278289c..869dc3ec0 100644 --- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.ProductAttributes.TabAttributeCombinations.cshtml +++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.ProductAttributes.TabAttributeCombinations.cshtml @@ -55,23 +55,48 @@ }, dataSource: { transport: { - read: { - url: "@Html.Raw(Url.Action("ProductAttributeCombinationList", "Product", new { productId = Model.Id, area = Constants.AreaAdmin }))", - type: "POST", - dataType: "json", - data: addAntiForgeryToken + read: function(options) { + $.ajax({ + url: "@Html.Raw(Url.Action("ProductAttributeCombinationList", "Product", new { productId = Model.Id, area = Constants.AreaAdmin }))", + type: "POST", + dataType: "json", + data: addAntiForgeryToken(options.data), + success: function(result) { + options.success(result); + $('input[name="Ticks"]').val(result.ExtraData.ProductTicks); + }, + error: function(result) { + options.error(result); + } + }); }, - update: { - url: "@Html.Raw(Url.Action("ProductAttributeCombinationUpdate", "Product", new { area = Constants.AreaAdmin }))", - type: "POST", - dataType: "json", - data: addAntiForgeryToken + update: function(options) { + $.ajax({ + url: "@Html.Raw(Url.Action("ProductAttributeCombinationUpdate", "Product", new { area = Constants.AreaAdmin }))", + type: "POST", + dataType: "json", + data: addAntiForgeryToken(options.data), + success: function(result) { + options.success(result); + }, + error: function(result) { + options.error(result); + } + }); }, - destroy: { - url: "@Html.Raw(Url.Action("ProductAttributeCombinationDelete", "Product", new { area = Constants.AreaAdmin }))", - type: "POST", - dataType: "json", - data: addAntiForgeryToken + destroy: function(options) { + $.ajax({ + url: "@Html.Raw(Url.Action("ProductAttributeCombinationDelete", "Product", new { area = Constants.AreaAdmin }))", + type: "POST", + dataType: "json", + data: addAntiForgeryToken(options.data), + success: function(result) { + options.success(result); + }, + error: function(result) { + options.error(result); + } + }); } }, schema: { @@ -95,7 +120,7 @@ } }, requestEnd: function(e) { - if (e.type == "update") { + if (e.type == "update" || e.type == "destroy") { this.read(); } }, diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs index 4cb677459..24a19b34b 100644 --- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs +++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs @@ -2344,7 +2344,8 @@ public async Task ProductAttributeCombinationList(DataSourceReque var combinationsModel = await _productViewModelService.PrepareProductAttributeCombinationModel(product); var gridModel = new DataSourceResult { Data = combinationsModel, - Total = combinationsModel.Count + Total = combinationsModel.Count, + ExtraData = new { ProductTicks = product.UpdatedOnUtc.Ticks.ToString() } }; return Json(gridModel); } From 74384621167f75065fca11fbc492bb7ca54d37b3 Mon Sep 17 00:00:00 2001 From: Lurvy Date: Sat, 6 Aug 2022 13:20:29 +0800 Subject: [PATCH 2/3] Complete fixed the product changed warning when save product after delete attribute combination --- src/Web/Grand.Web.Admin/Controllers/ProductController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs index 24a19b34b..76b60663e 100644 --- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs +++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs @@ -2373,7 +2373,7 @@ public async Task ProductAttributeCombinationDelete(string id, st await productAttributeService.DeleteProductAttributeCombination(combination, productId); if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes) { - var pr = await _productService.GetProductById(productId); + var pr = await _productService.GetProductById(productId, true); pr.StockQuantity = pr.ProductAttributeCombinations.Sum(x => x.StockQuantity); pr.ReservedQuantity = pr.ProductAttributeCombinations.Sum(x => x.ReservedQuantity); await _inventoryManageService.UpdateStockProduct(pr, false); From 22d7ee78a54539d554d9e3a1b143f39f746611c3 Mon Sep 17 00:00:00 2001 From: Lurvy Date: Tue, 9 Aug 2022 21:55:12 +0800 Subject: [PATCH 3/3] Fixed product cache issue: same as delete attribute combination, change attribute combination stock quantity will also write and clear the product cache frequently in a short period of time, that will cause cache can't clear --- src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs index 538393512..a8491a64e 100644 --- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs +++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs @@ -2545,7 +2545,7 @@ async Task PrepareCombinationWarehouseInventory(ProductAttributeCombination comb if (product.ManageInventoryMethodId == ManageInventoryMethod.ManageStockByAttributes) { - var pr = await _productService.GetProductById(model.ProductId); + var pr = await _productService.GetProductById(model.ProductId, true); pr.StockQuantity = pr.ProductAttributeCombinations.Sum(x => x.StockQuantity); pr.ReservedQuantity = pr.ProductAttributeCombinations.Sum(x => x.ReservedQuantity); await _inventoryManageService.UpdateStockProduct(pr, false);