Skip to content

Commit dbf8ff1

Browse files
Merge pull request #8736 from woocommerce/feat/8715-product-attributes-migration
[REST API] Migrate product variations and attributes
2 parents 8e34e1f + fdc42f9 commit dbf8ff1

29 files changed

+1577
-62
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 44 additions & 0 deletions
Large diffs are not rendered by default.

Networking/Networking/Mapper/ProductAttributeListMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct ProductAttributeListMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(ProductAttributeListEnvelope.self, from: response).productAttributes
20+
do {
21+
return try decoder.decode(ProductAttributeListEnvelope.self, from: response).productAttributes
22+
} catch {
23+
return try decoder.decode([ProductAttribute].self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/ProductAttributeMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ struct ProductAttributeMapper: Mapper {
2020
.siteID: siteID
2121
]
2222

23-
return try decoder.decode(ProductAttributeEnvelope.self, from: response).productAttribute
23+
do {
24+
return try decoder.decode(ProductAttributeEnvelope.self, from: response).productAttribute
25+
} catch {
26+
return try decoder.decode(ProductAttribute.self, from: response)
27+
}
2428
}
2529
}
2630

Networking/Networking/Mapper/ProductAttributeTermListMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct ProductAttributeTermListMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(ProductAttributeTermListEnvelope.self, from: response).productAttributeTerms
20+
do {
21+
return try decoder.decode(ProductAttributeTermListEnvelope.self, from: response).productAttributeTerms
22+
} catch {
23+
return try decoder.decode([ProductAttributeTerm].self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/ProductAttributeTermMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ struct ProductAttributeTermMapper: Mapper {
1818
.siteID: siteID
1919
]
2020

21-
return try decoder.decode(ProductAttributeTermEnvelope.self, from: response).productAttributeTerm
21+
do {
22+
return try decoder.decode(ProductAttributeTermEnvelope.self, from: response).productAttributeTerm
23+
} catch {
24+
return try decoder.decode(ProductAttributeTerm.self, from: response)
25+
}
2226
}
2327
}
2428

Networking/Networking/Mapper/ProductVariationListMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ struct ProductVariationListMapper: Mapper {
2626
.productID: productID
2727
]
2828

29-
return try decoder.decode(ProductVariationsEnvelope.self, from: response).productVariations
29+
do {
30+
return try decoder.decode(ProductVariationsEnvelope.self, from: response).productVariations
31+
} catch {
32+
return try decoder.decode([ProductVariation].self, from: response)
33+
}
3034
}
3135
}
3236

Networking/Networking/Mapper/ProductVariationMapper.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ struct ProductVariationMapper: Mapper {
2424
.siteID: siteID,
2525
.productID: productID
2626
]
27-
return try decoder.decode(ProductVariationEnvelope.self, from: response).productVariation
27+
28+
do {
29+
return try decoder.decode(ProductVariationEnvelope.self, from: response).productVariation
30+
} catch {
31+
return try decoder.decode(ProductVariation.self, from: response)
32+
}
2833
}
2934
}
3035

Networking/Networking/Mapper/ProductVariationsBulkCreateMapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ private struct ProductVariationsEnvelope: Decodable {
4444
public init(from decoder: Decoder) throws {
4545
let container = try decoder.container(keyedBy: CodingKeys.self)
4646

47-
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
48-
createdProductVariations = try nestedContainer.decode([ProductVariation].self, forKey: .create)
47+
do {
48+
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
49+
createdProductVariations = try nestedContainer.decode([ProductVariation].self, forKey: .create)
50+
} catch {
51+
createdProductVariations = try container.decode([ProductVariation].self, forKey: .create)
52+
}
4953
}
5054
}

Networking/Networking/Mapper/ProductVariationsBulkUpdateMapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ private struct ProductVariationsEnvelope: Decodable {
4444
public init(from decoder: Decoder) throws {
4545
let container = try decoder.container(keyedBy: CodingKeys.self)
4646

47-
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
48-
updatedProductVariations = try nestedContainer.decode([ProductVariation].self, forKey: .update)
47+
do {
48+
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
49+
updatedProductVariations = try nestedContainer.decode([ProductVariation].self, forKey: .update)
50+
} catch {
51+
updatedProductVariations = try container.decode([ProductVariation].self, forKey: .update)
52+
}
4953
}
5054
}

Networking/Networking/Mapper/ProductsBulkUpdateMapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ private struct ProductsEnvelope: Decodable {
3737
public init(from decoder: Decoder) throws {
3838
let container = try decoder.container(keyedBy: CodingKeys.self)
3939

40-
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
41-
updatedProducts = try nestedContainer.decode([Product].self, forKey: .update)
40+
do {
41+
let nestedContainer = try container.nestedContainer(keyedBy: CodingKeys.self, forKey: .data)
42+
updatedProducts = try nestedContainer.decode([Product].self, forKey: .update)
43+
} catch {
44+
updatedProducts = try container.decode([Product].self, forKey: .update)
45+
}
4246
}
4347
}

0 commit comments

Comments
 (0)