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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Refactoring - further improvements
KrzysztofPajak0495e6e18e6c
diff --git a/src/Business/Grand.Business.Checkout/Interfaces/Shipping/IShipmentService.cs b/src/Business/Grand.Business.Checkout/Interfaces/Shipping/IShipmentService.csindex ead67ef93..399ddfe84 100644--- a/src/Business/Grand.Business.Checkout/Interfaces/Shipping/IShipmentService.cs+++ b/src/Business/Grand.Business.Checkout/Interfaces/Shipping/IShipmentService.cs@@ -72,18 +72,6 @@ namespace Grand.Business.Checkout.Interfaces.Shipping/// <param name="shipment">Shipment</param>Task DeleteShipment(Shipment shipment);- /// <summary>- /// Get quantity in shipments. For example, get planned quantity to be shipped- /// </summary>- /// <param name="product">Product</param>- /// <param name="customAttribute">Custom Attribute</param>- /// <param name="warehouseId">Warehouse identifier</param>- /// <param name="ignoreShipped">Ignore already shipped shipments</param>- /// <param name="ignoreDelivered">Ignore already delivered shipments</param>- /// <returns>Quantity</returns>- Task<int> GetQuantityInShipments(Product product, IList<CustomAttribute> customAttribute, string warehouseId,- bool ignoreShipped, bool ignoreDelivered);-#region Shipment notes/// <summary>diff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.csindex da6efe471..4e45bf214 100644--- a/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs+++ b/src/Business/Grand.Business.Checkout/Services/Shipping/ShipmentService.cs@@ -1,10 +1,8 @@using Grand.Business.Checkout.Interfaces.Shipping;-using Grand.Infrastructure.Extensions;using Grand.Domain;-using Grand.Domain.Catalog;-using Grand.Domain.Common;using Grand.Domain.Data;using Grand.Domain.Shipping;+using Grand.Infrastructure.Extensions;using MediatR;using System;using System.Collections.Generic;@@ -186,49 +184,6 @@ namespace Grand.Business.Checkout.Services.Shippingawait _mediator.EntityDeleted(shipment);}- /// <summary>- /// Get quantity in shipments. For example, get planned quantity to be shipped- /// </summary>- /// <param name="product">Product</param>- /// <param name="customAttributes">Attributes</param>- /// <param name="warehouseId">Warehouse identifier</param>- /// <param name="ignoreShipped">Ignore already shipped shipments</param>- /// <param name="ignoreDelivered">Ignore already delivered shipments</param>- /// <returns>Quantity</returns>- public virtual async Task<int> GetQuantityInShipments(Product product, IList<CustomAttribute> customAttributes, string warehouseId,- bool ignoreShipped, bool ignoreDelivered)- {- if (product == null)- throw new ArgumentNullException(nameof(product));-- //only products with "use multiple warehouses" are handled this way- if (product.ManageInventoryMethodId == ManageInventoryMethod.DontManageStock)- return 0;- if (!product.UseMultipleWarehouses)- return 0;-- var query = from p in _shipmentRepository.Table- select p;-- if (!String.IsNullOrEmpty(warehouseId))- query = query.Where(si => si.ShipmentItems.Any(x => x.WarehouseId == warehouseId));- if (ignoreShipped)- query = query.Where(si => !si.ShippedDateUtc.HasValue);- if (ignoreDelivered)- query = query.Where(si => !si.DeliveryDateUtc.HasValue);-- query = query.Where(si => si.ShipmentItems.Any(x => x.ProductId == product.Id));- if (customAttributes != null && customAttributes.Any())- query = query.Where(si => si.ShipmentItems.Any(x => x.Attributes == customAttributes));-- var result = query.SelectMany(x => x.ShipmentItems).Where(x => x.ProductId == product.Id);- if (!String.IsNullOrEmpty(warehouseId))- result = result.Where(x => x.WarehouseId == warehouseId);-- return await Task.FromResult(result.Sum(x => x.Quantity));-- }-#region Shipment notes/// <summary>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/AttributeCombinationPopup.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/AttributeCombinationPopup.cshtmlindex 5ad055480..d1625d123 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/AttributeCombinationPopup.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/AttributeCombinationPopup.cshtml@@ -116,9 +116,6 @@<th align="center">@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.ReservedQuantity"]</th>- <th align="center">- @Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.PlannedQuantity"]- </th></tr></thead><tbody>@@ -143,9 +140,7 @@<td align="center" style="width: 20%;"><admin-input asp-for="@Model.WarehouseInventoryModels[i].ReservedQuantity" /></td>- <td align="center" style="width: 20%;">- @item.PlannedQuantity- </td>+</tr>}</tbody>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Inventory.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Inventory.cshtmlindex 82975c4d9..2d7caa0aa 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Inventory.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Product/_CreateOrUpdate.Inventory.cshtml@@ -49,9 +49,6 @@<th align="center">@Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.ReservedQuantity"]</th>- <th align="center">- @Loc["Admin.Catalog.Products.ProductWarehouseInventory.Fields.PlannedQuantity"]- </th></tr></thead><tbody>@@ -76,9 +73,7 @@<td align="center" style="width: 20%;"><admin-input asp-for="@Model.ProductWarehouseInventoryModels[i].ReservedQuantity" /></td>- <td align="center" style="width: 10%;">- @item.PlannedQuantity- </td>+</tr>}</tbody>diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtmlindex da46f9e89..633cc0426 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shipment/AddShipment.cshtml@@ -176,9 +176,8 @@var selected = warehouse.WarehouseId == item.WarehouseId ? true : false;<option value="@(warehouse.WarehouseId)" data-stock-qty="@(warehouse.StockQuantity)"data-reserved-qty="@(warehouse.ReservedQuantity)"- data-planned-qty="@(warehouse.PlannedQuantity)"selected="@selected">- @Loc["Admin.Orders.Shipments.Products.Warehouse.ChooseQty", warehouse.WarehouseName, warehouse.StockQuantity, warehouse.ReservedQuantity, warehouse.PlannedQuantity]+ @Loc["Admin.Orders.Shipments.Products.Warehouse.ChooseQty", warehouse.WarehouseName, warehouse.StockQuantity, warehouse.ReservedQuantity]</option>}</select>diff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.csindex 19c5a2966..d55dca93a 100644--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductAttributeCombinationModel.cs@@ -102,9 +102,6 @@ namespace Grand.Web.Admin.Models.Catalog[GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.AttributeCombination.WarehouseInventory.Fields.ReservedQuantity")]public int ReservedQuantity { get; set; }-- [GrandResourceDisplayName("Admin.Catalog.Products.ProductAttributes.AttributeCombination.WarehouseInventory.Fields.PlannedQuantity")]- public int PlannedQuantity { get; set; }}#endregiondiff --git a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.csindex 64ec0e93a..90949cd2b 100644--- a/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Catalog/ProductModel.cs@@ -854,8 +854,6 @@ namespace Grand.Web.Admin.Models.Catalog[GrandResourceDisplayName("Admin.Catalog.Products.ProductWarehouseInventory.Fields.ReservedQuantity")]public int ReservedQuantity { get; set; }- [GrandResourceDisplayName("Admin.Catalog.Products.ProductWarehouseInventory.Fields.PlannedQuantity")]- public int PlannedQuantity { get; set; }}public partial class ReservationModel : BaseEntityModel{diff --git a/src/Web/Grand.Web.Admin/Models/Orders/ShipmentModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/ShipmentModel.csindex 936c5dcf2..2011db12c 100644--- a/src/Web/Grand.Web.Admin/Models/Orders/ShipmentModel.cs+++ b/src/Web/Grand.Web.Admin/Models/Orders/ShipmentModel.cs@@ -99,7 +99,6 @@ namespace Grand.Web.Admin.Models.Orderspublic string WarehouseName { get; set; }public int StockQuantity { get; set; }public int ReservedQuantity { get; set; }- public int PlannedQuantity { get; set; }}#endregiondiff --git a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.csindex 3481967f7..33b476622 100644--- a/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ProductViewModelService.cs@@ -59,7 +59,6 @@ namespace Grand.Web.Admin.Servicesprivate readonly IWorkContext _workContext;private readonly IGroupService _groupService;private readonly IWarehouseService _warehouseService;- private readonly IShipmentService _shipmentService;private readonly IDeliveryDateService _deliveryDateService;private readonly ITaxCategoryService _taxCategoryService;private readonly IDiscountService _discountService;@@ -99,7 +98,6 @@ namespace Grand.Web.Admin.ServicesIGroupService groupService,IWarehouseService warehouseService,IDeliveryDateService deliveryDateService,- IShipmentService shipmentService,ITaxCategoryService taxCategoryService,IDiscountService discountService,ICustomerService customerService,@@ -137,7 +135,6 @@ namespace Grand.Web.Admin.Services_groupService = groupService;_warehouseService = warehouseService;_deliveryDateService = deliveryDateService;- _shipmentService = shipmentService;_taxCategoryService = taxCategoryService;_discountService = discountService;_customerService = customerService;@@ -558,7 +555,6 @@ namespace Grand.Web.Admin.ServicespwiModel.WarehouseUsed = true;pwiModel.StockQuantity = pwi.StockQuantity;pwiModel.ReservedQuantity = pwi.ReservedQuantity;- pwiModel.PlannedQuantity = await _shipmentService.GetQuantityInShipments(product, null, pwi.WarehouseId, true, true);}}model.ProductWarehouseInventoryModels.Add(pwiModel);@@ -2528,7 +2524,6 @@ namespace Grand.Web.Admin.ServiceswarehouseInventoryModel.Id = _winv.Id;warehouseInventoryModel.StockQuantity = _winv.StockQuantity;warehouseInventoryModel.ReservedQuantity = _winv.ReservedQuantity;- warehouseInventoryModel.PlannedQuantity = await _shipmentService.GetQuantityInShipments(product, combination.Attributes, _winv.WarehouseId, true, true);}}}diff --git a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.csindex 4d94ded39..2f241419b 100644--- a/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs+++ b/src/Web/Grand.Web.Admin/Services/ShipmentViewModelService.cs@@ -421,8 +421,7 @@ namespace Grand.Web.Admin.ServicesWarehouseId = warehouse.Id,WarehouseName = warehouse.Name,StockQuantity = pwi.StockQuantity,- ReservedQuantity = pwi.ReservedQuantity,- PlannedQuantity = await _shipmentService.GetQuantityInShipments(product, orderItem.Attributes, warehouse.Id, true, true)+ ReservedQuantity = pwi.ReservedQuantity});}}@@ -464,8 +463,7 @@ namespace Grand.Web.Admin.ServicesWarehouseId = warehouse.Id,WarehouseName = warehouse.Name,StockQuantity = pwi.StockQuantity,- ReservedQuantity = pwi.ReservedQuantity,- PlannedQuantity = await _shipmentService.GetQuantityInShipments(product, orderItem.Attributes, warehouse.Id, true, true)+ ReservedQuantity = pwi.ReservedQuantity});}}@@ -499,8 +497,7 @@ namespace Grand.Web.Admin.ServicesWarehouseId = warehouse.Id,WarehouseName = warehouse.Name,StockQuantity = await GetStockQty(product, orderItem.WarehouseId),- ReservedQuantity = await GetReservedQty(product, orderItem.WarehouseId),- PlannedQuantity = await GetPlannedQty(product, orderItem.WarehouseId)+ ReservedQuantity = await GetReservedQty(product, orderItem.WarehouseId)});}}@@ -518,7 +515,6 @@ namespace Grand.Web.Admin.ServicesWarehouseName = warehouse.Name,StockQuantity = await GetStockQty(product, warehouse.Id),ReservedQuantity = await GetReservedQty(product, warehouse.Id),- PlannedQuantity = await GetPlannedQty(product, warehouse.Id)});}}diff --git a/src/Web/Grand.Web.Common/Localization/LocService.cs b/src/Web/Grand.Web.Common/Localization/LocService.csindex e599c2294..8639f12b1 100644--- a/src/Web/Grand.Web.Common/Localization/LocService.cs+++ b/src/Web/Grand.Web.Common/Localization/LocService.cs@@ -34,8 +34,15 @@ namespace Grand.Web.Common.Localization{return new LocalizedString(name, resFormat, resFormat == null);}- return new LocalizedString(name, string.Format(resFormat, arguments),- resFormat == null);+ try+ {+ return new LocalizedString(name, string.Format(resFormat, arguments),+ resFormat == null);+ }+ catch+ {+ return new LocalizedString(name, resFormat, resFormat == null);+ }}}}diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xmlindex a40426897..43674f8c9 100644--- a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml+++ b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml@@ -3573,9 +3573,6 @@<Resource Name="Admin.Catalog.Products.ProductWarehouseInventory.Description3"><Value>"Planned qty" is product quantity that is ordered and already added to a shipment but not shipped yet.</Value></Resource>- <Resource Name="Admin.Catalog.Products.ProductWarehouseInventory.Fields.PlannedQuantity">- <Value>Planned qty</Value>- </Resource><Resource Name="Admin.Catalog.Products.ProductWarehouseInventory.Fields.ReservedQuantity"><Value>Reserved qty</Value></Resource>@@ -9617,7 +9614,7 @@<Value>Warehouse</Value></Resource><Resource Name="Admin.Orders.Shipments.Products.Warehouse.ChooseQty">- <Value>{0} ({1} qty in stock, {2} qty reserved, {3} qty planned)</Value>+ <Value>{0} ({1} qty in stock, {2} qty reserved</Value></Resource><Resource Name="Admin.Orders.Shipments.Products.Warehouse.NotAvailabe"><Value>No warehouses available. You cannot ship this product.</Value>