Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ad06b2
Remove unused properties from POS models
joshheald Aug 29, 2025
0d908b9
Add description fields to POS entities
joshheald Aug 29, 2025
6c877e8
Update GRDB tables to include stock properties
joshheald Aug 29, 2025
906316b
Periphery ignores
joshheald Aug 29, 2025
d432ab2
Add persisted models
joshheald Aug 29, 2025
5205ada
Support for autoincrementing keys
joshheald Aug 29, 2025
f4cf155
Add mapping for persisted models
joshheald Aug 29, 2025
b37d574
Add attribute and image associations
joshheald Aug 29, 2025
ff03881
Test persisted to networking model conversion
joshheald Aug 29, 2025
f416265
Save product/variation entities with relationships
joshheald Aug 29, 2025
627787d
Fix whitespace
joshheald Aug 29, 2025
e831e89
Test saving POS models and regroup mapping tests
joshheald Aug 29, 2025
e9fc1ce
Tests for saving POS models to GRDB
joshheald Aug 29, 2025
9f46de1
Fix test expectation
joshheald Aug 29, 2025
a25fb79
Merge branch 'trunk' into woomob-1210-remove-unused-properties-from-p…
joshheald Sep 1, 2025
fa81d6b
Fix lint from merge
joshheald Sep 1, 2025
6c9b6c8
Fix merge test issue
joshheald Sep 1, 2025
f822a09
Match attribute handling for product and variation
joshheald Sep 1, 2025
218d704
Test updates from code revier
joshheald Sep 1, 2025
cdc2e9d
Test fix
joshheald Sep 1, 2025
e3d7b85
Use a single transaction for reading relationships
joshheald Sep 1, 2025
435502f
Merge branch 'woomob-1210-basic-mapping-from-POS-entities-to-persiste…
joshheald Sep 1, 2025
b9c3b19
Merge branch 'woomob-1210-relationship-based-mapping-and-saving-for-P…
joshheald Sep 1, 2025
5c8d942
Remove test prefixes
joshheald Sep 1, 2025
a9048a2
Demonstrate joined records in variation tests
joshheald Sep 1, 2025
991e405
Given/When/Then for all tests
joshheald Sep 1, 2025
c523e48
Fix lint
joshheald Sep 1, 2025
2477ef4
Ignore periphery
joshheald Sep 1, 2025
604a3df
More periphery
joshheald Sep 1, 2025
d0c1b2d
[Woo POS][Local Catalog] Tests for saving pos models (#16064)
joshheald Sep 1, 2025
2159f0d
[Woo POS][Local catalog] Add relationship mapping and saving for POS …
joshheald Sep 1, 2025
64b030a
[Woo POS][Local Catalog] Basic mapping from POS models to Persisted m…
joshheald Sep 1, 2025
446d6d7
[Woo POS][Local catalog] Add persistence classes (#16061)
joshheald Sep 2, 2025
cd292c4
Merge branch 'trunk' into woomob-1210-remove-unused-properties-from-p…
joshheald Sep 2, 2025
a761ebf
Remove unused code from catalog sync
joshheald Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Modules/Sources/Fakes/Networking.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,11 @@ extension Networking.POSProduct {
productID: .fake(),
name: .fake(),
productTypeKey: .fake(),
fullDescription: .fake(),
shortDescription: .fake(),
sku: .fake(),
globalUniqueID: .fake(),
price: .fake(),
regularPrice: .fake(),
salePrice: .fake(),
onSale: .fake(),
downloadable: .fake(),
parentID: .fake(),
images: .fake(),
Expand All @@ -779,12 +778,10 @@ extension Networking.POSProductVariation {
productVariationID: .fake(),
attributes: .fake(),
image: .fake(),
fullDescription: .fake(),
sku: .fake(),
globalUniqueID: .fake(),
price: .fake(),
regularPrice: .fake(),
salePrice: .fake(),
onSale: .fake(),
downloadable: .fake(),
manageStock: .fake(),
stockQuantity: .fake(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,11 @@ extension Networking.POSProduct {
productID: CopiableProp<Int64> = .copy,
name: CopiableProp<String> = .copy,
productTypeKey: CopiableProp<String> = .copy,
fullDescription: NullableCopiableProp<String> = .copy,
shortDescription: NullableCopiableProp<String> = .copy,
sku: NullableCopiableProp<String> = .copy,
globalUniqueID: NullableCopiableProp<String> = .copy,
price: CopiableProp<String> = .copy,
regularPrice: NullableCopiableProp<String> = .copy,
salePrice: NullableCopiableProp<String> = .copy,
onSale: CopiableProp<Bool> = .copy,
downloadable: CopiableProp<Bool> = .copy,
parentID: CopiableProp<Int64> = .copy,
images: CopiableProp<[ProductImage]> = .copy,
Expand All @@ -1264,12 +1263,11 @@ extension Networking.POSProduct {
let productID = productID ?? self.productID
let name = name ?? self.name
let productTypeKey = productTypeKey ?? self.productTypeKey
let fullDescription = fullDescription ?? self.fullDescription
let shortDescription = shortDescription ?? self.shortDescription
let sku = sku ?? self.sku
let globalUniqueID = globalUniqueID ?? self.globalUniqueID
let price = price ?? self.price
let regularPrice = regularPrice ?? self.regularPrice
let salePrice = salePrice ?? self.salePrice
let onSale = onSale ?? self.onSale
let downloadable = downloadable ?? self.downloadable
let parentID = parentID ?? self.parentID
let images = images ?? self.images
Expand All @@ -1283,12 +1281,11 @@ extension Networking.POSProduct {
productID: productID,
name: name,
productTypeKey: productTypeKey,
fullDescription: fullDescription,
shortDescription: shortDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
parentID: parentID,
images: images,
Expand All @@ -1307,12 +1304,10 @@ extension Networking.POSProductVariation {
productVariationID: CopiableProp<Int64> = .copy,
attributes: CopiableProp<[ProductVariationAttribute]> = .copy,
image: NullableCopiableProp<ProductImage> = .copy,
fullDescription: NullableCopiableProp<String> = .copy,
sku: NullableCopiableProp<String> = .copy,
globalUniqueID: NullableCopiableProp<String> = .copy,
price: CopiableProp<String> = .copy,
regularPrice: NullableCopiableProp<String> = .copy,
salePrice: NullableCopiableProp<String> = .copy,
onSale: CopiableProp<Bool> = .copy,
downloadable: CopiableProp<Bool> = .copy,
manageStock: CopiableProp<Bool> = .copy,
stockQuantity: NullableCopiableProp<Decimal> = .copy,
Expand All @@ -1323,12 +1318,10 @@ extension Networking.POSProductVariation {
let productVariationID = productVariationID ?? self.productVariationID
let attributes = attributes ?? self.attributes
let image = image ?? self.image
let fullDescription = fullDescription ?? self.fullDescription
let sku = sku ?? self.sku
let globalUniqueID = globalUniqueID ?? self.globalUniqueID
let price = price ?? self.price
let regularPrice = regularPrice ?? self.regularPrice
let salePrice = salePrice ?? self.salePrice
let onSale = onSale ?? self.onSale
let downloadable = downloadable ?? self.downloadable
let manageStock = manageStock ?? self.manageStock
let stockQuantity = stockQuantity ?? self.stockQuantity
Expand All @@ -1340,12 +1333,10 @@ extension Networking.POSProductVariation {
productVariationID: productVariationID,
attributes: attributes,
image: image,
fullDescription: fullDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
manageStock: manageStock,
stockQuantity: stockQuantity,
Expand Down
46 changes: 13 additions & 33 deletions Modules/Sources/Networking/Model/POSProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
public let productID: Int64
public let name: String
public let productTypeKey: String
public let fullDescription: String?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting that shortDescription requires periphery ignore but this one doesn't 🤔

// periphery:ignore - Will be used for search in future
public let shortDescription: String?
public let sku: String?
public let globalUniqueID: String?

public let price: String
public let regularPrice: String?
public let salePrice: String?
public let onSale: Bool

public let downloadable: Bool

Expand Down Expand Up @@ -47,12 +47,11 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
productID: Int64,
name: String,
productTypeKey: String,
fullDescription: String?,
shortDescription: String?,
sku: String?,
globalUniqueID: String?,
price: String,
regularPrice: String?,
salePrice: String?,
onSale: Bool,
downloadable: Bool,
parentID: Int64,
images: [ProductImage],
Expand All @@ -64,13 +63,12 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
self.productID = productID
self.name = name
self.productTypeKey = productTypeKey
self.fullDescription = fullDescription
self.shortDescription = shortDescription
self.sku = sku
self.globalUniqueID = globalUniqueID

self.price = price
self.regularPrice = regularPrice
self.salePrice = salePrice
self.onSale = onSale

self.downloadable = downloadable

Expand Down Expand Up @@ -101,6 +99,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
let productID = try container.decode(Int64.self, forKey: .productID)
let name = try container.decode(String.self, forKey: .name)
let productTypeKey = try container.decode(String.self, forKey: .productTypeKey)
let fullDescription = try container.decodeIfPresent(String.self, forKey: .fullDescription)
let shortDescription = try container.decodeIfPresent(String.self, forKey: .shortDescription)
let sku = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .sku,
Expand All @@ -111,24 +111,6 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
targetType: String.self,
forKey: .price,
alternativeTypes: [decimalString]) ?? ""
let regularPrice = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .regularPrice,
alternativeTypes: [decimalString])
let onSale = container.failsafeDecodeIfPresent(
targetType: Bool.self,
forKey: .onSale,
alternativeTypes: [ .string(transform: { NSString(string: $0).boolValue })]) ?? false

// Even though a plain install of WooCommerce Core provides string values,
// some plugins alter the field value from String to Int or Decimal.
let salePrice = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .salePrice,
shouldDecodeTargetTypeFirst: false,
alternativeTypes: [
.string(transform: { (onSale && $0.isEmpty) ? "0" : $0 }),
decimalString])

let downloadable = try container.decode(Bool.self, forKey: .downloadable)

Expand All @@ -146,12 +128,11 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
productID: productID,
name: name,
productTypeKey: productTypeKey,
fullDescription: fullDescription,
shortDescription: shortDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
parentID: parentID,
images: images,
Expand Down Expand Up @@ -179,12 +160,11 @@ private extension POSProduct {
case productID = "id"
case name
case productTypeKey = "type"
case fullDescription = "description"
case shortDescription = "short_description"
case sku
case globalUniqueID = "global_unique_id"
case price
case regularPrice = "regular_price"
case salePrice = "sale_price"
case onSale = "on_sale"
case downloadable
case parentID = "parent_id"
case images
Expand Down
35 changes: 7 additions & 28 deletions Modules/Sources/Networking/Model/POSProductVariation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
public let attributes: [ProductVariationAttribute]
public let image: ProductImage?

// periphery:ignore - Will be used for search in future
public let fullDescription: String?
public let sku: String?
public let globalUniqueID: String?

public let price: String
public let regularPrice: String?
public let salePrice: String?
public let onSale: Bool

public let downloadable: Bool

public let manageStock: Bool
Expand All @@ -40,12 +38,10 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
productVariationID: Int64,
attributes: [ProductVariationAttribute],
image: ProductImage?,
fullDescription: String?,
sku: String?,
globalUniqueID: String?,
price: String,
regularPrice: String?,
salePrice: String?,
onSale: Bool,
downloadable: Bool,
manageStock: Bool,
stockQuantity: Decimal?,
Expand All @@ -55,12 +51,10 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
self.productVariationID = productVariationID
self.attributes = attributes
self.image = image
self.fullDescription = fullDescription
self.sku = sku
self.globalUniqueID = globalUniqueID
self.price = price
self.regularPrice = regularPrice
self.salePrice = salePrice
self.onSale = onSale
self.downloadable = downloadable
self.manageStock = manageStock
self.stockQuantity = stockQuantity
Expand All @@ -81,6 +75,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
let productID = try container.decode(Int64.self, forKey: .productID)
let attributes = try container.decode([ProductVariationAttribute].self, forKey: .attributes)
let image = try container.decodeIfPresent(ProductImage.self, forKey: .image)
let fullDescription = try container.decodeIfPresent(String.self, forKey: .fullDescription)
let sku = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .sku,
Expand All @@ -90,18 +85,6 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
targetType: String.self,
forKey: .price,
alternativeTypes: [decimalString]) ?? ""
let regularPrice = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .regularPrice,
alternativeTypes: [decimalString])
let salePrice = container.failsafeDecodeIfPresent(
targetType: String.self,
forKey: .salePrice,
alternativeTypes: [decimalString])
let onSale = container.failsafeDecodeIfPresent(
targetType: Bool.self,
forKey: .onSale,
alternativeTypes: [.string(transform: { NSString(string: $0).boolValue })]) ?? false
let downloadable = try container.decode(Bool.self, forKey: .downloadable)
let manageStock = container.failsafeDecodeIfPresent(
targetType: Bool.self,
Expand All @@ -125,12 +108,10 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
productVariationID: productVariationID,
attributes: attributes,
image: image,
fullDescription: fullDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
manageStock: manageStock,
stockQuantity: stockQuantity,
Expand Down Expand Up @@ -158,9 +139,7 @@ private extension POSProductVariation {
case attributes
case image
case price
case regularPrice = "regular_price"
case salePrice = "sale_price"
case onSale = "on_sale"
case fullDescription = "description"
case sku
case globalUniqueID = "global_unique_id"
case downloadable
Expand Down
4 changes: 1 addition & 3 deletions Modules/Sources/Networking/Remote/POSCatalogSyncRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,10 @@ private extension POSProduct {
productVariationID: productID,
attributes: variationAttributes,
image: firstImage,
fullDescription: fullDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
manageStock: manageStock,
stockQuantity: stockQuantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct V001InitialSchema {
productTable.column("downloadable", .boolean).notNull()

productTable.column("parentID", .integer).notNull()

productTable.column("manageStock", .boolean).notNull()
productTable.column("stockQuantity", .double)
productTable.column("stockStatusKey", .text).notNull()
}
}

Expand Down Expand Up @@ -87,6 +91,10 @@ struct V001InitialSchema {
productVariationTable.column("downloadable", .boolean).notNull()

productVariationTable.column("fullDescription", .text)

productVariationTable.column("manageStock", .boolean).notNull()
productVariationTable.column("stockQuantity", .double)
productVariationTable.column("stockStatusKey", .text).notNull()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ private extension POSProduct {
productVariationID: productID,
attributes: try attributes.compactMap { try $0.toProductVariationAttribute() },
image: images.first,
fullDescription: fullDescription,
sku: sku,
globalUniqueID: globalUniqueID,
price: price,
regularPrice: regularPrice,
salePrice: salePrice,
onSale: onSale,
downloadable: downloadable,
manageStock: manageStock,
stockQuantity: stockQuantity,
Expand Down
Loading