Skip to content

Commit bdf3a9d

Browse files
committed
Remove POSCartCouponItem
1 parent 7f1b730 commit bdf3a9d

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

WooCommerce/Classes/POS/Controllers/PointOfSaleOrderController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import struct Yosemite.Order
77
import struct Yosemite.PaymentGateway
88
import struct Yosemite.POSCart
99
import struct Yosemite.POSCartItem
10-
import struct Yosemite.POSCartCouponItem
10+
import struct Yosemite.POSCoupon
1111
import enum Yosemite.OrderAction
1212
import enum Yosemite.OrderUpdateField
1313
import class WooFoundation.CurrencyFormatter
@@ -255,7 +255,7 @@ extension PointOfSaleOrderController {
255255
private extension POSCart {
256256
init(cart: Cart) {
257257
let items = cart.items.map { POSCartItem(item: $0.item, quantity: Decimal($0.quantity)) }
258-
let coupons = cart.coupons.map { POSCartCouponItem(code: $0.code) }
258+
let coupons = cart.coupons.map { POSCoupon(id: $0.id, code: $0.code) }
259259
self.init(items: items, coupons: coupons)
260260
}
261261
}

Yosemite/Yosemite/Tools/POS/POSCart.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Foundation
55

66
public struct POSCart {
77
public let items: [POSCartItem]
8-
public let coupons: [POSCartCouponItem]
8+
public let coupons: [POSCoupon]
99

10-
public init(items: [POSCartItem] = [], coupons: [POSCartCouponItem] = []) {
10+
public init(items: [POSCartItem] = [], coupons: [POSCoupon] = []) {
1111
self.items = items
1212
self.coupons = coupons
1313
}
@@ -23,14 +23,6 @@ public struct POSCartItem {
2323
}
2424
}
2525

26-
public struct POSCartCouponItem {
27-
public let code: String
28-
29-
public init(code: String) {
30-
self.code = code
31-
}
32-
}
33-
3426
public extension POSCart {
3527
func matches(order: Order?) -> Bool {
3628
return items.matches(order: order) && coupons.matches(order: order)
@@ -101,7 +93,7 @@ extension [POSCartItem] {
10193
}
10294
}
10395

104-
extension [POSCartCouponItem] {
96+
extension [POSCoupon] {
10597
func matches(order: Order?) -> Bool {
10698
guard let order else {
10799
return self.isEmpty

Yosemite/Yosemite/Tools/POS/POSOrderService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private extension POSOrderService {
9898
return order
9999
}
100100

101-
func updateCoupons(_ coupons: [POSCartCouponItem], on order: Order) -> Order {
101+
func updateCoupons(_ coupons: [POSCoupon], on order: Order) -> Order {
102102
// Get coupon codes from cart
103103
let cartCouponCodes = Set(coupons.map { $0.code })
104104

Yosemite/YosemiteTests/Tools/POS/POSOrderServiceTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct POSOrderServiceTests {
144144
// When
145145
let cart = POSCart(
146146
items: [makePOSCartItem(productID: 100, quantity: 1)],
147-
coupons: [.init(code: "SAVE10")]
147+
coupons: [.init(id: UUID(), code: "SAVE10")]
148148
)
149149
_ = try await sut.syncOrder(cart: cart, order: order, currency: .USD)
150150

@@ -186,9 +186,9 @@ struct POSOrderServiceTests {
186186
let cart = POSCart(
187187
items: [makePOSCartItem(productID: 100, quantity: 1)],
188188
coupons: [
189-
.init(code: "KEEP1"),
190-
.init(code: "NEW1"),
191-
.init(code: "NEW2")
189+
.init(id: UUID(), code: "KEEP1"),
190+
.init(id: UUID(), code: "NEW1"),
191+
.init(id: UUID(), code: "NEW2")
192192
]
193193
)
194194
_ = try await sut.syncOrder(cart: cart, order: order, currency: .USD)
@@ -220,7 +220,7 @@ struct POSOrderServiceTests {
220220
// When
221221
let cart = POSCart(
222222
items: [makePOSCartItem(productID: 100, quantity: 1)],
223-
coupons: [.init(code: "KEEP1")] // Same coupon in cart
223+
coupons: [.init(id: UUID(), code: "KEEP1")] // Same coupon in cart
224224
)
225225
_ = try await sut.syncOrder(cart: cart, order: order, currency: .USD)
226226

0 commit comments

Comments
 (0)