Skip to content

Commit 93bcb4d

Browse files
Move allowed country restore to before pricing restore
1 parent ab3df30 commit 93bcb4d

File tree

2 files changed

+76
-74
lines changed

2 files changed

+76
-74
lines changed

src/Umbraco.Commerce.Deploy/Connectors/ServiceConnectors/UmbracoCommercePaymentMethodServiceConnector.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,45 @@ private Task Pass4Async(ArtifactDeployState<PaymentMethodArtifact, PaymentMethod
247247
entity.ClearTaxClass();
248248
}
249249

250+
// AllowedCountryRegions
251+
var allowedCountryRegionsToRemove = entity.AllowedCountryRegions
252+
.Where(x => artifact.AllowedCountryRegions == null || !artifact.AllowedCountryRegions.Any(y => y.CountryUdi.Guid == x.CountryId
253+
&& y.RegionUdi?.Guid == x.RegionId))
254+
.ToList();
255+
256+
if (artifact.AllowedCountryRegions != null)
257+
{
258+
foreach (AllowedCountryRegionArtifact acr in artifact.AllowedCountryRegions)
259+
{
260+
acr.CountryUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Country);
261+
262+
if (acr.RegionUdi != null)
263+
{
264+
acr.RegionUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Region);
265+
266+
entity.AllowInRegion(acr.CountryUdi.Guid, acr.RegionUdi.Guid);
267+
}
268+
else
269+
{
270+
entity.AllowInCountry(acr.CountryUdi.Guid);
271+
}
272+
}
273+
}
274+
275+
foreach (AllowedCountryRegion? acr in allowedCountryRegionsToRemove)
276+
{
277+
if (acr.RegionId != null)
278+
{
279+
entity.DisallowInRegion(acr.CountryId, acr.RegionId.Value);
280+
}
281+
else
282+
{
283+
entity.DisallowInCountry(acr.CountryId);
284+
}
285+
}
286+
250287
// Prices
288+
// Must come after AllowedCountryRegions as it may be affected by them
251289
var pricesToRemove = entity.Prices
252290
.Where(x => artifact.Prices == null || !artifact.Prices.Any(y => y.CountryUdi?.Guid == x.CountryId
253291
&& y.RegionUdi?.Guid == x.RegionId
@@ -298,43 +336,6 @@ private Task Pass4Async(ArtifactDeployState<PaymentMethodArtifact, PaymentMethod
298336
}
299337
}
300338

301-
// AllowedCountryRegions
302-
var allowedCountryRegionsToRemove = entity.AllowedCountryRegions
303-
.Where(x => artifact.AllowedCountryRegions == null || !artifact.AllowedCountryRegions.Any(y => y.CountryUdi.Guid == x.CountryId
304-
&& y.RegionUdi?.Guid == x.RegionId))
305-
.ToList();
306-
307-
if (artifact.AllowedCountryRegions != null)
308-
{
309-
foreach (AllowedCountryRegionArtifact acr in artifact.AllowedCountryRegions)
310-
{
311-
acr.CountryUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Country);
312-
313-
if (acr.RegionUdi != null)
314-
{
315-
acr.RegionUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Region);
316-
317-
entity.AllowInRegion(acr.CountryUdi.Guid, acr.RegionUdi.Guid);
318-
}
319-
else
320-
{
321-
entity.AllowInCountry(acr.CountryUdi.Guid);
322-
}
323-
}
324-
}
325-
326-
foreach (AllowedCountryRegion? acr in allowedCountryRegionsToRemove)
327-
{
328-
if (acr.RegionId != null)
329-
{
330-
entity.DisallowInRegion(acr.CountryId, acr.RegionId.Value);
331-
}
332-
else
333-
{
334-
entity.DisallowInCountry(acr.CountryId);
335-
}
336-
}
337-
338339
_umbracoCommerceApi.SavePaymentMethod(entity);
339340
}
340341

src/Umbraco.Commerce.Deploy/Connectors/ServiceConnectors/UmbracoCommerceShippingMethodServiceConnector.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,45 @@ private Task Pass4Async(ArtifactDeployState<ShippingMethodArtifact, ShippingMeth
266266
entity.ClearTaxClass();
267267
}
268268

269+
// AllowedCountryRegions
270+
var allowedCountryRegionsToRemove = entity.AllowedCountryRegions
271+
.Where(x => artifact.AllowedCountryRegions == null || !artifact.AllowedCountryRegions.Any(y => y.CountryUdi.Guid == x.CountryId
272+
&& y.RegionUdi?.Guid == x.RegionId))
273+
.ToList();
274+
275+
if (artifact.AllowedCountryRegions != null)
276+
{
277+
foreach (AllowedCountryRegionArtifact acr in artifact.AllowedCountryRegions)
278+
{
279+
acr.CountryUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Country);
280+
281+
if (acr.RegionUdi != null)
282+
{
283+
acr.RegionUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Region);
284+
285+
entity.AllowInRegion(acr.CountryUdi.Guid, acr.RegionUdi.Guid);
286+
}
287+
else
288+
{
289+
entity.AllowInCountry(acr.CountryUdi.Guid);
290+
}
291+
}
292+
}
293+
294+
foreach (AllowedCountryRegion? acr in allowedCountryRegionsToRemove)
295+
{
296+
if (acr.RegionId != null)
297+
{
298+
entity.DisallowInRegion(acr.CountryId, acr.RegionId.Value);
299+
}
300+
else
301+
{
302+
entity.DisallowInCountry(acr.CountryId);
303+
}
304+
}
305+
269306
// Calculation config
307+
// Must come after AllowedCountryRegions as it may depend on them
270308
if (artifact.CalculationConfig != null)
271309
{
272310
if (artifact.CalculationMode == (int)ShippingCalculationMode.Fixed)
@@ -308,43 +346,6 @@ private Task Pass4Async(ArtifactDeployState<ShippingMethodArtifact, ShippingMeth
308346
}
309347
}
310348

311-
// AllowedCountryRegions
312-
var allowedCountryRegionsToRemove = entity.AllowedCountryRegions
313-
.Where(x => artifact.AllowedCountryRegions == null || !artifact.AllowedCountryRegions.Any(y => y.CountryUdi.Guid == x.CountryId
314-
&& y.RegionUdi?.Guid == x.RegionId))
315-
.ToList();
316-
317-
if (artifact.AllowedCountryRegions != null)
318-
{
319-
foreach (AllowedCountryRegionArtifact acr in artifact.AllowedCountryRegions)
320-
{
321-
acr.CountryUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Country);
322-
323-
if (acr.RegionUdi != null)
324-
{
325-
acr.RegionUdi.EnsureType(UmbracoCommerceConstants.UdiEntityType.Region);
326-
327-
entity.AllowInRegion(acr.CountryUdi.Guid, acr.RegionUdi.Guid);
328-
}
329-
else
330-
{
331-
entity.AllowInCountry(acr.CountryUdi.Guid);
332-
}
333-
}
334-
}
335-
336-
foreach (AllowedCountryRegion? acr in allowedCountryRegionsToRemove)
337-
{
338-
if (acr.RegionId != null)
339-
{
340-
entity.DisallowInRegion(acr.CountryId, acr.RegionId.Value);
341-
}
342-
else
343-
{
344-
entity.DisallowInCountry(acr.CountryId);
345-
}
346-
}
347-
348349
_umbracoCommerceApi.SaveShippingMethod(entity);
349350
}
350351

0 commit comments

Comments
 (0)