Skip to content

Commit 4d06a14

Browse files
committed
Add missing attributes for ShippingLabelAccountSettings
1 parent 37422ce commit 4d06a14

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

Modules/Sources/Storage/Model/MIGRATIONS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This file documents changes in the WCiOS Storage data model. Please explain any
1010
- Added `shipments` relationship to `Order` entity.
1111
- @itsmeichigo 2025-07-22
1212
- Added `WooShippingOriginAddress` entity.
13+
- Added attributes `lastOrderCompleted` and `addPaymentMethodURL` to `ShippingLabelAccountSettings` entity.
1314

1415
## Model 123 (Release 22.8.0.0)
1516
- @iamgabrielma 2025-06-30

Modules/Sources/Storage/Model/ShippingLabelAccountSettings+CoreDataProperties.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ extension ShippingLabelAccountSettings {
1212
@NSManaged public var canManagePayments: Bool
1313
@NSManaged public var isEmailReceiptsEnabled: Bool
1414
@NSManaged public var lastSelectedPackageID: String?
15+
@NSManaged public var lastOrderCompleted: Bool
1516
@NSManaged public var paperSize: String?
1617
@NSManaged public var selectedPaymentMethodID: Int64
1718
@NSManaged public var siteID: Int64
1819
@NSManaged public var storeOwnerDisplayName: String?
1920
@NSManaged public var storeOwnerUsername: String?
2021
@NSManaged public var storeOwnerWpcomEmail: String?
2122
@NSManaged public var storeOwnerWpcomUsername: String?
23+
@NSManaged public var addPaymentMethodURL: String?
2224
@NSManaged public var paymentMethods: Set<ShippingLabelPaymentMethod>?
2325

2426
}

Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 124.xcdatamodel/contents

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,11 @@
778778
<relationship name="shipment" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="WooShippingShipment" inverseName="shippingLabel" inverseEntity="WooShippingShipment"/>
779779
</entity>
780780
<entity name="ShippingLabelAccountSettings" representedClassName="ShippingLabelAccountSettings" syncable="YES">
781+
<attribute name="addPaymentMethodURL" optional="YES" attributeType="String"/>
781782
<attribute name="canEditSettings" attributeType="Boolean" usesScalarValueType="YES"/>
782783
<attribute name="canManagePayments" attributeType="Boolean" usesScalarValueType="YES"/>
783784
<attribute name="isEmailReceiptsEnabled" attributeType="Boolean" usesScalarValueType="YES"/>
785+
<attribute name="lastOrderCompleted" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
784786
<attribute name="lastSelectedPackageID" attributeType="String" defaultValueString=""/>
785787
<attribute name="paperSize" attributeType="String"/>
786788
<attribute name="selectedPaymentMethodID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>

Modules/Sources/Yosemite/Model/Storage/ShippingLabelAccountSettings+ReadOnlyConvertible.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension Storage.ShippingLabelAccountSettings: ReadOnlyConvertible {
1818
isEmailReceiptsEnabled = settings.isEmailReceiptsEnabled
1919
paperSize = settings.paperSize.rawValue
2020
lastSelectedPackageID = settings.lastSelectedPackageID
21+
lastOrderCompleted = settings.lastOrderCompleted
22+
addPaymentMethodURL = settings.addPaymentMethodURL?.absoluteString
2123
}
2224

