From 1272a878c386fc5b7310e1ca70d2f59bed97901c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Mon, 19 Jun 2023 20:30:18 +0200 Subject: [PATCH] OCC-160: Upgrade to Orchard Core 1.6 (#308) * Updating Orchard Core versions and other NuGet packages related to Orchard Core. * Adding interface implementation * Changing parameter name instance to part in order to match the identifier * Updating Ids * Updating Ids * Using queryselector instead of specific id selector --- .../OrchardCore.Commerce.ContentFields.csproj | 6 ++--- .../OrchardCore.Commerce.Inventory.csproj | 8 +++---- .../OrchardCore.Commerce.Promotion.csproj | 4 ++-- .../OrchardCore.Commerce.Tax.csproj | 4 ++-- .../Assets/Scripts/toggle-second-address.js | 8 +++---- .../Handlers/DiscountPartHandler.cs | 8 +++---- .../Handlers/PricePartHandler.cs | 16 +++++++------- .../Handlers/PriceVariantsPartHandler.cs | 10 ++++----- .../Handlers/SkuValidationHandler.cs | 12 +++++----- .../Handlers/TaxPartAndPricePartHandler.cs | 6 ++--- .../OrchardCore.Commerce.csproj | 22 +++++++++---------- .../OrchardCore.Commerce.Web.csproj | 6 ++--- ...ardCore.Commerce.Tests.UI.Shortcuts.csproj | 8 +++---- .../OrchardCore.Commerce.Tests.UI.csproj | 4 ++-- .../Tests/UserTests/UserPersistenceTests.cs | 6 ++--- .../Fakes/FakeContentManager.cs | 3 +++ .../OrchardCore.Commerce.Tests.csproj | 2 +- 17 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/Modules/OrchardCore.Commerce.ContentFields/OrchardCore.Commerce.ContentFields.csproj b/src/Modules/OrchardCore.Commerce.ContentFields/OrchardCore.Commerce.ContentFields.csproj index 9073e1c43..6425607b1 100644 --- a/src/Modules/OrchardCore.Commerce.ContentFields/OrchardCore.Commerce.ContentFields.csproj +++ b/src/Modules/OrchardCore.Commerce.ContentFields/OrchardCore.Commerce.ContentFields.csproj @@ -22,8 +22,8 @@ - - + + @@ -44,7 +44,7 @@ - + diff --git a/src/Modules/OrchardCore.Commerce.Inventory/OrchardCore.Commerce.Inventory.csproj b/src/Modules/OrchardCore.Commerce.Inventory/OrchardCore.Commerce.Inventory.csproj index d4b6be373..33eb4fddb 100644 --- a/src/Modules/OrchardCore.Commerce.Inventory/OrchardCore.Commerce.Inventory.csproj +++ b/src/Modules/OrchardCore.Commerce.Inventory/OrchardCore.Commerce.Inventory.csproj @@ -28,9 +28,9 @@ - - - + + + @@ -41,7 +41,7 @@ - + diff --git a/src/Modules/OrchardCore.Commerce.Promotion/OrchardCore.Commerce.Promotion.csproj b/src/Modules/OrchardCore.Commerce.Promotion/OrchardCore.Commerce.Promotion.csproj index b6437e29e..c7bbfee7a 100644 --- a/src/Modules/OrchardCore.Commerce.Promotion/OrchardCore.Commerce.Promotion.csproj +++ b/src/Modules/OrchardCore.Commerce.Promotion/OrchardCore.Commerce.Promotion.csproj @@ -22,8 +22,8 @@ - - + + diff --git a/src/Modules/OrchardCore.Commerce.Tax/OrchardCore.Commerce.Tax.csproj b/src/Modules/OrchardCore.Commerce.Tax/OrchardCore.Commerce.Tax.csproj index 06fe0f790..ca8ffec13 100644 --- a/src/Modules/OrchardCore.Commerce.Tax/OrchardCore.Commerce.Tax.csproj +++ b/src/Modules/OrchardCore.Commerce.Tax/OrchardCore.Commerce.Tax.csproj @@ -22,8 +22,8 @@ - - + + diff --git a/src/Modules/OrchardCore.Commerce/Assets/Scripts/toggle-second-address.js b/src/Modules/OrchardCore.Commerce/Assets/Scripts/toggle-second-address.js index 6bc4669f7..62dacff4f 100644 --- a/src/Modules/OrchardCore.Commerce/Assets/Scripts/toggle-second-address.js +++ b/src/Modules/OrchardCore.Commerce/Assets/Scripts/toggle-second-address.js @@ -38,16 +38,16 @@ window.initializeToggleSecondAddress = function ( }; (function autoInitializeToggleSecondAddress() { - if (document.getElementById('UserAddressesPart_BillingAndShippingAddressesMatch_Value')) { + if (document.querySelector('[id$=UserAddressesPart_BillingAndShippingAddressesMatch_Value]')) { initializeToggleSecondAddress( - document.getElementById('UserAddressesPart_BillingAndShippingAddressesMatch_Value'), + document.querySelector('[id$=UserAddressesPart_BillingAndShippingAddressesMatch_Value]'), document.querySelector('.address_billing-address'), document.querySelector('.address_shipping-address')); } - if (document.getElementById('OrderPart_BillingAndShippingAddressesMatch_Value')) { + if (document.querySelector('[id$=OrderPart_BillingAndShippingAddressesMatch_Value]')) { initializeToggleSecondAddress( - document.getElementById('OrderPart_BillingAndShippingAddressesMatch_Value'), + document.querySelector('[id$=OrderPart_BillingAndShippingAddressesMatch_Value]'), document.querySelector('.address_billing-address'), document.querySelector('.address_shipping-address')); } diff --git a/src/Modules/OrchardCore.Commerce/Handlers/DiscountPartHandler.cs b/src/Modules/OrchardCore.Commerce/Handlers/DiscountPartHandler.cs index 6b988e1b4..ab20f44c8 100644 --- a/src/Modules/OrchardCore.Commerce/Handlers/DiscountPartHandler.cs +++ b/src/Modules/OrchardCore.Commerce/Handlers/DiscountPartHandler.cs @@ -28,9 +28,9 @@ public DiscountPartHandler( T = stringLocalizer; } - public override Task UpdatedAsync(UpdateContentContext context, DiscountPart instance) + public override Task UpdatedAsync(UpdateContentContext context, DiscountPart part) { - if (instance.ContentItem.As() is not { } discountPart) return Task.CompletedTask; + if (part.ContentItem.As() is not { } discountPart) return Task.CompletedTask; var discountPercentage = discountPart.DiscountPercentage?.Value ?? 0; var discountAmount = discountPart.DiscountAmount.Amount; @@ -42,10 +42,10 @@ public override Task UpdatedAsync(UpdateContentContext context, DiscountPart ins InvalidateEvenState(); } - if ((instance.ContentItem.As()?.Price is { } pricePartPrice && + if ((part.ContentItem.As()?.Price is { } pricePartPrice && pricePartPrice.Currency.Equals(discountAmount.Currency) && pricePartPrice < discountAmount) || - (instance.ContentItem.As()?.GrossPrice.Amount is { } taxPartGrossPriceAmount && + (part.ContentItem.As()?.GrossPrice.Amount is { } taxPartGrossPriceAmount && taxPartGrossPriceAmount.IsValid && taxPartGrossPriceAmount.Currency.Equals(discountAmount.Currency) && taxPartGrossPriceAmount < discountAmount)) diff --git a/src/Modules/OrchardCore.Commerce/Handlers/PricePartHandler.cs b/src/Modules/OrchardCore.Commerce/Handlers/PricePartHandler.cs index 807d556ef..8f85a6df1 100644 --- a/src/Modules/OrchardCore.Commerce/Handlers/PricePartHandler.cs +++ b/src/Modules/OrchardCore.Commerce/Handlers/PricePartHandler.cs @@ -19,20 +19,20 @@ public PricePartHandler(IMoneyService moneyService, ISession session) _session = session; } - public override Task LoadingAsync(LoadContentContext context, PricePart instance) + public override Task LoadingAsync(LoadContentContext context, PricePart part) { - var amount = _moneyService.EnsureCurrency(instance.Price); - instance.Price = amount; + var amount = _moneyService.EnsureCurrency(part.Price); + part.Price = amount; // Migrate objects to use PriceField instead of PricePart.Amount. - if (instance.Content.Price is { } price && instance.Content.PriceField?.Amount.ToString() != price.ToString()) + if (part.Content.Price is { } price && part.Content.PriceField?.Amount.ToString() != price.ToString()) { - instance.Content.PriceField = JObject.FromObject(new PriceField { Amount = amount }); - ((JObject)instance.Content).Remove(nameof(PricePart.Price)); + part.Content.PriceField = JObject.FromObject(new PriceField { Amount = amount }); + ((JObject)part.Content).Remove(nameof(PricePart.Price)); - _session.Save(instance.ContentItem); + _session.Save(part.ContentItem); } - return base.LoadingAsync(context, instance); + return base.LoadingAsync(context, part); } } diff --git a/src/Modules/OrchardCore.Commerce/Handlers/PriceVariantsPartHandler.cs b/src/Modules/OrchardCore.Commerce/Handlers/PriceVariantsPartHandler.cs index 196b47652..c9098ead6 100644 --- a/src/Modules/OrchardCore.Commerce/Handlers/PriceVariantsPartHandler.cs +++ b/src/Modules/OrchardCore.Commerce/Handlers/PriceVariantsPartHandler.cs @@ -11,16 +11,16 @@ public class PriceVariantsPartHandler : ContentPartHandler public PriceVariantsPartHandler(IMoneyService moneyService) => _moneyService = moneyService; - public override Task LoadingAsync(LoadContentContext context, PriceVariantsPart instance) + public override Task LoadingAsync(LoadContentContext context, PriceVariantsPart part) { - if (instance.Variants != null) + if (part.Variants != null) { - foreach (var variantKey in instance.Variants.Keys) + foreach (var variantKey in part.Variants.Keys) { - instance.Variants[variantKey] = _moneyService.EnsureCurrency(instance.Variants[variantKey]); + part.Variants[variantKey] = _moneyService.EnsureCurrency(part.Variants[variantKey]); } } - return base.LoadingAsync(context, instance); + return base.LoadingAsync(context, part); } } diff --git a/src/Modules/OrchardCore.Commerce/Handlers/SkuValidationHandler.cs b/src/Modules/OrchardCore.Commerce/Handlers/SkuValidationHandler.cs index 307666830..31c69466c 100644 --- a/src/Modules/OrchardCore.Commerce/Handlers/SkuValidationHandler.cs +++ b/src/Modules/OrchardCore.Commerce/Handlers/SkuValidationHandler.cs @@ -21,24 +21,24 @@ public SkuValidationHandler( _updateModelAccessor = updateModelAccessor; } - public override async Task UpdatedAsync(UpdateContentContext context, ProductPart instance) + public override async Task UpdatedAsync(UpdateContentContext context, ProductPart part) { - if (string.IsNullOrWhiteSpace(instance.Sku)) + if (string.IsNullOrWhiteSpace(part.Sku)) { - _updateModelAccessor.ModelUpdater.ModelState.AddModelError(nameof(instance.Sku), "SKU must not be empty."); + _updateModelAccessor.ModelUpdater.ModelState.AddModelError(nameof(part.Sku), "SKU must not be empty."); return; } var isProductSkuAlreadyExisting = await _session .Query(index => - index.Sku == instance.Sku && - index.ContentItemId != instance.ContentItem.ContentItemId) + index.Sku == part.Sku && + index.ContentItemId != part.ContentItem.ContentItemId) .CountAsync() > 0; if (isProductSkuAlreadyExisting) { _updateModelAccessor.ModelUpdater.ModelState.AddModelError( - nameof(instance.Sku), + nameof(part.Sku), "SKU must be unique. A product with the given SKU already exists."); } } diff --git a/src/Modules/OrchardCore.Commerce/Handlers/TaxPartAndPricePartHandler.cs b/src/Modules/OrchardCore.Commerce/Handlers/TaxPartAndPricePartHandler.cs index a0a1747c7..f0cdd675e 100644 --- a/src/Modules/OrchardCore.Commerce/Handlers/TaxPartAndPricePartHandler.cs +++ b/src/Modules/OrchardCore.Commerce/Handlers/TaxPartAndPricePartHandler.cs @@ -32,9 +32,9 @@ public TaxPartAndPricePartHandler( T = stringLocalizer; } - public override Task UpdatedAsync(UpdateContentContext context, PricePart instance) + public override Task UpdatedAsync(UpdateContentContext context, PricePart part) { - if (instance.ContentItem.As() is not { } taxPart) return Task.CompletedTask; + if (part.ContentItem.As() is not { } taxPart) return Task.CompletedTask; var taxRate = taxPart.TaxRate?.Value ?? 0; @@ -43,7 +43,7 @@ public override Task UpdatedAsync(UpdateContentContext context, PricePart instan if (isGrossPricePresent && isTaxRatePresent) { - UpdatePricePart(instance.ContentItem, taxPart.GrossPrice.Amount, taxRate); + UpdatePricePart(part.ContentItem, taxPart.GrossPrice.Amount, taxRate); } else if (isGrossPricePresent ^ isTaxRatePresent) { diff --git a/src/Modules/OrchardCore.Commerce/OrchardCore.Commerce.csproj b/src/Modules/OrchardCore.Commerce/OrchardCore.Commerce.csproj index 35c5752a1..98f831461 100644 --- a/src/Modules/OrchardCore.Commerce/OrchardCore.Commerce.csproj +++ b/src/Modules/OrchardCore.Commerce/OrchardCore.Commerce.csproj @@ -27,16 +27,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -58,7 +58,7 @@ - + diff --git a/src/OrchardCore.Commerce.Web/OrchardCore.Commerce.Web.csproj b/src/OrchardCore.Commerce.Web/OrchardCore.Commerce.Web.csproj index b23f7e162..f19ed3c52 100644 --- a/src/OrchardCore.Commerce.Web/OrchardCore.Commerce.Web.csproj +++ b/src/OrchardCore.Commerce.Web/OrchardCore.Commerce.Web.csproj @@ -13,9 +13,9 @@ --> - - - + + + diff --git a/test/OrchardCore.Commerce.Tests.UI.Shortcuts/OrchardCore.Commerce.Tests.UI.Shortcuts.csproj b/test/OrchardCore.Commerce.Tests.UI.Shortcuts/OrchardCore.Commerce.Tests.UI.Shortcuts.csproj index 32173499e..4f33ebf95 100644 --- a/test/OrchardCore.Commerce.Tests.UI.Shortcuts/OrchardCore.Commerce.Tests.UI.Shortcuts.csproj +++ b/test/OrchardCore.Commerce.Tests.UI.Shortcuts/OrchardCore.Commerce.Tests.UI.Shortcuts.csproj @@ -12,9 +12,9 @@ - - - + + + @@ -29,7 +29,7 @@ - + diff --git a/test/OrchardCore.Commerce.Tests.UI/OrchardCore.Commerce.Tests.UI.csproj b/test/OrchardCore.Commerce.Tests.UI/OrchardCore.Commerce.Tests.UI.csproj index 8f60f912a..77f3ecccf 100644 --- a/test/OrchardCore.Commerce.Tests.UI/OrchardCore.Commerce.Tests.UI.csproj +++ b/test/OrchardCore.Commerce.Tests.UI/OrchardCore.Commerce.Tests.UI.csproj @@ -9,8 +9,8 @@ - - + + all diff --git a/test/OrchardCore.Commerce.Tests.UI/Tests/UserTests/UserPersistenceTests.cs b/test/OrchardCore.Commerce.Tests.UI/Tests/UserTests/UserPersistenceTests.cs index e03cc6d92..08a68210a 100644 --- a/test/OrchardCore.Commerce.Tests.UI/Tests/UserTests/UserPersistenceTests.cs +++ b/test/OrchardCore.Commerce.Tests.UI/Tests/UserTests/UserPersistenceTests.cs @@ -142,16 +142,16 @@ await context.ClickReliablyOnAsync(By.XPath( const string testCustomerName = "Test Customer Name"; await context.ClickAndFillInWithRetriesAsync( - By.Id("UserAddressesPart_BillingAddress_Address_Name"), + By.Id("User_UserAddressesPart_BillingAddress_Address_Name"), testCustomerName); await context.SetCheckboxValueAsync( - By.Id("UserAddressesPart_BillingAndShippingAddressesMatch_Value"), + By.Id("User_UserAddressesPart_BillingAndShippingAddressesMatch_Value"), isChecked: true); await SubmitAndGoToUserAddressesAsync(); context - .Get(By.Id("UserAddressesPart_ShippingAddress_Address_Name").OfAnyVisibility()) + .Get(By.Id("User_UserAddressesPart_ShippingAddress_Address_Name").OfAnyVisibility()) .GetAttribute("value")? .Trim() .ShouldBe(testCustomerName); diff --git a/test/OrchardCore.Commerce.Tests/Fakes/FakeContentManager.cs b/test/OrchardCore.Commerce.Tests/Fakes/FakeContentManager.cs index 7255b487f..6e32ac45e 100644 --- a/test/OrchardCore.Commerce.Tests/Fakes/FakeContentManager.cs +++ b/test/OrchardCore.Commerce.Tests/Fakes/FakeContentManager.cs @@ -29,6 +29,9 @@ public Task CreateContentItemVersionAsync(ContentItem con public Task> GetAsync(IEnumerable contentItemIds, bool latest = false) => throw new NotSupportedException(); + public Task> GetAsync(IEnumerable contentItemIds, VersionOptions options) => + throw new NotSupportedException(); + public Task GetVersionAsync(string contentItemVersionId) => throw new NotSupportedException(); public Task ImportAsync(IEnumerable contentItems) => throw new NotSupportedException(); diff --git a/test/OrchardCore.Commerce.Tests/OrchardCore.Commerce.Tests.csproj b/test/OrchardCore.Commerce.Tests/OrchardCore.Commerce.Tests.csproj index 7809fbcf3..2cf78f541 100644 --- a/test/OrchardCore.Commerce.Tests/OrchardCore.Commerce.Tests.csproj +++ b/test/OrchardCore.Commerce.Tests/OrchardCore.Commerce.Tests.csproj @@ -15,7 +15,7 @@ - +