Skip to content

Commit

Permalink
OCC-245: Upgrade to latest OC preview to test System.Text.Json (#454)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Alhayek <[email protected]>
Co-authored-by: Zoltán Lehóczky <[email protected]>
  • Loading branch information
3 people authored Jul 28, 2024
1 parent 1944cdc commit 08018a8
Show file tree
Hide file tree
Showing 142 changed files with 729 additions and 1,022 deletions.
3 changes: 2 additions & 1 deletion .github/actions/spelling/allow/occ.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ foobool
footext
GST
htmlfield
JConvert
LCID
markdownlint
Mastercard
Expand All @@ -39,4 +40,4 @@ testproductvariant
unpublish
vnd
webhooks
webshop
webshop
16 changes: 9 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
<!-- The Orchard Core version should always be x.y.0 of the latest minor version for maximum compatibility when
distributed as NuGet packages. On the other hand, the consuming projects (including OrchardCore.Commerce.Web)
should use Orchard Core references for the latest patch version to pull all versions up in the final app. -->
<OrchardCoreVersion>1.8.0</OrchardCoreVersion>
<OrchardCoreVersion>2.0.0-preview-18282</OrchardCoreVersion>

<LombiqHelpfulLibrariesVersion>10.0.1-alpha.3.occ-245</LombiqHelpfulLibrariesVersion>
<LombiqTestsUIVersion>10.0.2-alpha.1.occ-245</LombiqTestsUIVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Lombiq.Analyzers.OrchardCore" Version="5.0.0" />
<PackageVersion Include="Lombiq.HelpfulLibraries.OrchardCore" Version="10.0.0" />
<PackageVersion Include="Lombiq.HelpfulLibraries.Refit" Version="10.0.0" />
<PackageVersion Include="Lombiq.HelpfulLibraries.OrchardCore" Version="$(LombiqHelpfulLibrariesVersion)" />
<PackageVersion Include="Lombiq.HelpfulLibraries.Refit" Version="$(LombiqHelpfulLibrariesVersion)" />
<PackageVersion Include="Lombiq.NodeJs.Extensions" Version="2.1.0" />
<PackageVersion Include="Lombiq.Tests" Version="3.0.0" />
<PackageVersion Include="Lombiq.Tests.UI" Version="10.0.1" />
<PackageVersion Include="Lombiq.Tests.UI.AppExtensions" Version="10.0.1" />
<PackageVersion Include="Lombiq.Tests.UI.Shortcuts" Version="10.0.1" />
<PackageVersion Include="Lombiq.Tests.UI" Version="$(LombiqTestsUIVersion)" />
<PackageVersion Include="Lombiq.Tests.UI.AppExtensions" Version="$(LombiqTestsUIVersion)" />
<PackageVersion Include="Lombiq.Tests.UI.Shortcuts" Version="$(LombiqTestsUIVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="OrchardCore.Application.Cms.Targets" Version="$(OrchardCoreVersion)" />
<PackageVersion Include="OrchardCore.ContentFields" Version="$(OrchardCoreVersion)" />
<PackageVersion Include="OrchardCore.ContentManagement" Version="$(OrchardCoreVersion)" />
Expand Down
33 changes: 33 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Ignore global configuration -->
<clear />
<add key="LombiqPreview" value="https://nuget.cloudsmith.io/lombiq/open-source-orchard-core-extensions/v3/index.json" />
<add key="OrchardCorePreview" value="https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
<!-- OrchardCore.Translations.All is on a separate repo and doesn't have a preview -->
<package pattern="OrchardCore.Translations.*" />
</packageSource>
<packageSource key="OrchardCorePreview">
<package pattern="OrchardCore*" />
<!-- OrchardCore theme packages -->
<package pattern="SafeMode" />
<package pattern="TheAgencyTheme" />
<package pattern="TheBlogTheme" />
<package pattern="TheComingSoonTheme" />
<package pattern="TheTheme" />
<package pattern="TheAdmin" />
</packageSource>
<!-- Enable these to use the Lombiq packages from Cloudsmith instead of NuGet.
<packageSource key="LombiqPreview">
<package pattern="Lombiq.HelpfulLibraries*" />
<package pattern="Lombiq.Tests.UI*" />
</packageSource>
-->
</packageSourceMapping>
</configuration>
21 changes: 0 additions & 21 deletions Nuget.config

This file was deleted.

8 changes: 7 additions & 1 deletion OrchardCore.Commerce.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
License.md = License.md
mkdocs.yml = mkdocs.yml
Nuget.config = Nuget.config
Readme.md = Readme.md
Reset-Local.ps1 = Reset-Local.ps1
Directory.Packages.props = Directory.Packages.props
NuGet.config = NuGet.config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B2D057AA-E3F7-404D-A713-C3C59F9DE562}"
Expand Down Expand Up @@ -118,6 +118,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "guides", "guides", "{EF8008
docs\guides\create-webshop.md = docs\guides\create-webshop.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "releases", "releases", "{0A8AB166-9C4F-4161-BD69-362DBC73A11E}"
ProjectSection(SolutionItems) = preProject
docs\releases\3.0.0.md = docs\releases\3.0.0.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -214,6 +219,7 @@ Global
{28DB6CBB-1527-42A1-8EFE-3D95BF185884} = {90913510-3D7F-4BCC-B55E-56343128F049}
{73925C09-BF96-4727-91D8-57A88AD1601F} = {E6C02BDF-EEB0-4ABD-ADEC-9932F60923AE}
{EF8008F1-64F5-4053-A639-6285084AFA52} = {BEBA1764-178A-4722-A193-4DEF26DCE8D1}
{0A8AB166-9C4F-4161-BD69-362DBC73A11E} = {BEBA1764-178A-4722-A193-4DEF26DCE8D1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {456CBC78-579D-483F-A4C3-AF5C12AB3324}
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/create-webshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Navigate to _Design > Settings > Zones_ and define the zone where you want the S
_Header, Content, Footer, any zone can be created here. Except for Ozone, that's illegal._

- **Layers**:
A Layer is also going to be necessary for the Widget, so if you don't have one set up yet, see the [relevant documentation page](https://github.com/OrchardCMS/OrchardCore/tree/main/src/docs/reference/modules/Layers/).
A Layer is also going to be necessary for the Widget, so if you don't have one set up yet, see the [relevant documentation page](https://docs.orchardcore.net/en/latest/reference/modules/Layers/).

- **Widget**:
Widgets are content items that have their stereotype set to Widget. The Commerce module creates a simple Shopping Cart Widget when it's enabled, so we'll just use that. For more extensive documentation about Widgets, see the [usual place](https://docs.orchardcore.net/en/main/docs/reference/modules/Widgets/).
Expand Down
30 changes: 30 additions & 0 deletions docs/releases/3.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Orchard Core Commerce 3.0.0

Release date: Not yet released

## Important Upgrade Instructions

Prior to making the leap to Orchard Core Commerce 3.0.0, please read and follow the instructions for the [Orchard Core 2.0.0 release](https://docs.orchardcore.net/en/latest/releases/2.0.0/), as it contains several major breaking changes.

## Breaking Changes

### Dropped `Newtonsoft.Json` Support

The most important breaking change in OC 2.0 is the end of support for [Newtonsoft Json.NET](https://www.newtonsoft.com/json) and the switch to the [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) (STJ) library. For OCC, all Newtonsoft converters are removed, STJ converters were written or updated as necessary. Any models and interfaces that use `JToken` or `JObject` (such as `OrderPart.AdditionalData` and `IUserService.AlterUserSettingAsync()`) now use `JsonNode` and `JsonObject` respectively.

### Replaced `IPayment` with `Payment` Everywhere

We've dropped the [`IPayment`](https://github.com/OrchardCMS/OrchardCore.Commerce/blob/34ae00470e954459f19f688c9bfc51d196c386ca/src/Libraries/OrchardCore.Commerce.Abstractions/Abstractions/IPayment.cs) interface, now services and models use `Payment` directly, which was also moved into the `OrchardCore.Commerce.Abstractions` library. Migrating to STJ meant that to retain the polymorphic deserialization support for models using `IPayment` would've taken on some additional complexity, while we already found the separate interface unnecessary.

Update using references to `OrchardCore.Commerce.Abstractions.Models`. If you have a custom payment processor integration, update it to use `Payment`.

### Liquid Filters

The `order_line_item_view_models_and_tax_rates` Liquid filter has been removed. A new `order_part_to_order_summary` filter has been added instead, which can be treated as a drop-in replacement. It has additional `Amount` type properties: `UnitTax`, `SubTotal`, `TaxTotal`, and `Total`. These contain the calculated and appropriately rounded values.

The new `amount_to_string` filter processes the input object as `Amount` (like the `amount` filter) and correctly formats it just like the `Amount.ToString()` override in C#. You can use `amount_to_string: dot: ","` to make it display a comma as the decimal separator when it would use a dot. Unlike `amount`, you can also use this filter on a number with the `currency: "three-letter-code""` argument (e.g. `{{ value | amount_to_string: currency: "EUR" }}`). This will display any numeric value as the given currency.

## Change Logs

Please check the GitHub release entry [here](https://github.com/OrchardCMS/OrchardCore.Commerce/releases/tag/v3.0.0).

4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ nav:
- NumericProductAttributeField: features/numeric-product-attribute-field.md
- Resources:
- Libraries: resources/libraries/README.md
- Releases: https://github.com/OrchardCMS/OrchardCore.Commerce/releases
- Releases and Notes:
- GitHub: https://github.com/OrchardCMS/OrchardCore.Commerce/releases
- 3.0.0: docs/releases/3.0.0.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json.Linq;
using System;
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;

Expand All @@ -23,11 +22,6 @@ public interface IProductAttributeDeserializer
/// </summary>
string AttributeTypeName { get; }

/// <summary>
/// Deserializes using <c>Newtonsoft.Json</c>.
/// </summary>
IProductAttributeValue Deserialize(string attributeName, JObject attribute);

/// <summary>
/// Deserializes using <c>System.Text.Json</c>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Newtonsoft.Json;
using OrchardCore.Commerce.Abstractions.Serialization;
using System;
using System.Globalization;
using System.Linq;
using System.Text.Json.Serialization;

namespace OrchardCore.Commerce.Abstractions.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.Users.Models;
using System;
using System.Security.Claims;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace OrchardCore.Commerce.Abstractions.Abstractions;
Expand All @@ -22,7 +22,7 @@ public interface IUserService
/// Alters the JSON of a custom user setting content item and saves the result. If the setting doesn't exist for the
/// user then also creates it.
/// </summary>
Task AlterUserSettingAsync(User user, string contentType, Func<JObject, JObject> updateContentItemJson);
Task AlterUserSettingAsync(User user, string contentType, Func<JsonObject, JsonObject> updateContentItemJson);

/// <summary>
/// Retrieves a <see cref="ContentItem"/> that belongs to the custom user setting.
Expand All @@ -33,8 +33,7 @@ public interface IUserService
public static class UserServiceExtensions
{
public static Task<User> GetCurrentFullUserAsync(this IUserService service, IHttpContextAccessor hca) =>
hca.HttpContext?.User is { } user &&
hca.HttpContext.User.Identity?.IsAuthenticated == true
hca.HttpContext?.User is { Identity.IsAuthenticated: true } user
? service.GetFullUserAsync(user)
: Task.FromResult<User>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OrchardCore.Commerce.MoneyDataType;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OrchardCore.Commerce.Abstractions.Models;

Expand All @@ -13,10 +14,15 @@ public class OrderLineItem
public Amount UnitPrice { get; set; }
public Amount LinePrice { get; set; }
public string ContentItemVersion { get; set; }
public ISet<IProductAttributeValue> Attributes { get; }
public IDictionary<string, IDictionary<string, string>> SelectedAttributes { get; } =
public ISet<IProductAttributeValue> Attributes { get; init; }
public IDictionary<string, IDictionary<string, string>> SelectedAttributes { get; init; } =
new Dictionary<string, IDictionary<string, string>>();

[JsonConstructor]
private OrderLineItem()
{
}

// These are necessary.
#pragma warning disable S107 // Methods should not have too many parameters
public OrderLineItem(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.Commerce.Abstractions.Abstractions;
using OrchardCore.Commerce.Abstractions.Constants;
using OrchardCore.Commerce.Abstractions.Fields;
using OrchardCore.ContentFields.Fields;
using OrchardCore.ContentManagement;
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace OrchardCore.Commerce.Abstractions.Models;

Expand All @@ -26,16 +25,9 @@ public class OrderPart : ContentPart
public IList<OrderAdditionalCost> AdditionalCosts { get; } = new List<OrderAdditionalCost>();

/// <summary>
/// Gets the amounts charged for this order. Typically a single credit card charge.
/// Gets the amounts charged for this order. Typically, a single credit card charge.
/// </summary>

// This is a temporary solution, it needs to be reworked in the future!
#pragma warning disable CA2326 // Do not use TypeNameHandling values other than None
#pragma warning disable SCS0028 // TypeNameHandling is set to the other value than 'None'. It may lead to deserialization vulnerability.
[JsonProperty(ItemTypeNameHandling = TypeNameHandling.Auto)]
#pragma warning restore SCS0028 // TypeNameHandling is set to the other value than 'None'. It may lead to deserialization vulnerability.
#pragma warning restore CA2326 // Do not use TypeNameHandling values other than None
public IList<IPayment> Charges { get; } = new List<IPayment>();
public IList<Payment> Charges { get; } = new List<Payment>();

public TextField Email { get; set; } = new();
public TextField Phone { get; set; } = new();
Expand All @@ -46,7 +38,7 @@ public class OrderPart : ContentPart
public BooleanField BillingAndShippingAddressesMatch { get; set; } = new();
public BooleanField IsCorporation { get; set; } = new();

public IDictionary<string, JToken> AdditionalData { get; } = new Dictionary<string, JToken>();
public IDictionary<string, JsonNode> AdditionalData { get; } = new Dictionary<string, JsonNode>();

[JsonIgnore]
public bool IsPending => string.IsNullOrWhiteSpace(Status?.Text) || Status.Text.EqualsOrdinalIgnoreCase(OrderStatusCodes.Pending);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using OrchardCore.Commerce.Abstractions.Abstractions;
using OrchardCore.Commerce.MoneyDataType;
using System;

namespace OrchardCore.Commerce.Payment.Models;
namespace OrchardCore.Commerce.Abstractions.Models;

public record Payment(
string Kind,
string TransactionId,
string ChargeText,
Amount Amount,
DateTime CreatedUtc)
: IPayment;
DateTime CreatedUtc);
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Newtonsoft.Json;
using OrchardCore.Commerce.Abstractions.Serialization;
using OrchardCore.Commerce.MoneyDataType;
using System.Diagnostics;
using System.Globalization;
using System.Text.Json.Serialization;

namespace OrchardCore.Commerce.Abstractions.Models;

/// <summary>
/// A price and its priority.
/// </summary>
[JsonConverter(typeof(LegacyPrioritizedPriceConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(PrioritizedPriceConverter))]
[JsonConverter(typeof(PrioritizedPriceConverter))]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PrioritizedPrice
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public class ShoppingCart
/// <summary>
/// Gets the number of lines in the cart.
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[JsonIgnore]
public int Count => Items.Count;

/// <summary>
/// Gets the total number of items (i.e. products) in the cart. In other words, the sum of quantities of all lines.
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[JsonIgnore]
public int ItemCount => Items.Sum(item => item.Quantity);

Expand Down
Loading

0 comments on commit 08018a8

Please sign in to comment.