Skip to content

Commit de5af20

Browse files
Code comments
1 parent f2057e4 commit de5af20

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Umbraco.Commerce.Deploy/Connectors/ValueConnectors/UmbracoCommerceVariantsEditorValueConnector.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@ public class UmbracoCommerceVariantsEditorValueConnector(
4242
return null;
4343
}
4444

45-
if (!jsonSerializer.TryDeserialize(value, out VariantsBlockEditorValueBase? storeValue) || !storeValue.StoreId.HasValue)
46-
{
47-
return null;
48-
}
49-
5045
if (!jsonSerializer.TryDeserialize(value, out VariantsBlockEditorValue? result))
5146
{
5247
return null;
5348
}
5449

5550
await ToArtifactAsync(result, dependencies, contextCache, cancellationToken).ConfigureAwait(false);
5651

52+
// If we don't have a store id then we can't extract the product attribute dependencies
53+
// so we can just return the serialized value and hope the product attributes are there
54+
if (!jsonSerializer.TryDeserialize(value, out VariantsBlockEditorValueBase? storeValue) || !storeValue.StoreId.HasValue)
55+
{
56+
return jsonSerializer.Serialize(result);;
57+
}
58+
5759
IEnumerable<string>? productAttributeAliases = result.GetLayouts()?.SelectMany(x => x.Config.Attributes.Keys)
5860
.Distinct();
5961

@@ -73,6 +75,8 @@ public class UmbracoCommerceVariantsEditorValueConnector(
7375

7476
var artifact = jsonSerializer.Serialize(result);
7577

78+
// The block grid json converter will strip any none expected properties so we need to
79+
// temporarily deserialize the artifact as a generic JsonObject and add the store id back in
7680
JsonObject? artifactJson = jsonSerializer.Deserialize<JsonObject>(artifact.ToString()!);
7781

7882
artifactJson!.Remove("storeId");
@@ -98,7 +102,9 @@ public class UmbracoCommerceVariantsEditorValueConnector(
98102
{
99103
return artifact;
100104
}
101-
105+
106+
// The block grid json converter will strip any none expected properties so we need to
107+
// temporarily deserialize the artifact as a generic JsonObject and add the store id back in
102108
JsonObject? artifactJson = jsonSerializer.Deserialize<JsonObject>(artifact.ToString()!);
103109

104110
artifactJson!.Remove("storeId");

0 commit comments

Comments
 (0)