-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Coupons: Add Coupon(s) to Cart (dummy UI) #15407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3b1754f
Create Cart struct to support both Products and Coupons
staskus d3d1f1a
Use Cart instead of CartItems in PointOfSaleOrderController
staskus f293ea4
Update PointOfSaleAggregateModel to use Cart
staskus 34bea54
Update CartView to use Cart
staskus 11e49a9
Add CouponRowView with dummy design for displaying coupon in Cart
staskus d5563c2
Add dummy coupons to CartView
staskus fac9b49
Use coupon code in POSCoupon
staskus 61e3423
Insert coupons at coupons start index
staskus 94d203a
Rename CartProductItem back to CartItem, remove the protocol
staskus d888004
Add Cart isNotEmpty
staskus 26b4ece
Create a separate cart section and hide it behind the feature flag
staskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import Foundation | ||
| import protocol Yosemite.POSOrderableItem | ||
| import enum Yosemite.POSItem | ||
|
|
||
| struct Cart { | ||
| var items: [CartItem] = [] | ||
| var coupons: [CartCouponItem] = [] | ||
| } | ||
|
|
||
| struct CartItem { | ||
| let id: UUID | ||
| let item: POSOrderableItem | ||
| let title: String | ||
| let subtitle: String? | ||
| let quantity: Int | ||
| } | ||
|
|
||
| struct CartCouponItem { | ||
| let id: UUID | ||
| let code: String | ||
| } | ||
|
|
||
| // MARK: - Helper Methods | ||
|
|
||
| extension Cart { | ||
| mutating func add(_ posItem: POSItem) { | ||
| switch posItem { | ||
| case .simpleProduct(let simpleProduct): | ||
| let productItem = CartItem(id: UUID(), item: simpleProduct, title: simpleProduct.name, subtitle: nil, quantity: 1) | ||
| items.insert(productItem, at: items.startIndex) | ||
| case .variation(let variation): | ||
| let productItem = CartItem(id: UUID(), item: variation, title: variation.parentProductName, subtitle: variation.name, quantity: 1) | ||
| items.insert(productItem, at: items.startIndex) | ||
| case .variableParentProduct: | ||
| return | ||
| case .coupon(let coupon): | ||
| let couponItem = CartCouponItem(id: UUID(), code: coupon.code) | ||
| coupons.insert(couponItem, at: coupons.startIndex) | ||
| } | ||
| } | ||
|
|
||
| mutating func remove(_ cartItem: CartItem) { | ||
| items.removeAll { $0.id == cartItem.id } | ||
| } | ||
|
|
||
| mutating func remove(_ cartCouponItem: CartCouponItem) { | ||
| coupons.removeAll { $0.id == cartCouponItem.id } | ||
| } | ||
|
|
||
| mutating func removeAll() { | ||
| items.removeAll() | ||
| coupons.removeAll() | ||
| } | ||
|
|
||
| var isEmpty: Bool { | ||
| items.isEmpty && coupons.isEmpty | ||
| } | ||
|
|
||
| var isNotEmpty: Bool { | ||
| return !isEmpty | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import SwiftUI | ||
|
|
||
| struct CouponRowView: View { | ||
| private let couponItem: CartCouponItem | ||
| private let onItemRemoveTapped: (() -> Void)? | ||
|
|
||
| @ScaledMetric private var scale: CGFloat = 1.0 | ||
|
|
||
| init(couponItem: CartCouponItem, onItemRemoveTapped: (() -> Void)? = nil) { | ||
| self.couponItem = couponItem | ||
| self.onItemRemoveTapped = onItemRemoveTapped | ||
| } | ||
|
|
||
| var body: some View { | ||
| HStack(spacing: Constants.horizontalElementSpacing) { | ||
| Rectangle() | ||
| .foregroundColor(.posSurfaceDim) | ||
| .overlay { | ||
| Text(Image(systemName: "tag.square.fill")) | ||
| .font(.posButtonSymbolLarge) | ||
| .foregroundColor(.posOnSurfaceVariantLowest) | ||
| } | ||
| .frame(width: Constants.couponCardSize, height: Constants.couponCardSize) | ||
|
|
||
| VStack(alignment: .leading) { | ||
| Text(couponItem.code) | ||
| .foregroundColor(PointOfSaleItemListCardConstants.titleColor) | ||
| .font(Constants.itemTitleFont) | ||
| } | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| if let onItemRemoveTapped { | ||
| Button(action: { | ||
| onItemRemoveTapped() | ||
| }, label: { | ||
| Text(Image(systemName: "xmark.circle")) | ||
| .font(.posButtonSymbolMedium) | ||
| }) | ||
| .foregroundColor(Color.posOnSurfaceVariantLowest) | ||
| } | ||
| } | ||
| .padding(.trailing, Constants.cardContentHorizontalPadding) | ||
| .frame(maxWidth: .infinity, idealHeight: Constants.couponCardSize * scale) | ||
| .background(Color.posSurfaceContainerLowest) | ||
| .posItemCardBorderStyles() | ||
| .padding(.horizontal, Constants.horizontalPadding) | ||
| } | ||
| } | ||
|
|
||
| private extension CouponRowView { | ||
| enum Constants { | ||
| static let couponCardSize: CGFloat = 96 | ||
| static let horizontalPadding: CGFloat = POSPadding.medium | ||
| static let horizontalElementSpacing: CGFloat = POSSpacing.medium | ||
| static let cardContentHorizontalPadding: CGFloat = POSPadding.medium | ||
| static let itemTitleFont: POSFontStyle = .posBodySmallBold | ||
| } | ||
| } | ||
|
|
||
| #if DEBUG | ||
| @available(iOS 17.0, *) | ||
| #Preview(traits: .sizeThatFitsLayout) { | ||
| CouponRowView(couponItem: CartCouponItem(id: UUID(), code: "10-Discount")) {} | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