2325
/// Returns a ReadOnly version of the receiver.
@@ -26,7 +28,6 @@ extension Storage.ShippingLabelAccountSettings: ReadOnlyConvertible {
2628
let paymentMethodItems = paymentMethods?.map { $0.toReadOnly() } ?? []
2729

2830
/// Since account settings are not persisted for the new shipping label flow,
29-
/// the conversion for the new properties `addPaymentMethodURL` & `lastOrderCompleted` is ignored.
3031
/// This avoids the complication of unnecessary Core Data migration for the new properties.
3132
return ShippingLabelAccountSettings(siteID: siteID,
3233
canManagePayments: canManagePayments,
@@ -40,7 +41,7 @@ extension Storage.ShippingLabelAccountSettings: ReadOnlyConvertible {
4041
isEmailReceiptsEnabled: isEmailReceiptsEnabled,
4142
paperSize: .init(rawValue: paperSize ?? ""),
4243
lastSelectedPackageID: lastSelectedPackageID ?? "",
43-
lastOrderCompleted: false,
44-
addPaymentMethodURL: nil)
44+
lastOrderCompleted: lastOrderCompleted,
45+
addPaymentMethodURL: URL(string: addPaymentMethodURL ?? ""))
4546
}
4647
}

Modules/Tests/StorageTests/CoreData/MigrationTests.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,57 @@ final class MigrationTests: XCTestCase {
35183518
let insertedAddress = try XCTUnwrap(targetContext.firstObject(ofType: WooShippingOriginAddress.self))
35193519
XCTAssertEqual(insertedAddress, address)
35203520
}
3521+
3522+
func test_migrating_from_123_to_124_adds_new_attributes_lastOrderCompleted_and_addPaymentMethodURL_to_ShippingLabelAccountSettings() throws {
3523+
// Given
3524+
let sourceContainer = try startPersistentContainer("Model 123")
3525+
let sourceContext = sourceContainer.viewContext
3526+
3527+
let object = sourceContext.insert(entityName: "ShippingLabelAccountSettings", properties: [
3528+
"siteID": 123,
3529+
"canEditSettings": false,
3530+
"canManagePayments": false,
3531+
"isEmailReceiptsEnabled": false,
3532+
"lastSelectedPackageID": "",
3533+
"paperSize": "",
3534+
"selectedPaymentMethodID": 0,
3535+
"storeOwnerDisplayName": "",
3536+
"storeOwnerUsername": "",
3537+
"storeOwnerWpcomEmail": "",
3538+
"storeOwnerWpcomUsername": ""
3539+
])
3540+
try sourceContext.save()
3541+
3542+
// `lastOrderCompleted` and `addPaymentMethodURL` should not be present in model 122
3543+
XCTAssertNil(object.entity.attributesByName["lastOrderCompleted"], "Precondition. Attribute does not exist.")
3544+
XCTAssertNil(object.entity.attributesByName["addPaymentMethodURL"], "Precondition. Attribute does not exist.")
3545+
3546+
// When
3547+
let targetContainer = try migrate(sourceContainer, to: "Model 124")
3548+
3549+
// Then
3550+
let targetContext = targetContainer.viewContext
3551+
let migratedObject = try XCTUnwrap(targetContext.first(entityName: "ShippingLabelAccountSettings"))
3552+
3553+
// `lastOrderCompleted` should be present in model 124
3554+
XCTAssertNotNil(migratedObject.entity.attributesByName["lastOrderCompleted"])
3555+
3556+
// `addPaymentMethodURL` value should default as nil in model 124
3557+
let value = migratedObject.value(forKey: "addPaymentMethodURL") as? String
3558+
XCTAssertNil(value)
3559+
3560+
// `lastOrderCompleted` must be settable
3561+
migratedObject.setValue(true, forKey: "lastOrderCompleted")
3562+
try targetContext.save()
3563+
let updatedValue = migratedObject.value(forKey: "lastOrderCompleted") as? Bool
3564+
XCTAssertEqual(updatedValue, true)
3565+
3566+
// `addPaymentMethodURL` must be settable
3567+
migratedObject.setValue("https://example.com", forKey: "addPaymentMethodURL")
3568+
try targetContext.save()
3569+
let urlValue = migratedObject.value(forKey: "addPaymentMethodURL") as? String
3570+
XCTAssertEqual(urlValue, "https://example.com")
3571+
}
35213572
}
35223573

35233574
// MARK: - Persistent Store Setup and Migrations

0 commit comments

Comments
 (0)