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.

Shipping by weight - further improvements

KrzysztofPajak35e6f7f30f34
diff --git a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingService.cs b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingService.cs
index 5976c0e3d..71d09f4cf 100644
--- a/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingService.cs
+++ b/src/Business/Grand.Business.Checkout/Services/Shipping/ShippingService.cs
@@ -124,14 +124,15 @@ namespace Grand.Business.Checkout.Services.Shipping
public virtual async Task<GetShippingOptionRequest> CreateShippingOptionRequests(Customer customer,
IList<ShoppingCartItem> cart, Address shippingAddress, Store store)
{
- var request = new GetShippingOptionRequest();
- //store
- request.StoreId = store?.Id;
- //customer
- request.Customer = customer;
-
- //ship to
- request.ShippingAddress = shippingAddress;
+ var request = new GetShippingOptionRequest {
+ //store
+ StoreId = store?.Id,
+ //customer
+ Customer = customer,
+
+ //ship to
+ ShippingAddress = shippingAddress
+ };
//ship from
Address originAddress = _shippingSettings.ShippingOriginAddress;
diff --git a/src/Plugins/Shipping.ByWeight/Services/ShippingByWeightService.cs b/src/Plugins/Shipping.ByWeight/Services/ShippingByWeightService.cs
index 914032f99..4df82068b 100644
--- a/src/Plugins/Shipping.ByWeight/Services/ShippingByWeightService.cs
+++ b/src/Plugins/Shipping.ByWeight/Services/ShippingByWeightService.cs
@@ -66,27 +66,34 @@ namespace Shipping.ByWeight.Services
zip = string.Empty;
zip = zip.Trim();
- //filter by weight and shipping method
var existingRates = (await GetAll())
.Where(sbw => sbw.ShippingMethodId == shippingMethodId && weight >= sbw.From && weight <= sbw.To)
.ToList();
if (!string.IsNullOrEmpty(warehouseId))
- existingRates = existingRates.Where(x => x.WarehouseId == warehouseId).ToList();
- else
- existingRates = existingRates.Where(x => string.IsNullOrEmpty(x.WarehouseId)).ToList();
+ existingRates = existingRates.Where(x => x.WarehouseId == warehouseId).Any()
+ ? existingRates.Where(x => x.WarehouseId == warehouseId).ToList()
+ : existingRates.Where(x => string.IsNullOrEmpty(x.WarehouseId)).ToList();
if (!string.IsNullOrEmpty(storeId))
- existingRates = existingRates.Where(x => x.StoreId == storeId || string.IsNullOrEmpty(x.StoreId)).ToList();
-
+ existingRates = existingRates.Where(x => x.StoreId == storeId).Any()
+ ? existingRates.Where(x => x.StoreId == storeId).ToList()
+ : existingRates.Where(x => string.IsNullOrEmpty(x.StoreId)).ToList();
+
if (!string.IsNullOrEmpty(countryId))
- existingRates = existingRates.Where(x => x.CountryId == countryId || string.IsNullOrEmpty(x.CountryId)).ToList();
+ existingRates = existingRates.Where(x => x.CountryId == countryId).Any()
+ ? existingRates.Where(x => x.CountryId == countryId).ToList()
+ : existingRates.Where(x => string.IsNullOrEmpty(x.CountryId)).ToList();
if (!string.IsNullOrEmpty(stateProvinceId))
- existingRates = existingRates.Where(x => x.StateProvinceId == stateProvinceId || string.IsNullOrEmpty(x.StateProvinceId)).ToList();
+ existingRates = existingRates.Where(x => x.StateProvinceId == stateProvinceId).Any()
+ ? existingRates.Where(x => x.StateProvinceId == stateProvinceId).ToList()
+ : existingRates.Where(x => string.IsNullOrEmpty(x.StateProvinceId)).ToList();
if (!string.IsNullOrEmpty(zip))
- existingRates = existingRates.Where(x => x.Zip == zip || string.IsNullOrEmpty(x.Zip)).ToList();
+ existingRates = existingRates.Where(x => x.Zip == zip).Any()
+ ? existingRates.Where(x => x.Zip == zip).ToList()
+ : existingRates.Where(x => string.IsNullOrEmpty(x.Zip)).ToList();
return existingRates.FirstOrDefault();