-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Allow item list switch between Products and Coupons #15366
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
iamgabrielma
merged 23 commits into
trunk
from
task/15346-pos-allow-switch-product-vs-coupon-list
Mar 25, 2025
Merged
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
18c84df
Return coupons as PagedItems, hook to item list
iamgabrielma b888782
Make providePointOfSaleCoupons throwable
iamgabrielma a37563b
switch coupons feature flag to false
iamgabrielma 35d6193
Make CouponCardView
iamgabrielma 7d9305f
Remove unnecessary state. Collapse func duplication
iamgabrielma 9f5c228
lint
iamgabrielma 6d7dfa9
Invert fetch logic, make products first case
iamgabrielma b39973e
lint
iamgabrielma a5f58da
make test target compile
iamgabrielma e8fba94
Merge branch 'trunk' into task/15346-pos-allow-switch-product-vs-coup…
iamgabrielma 9523774
Make PointOfSaleCouponsController
iamgabrielma a10bdf1
Create PointOfSaleCouponService
iamgabrielma ad84397
Delete coupon-specific logic from itemservice
iamgabrielma 1aa3efc
Inject couponsController into POS entry point
iamgabrielma 2b30a41
Hook UI item type selection with switch in aggregate model
iamgabrielma d8945f5
Inject couponsController in aggregate model and update item view stat…
iamgabrielma 7462a04
Hook switching current viewstate to different controller
iamgabrielma 4b07017
lint
iamgabrielma 9d73d73
Revert dummy CouponCardView
iamgabrielma f716199
cleanup unused
iamgabrielma 7417b66
Merge branch 'trunk' into task/15346-pos-allow-switch-product-vs-coup…
iamgabrielma 5a26eb1
ammend merge conflict
iamgabrielma 249f75f
remove unnecessary prop
iamgabrielma 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 |
|---|---|---|
|
|
@@ -6,6 +6,11 @@ import enum Yosemite.PointOfSaleItemServiceError | |
| import struct Yosemite.POSVariableParentProduct | ||
| import class Yosemite.Store | ||
|
|
||
| enum POSItemType { | ||
| case products | ||
| case coupons | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| protocol PointOfSaleItemsControllerProtocol { | ||
| var itemsViewState: ItemsViewState { get } | ||
|
|
@@ -15,6 +20,8 @@ protocol PointOfSaleItemsControllerProtocol { | |
| func refreshItems(base: ItemListBaseItem) async | ||
| /// Loads the next page of items for a given base item. | ||
| func loadNextItems(base: ItemListBaseItem) async | ||
| /// Toggles between item types | ||
| func toggleItemType() async | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
|
|
@@ -25,6 +32,7 @@ protocol PointOfSaleItemsControllerProtocol { | |
| private let paginationTracker: AsyncPaginationTracker | ||
| private var childPaginationTrackers: [POSItem: AsyncPaginationTracker] = [:] | ||
| private let itemProvider: PointOfSaleItemServiceProtocol | ||
| private var itemType: POSItemType = .products | ||
|
||
|
|
||
| init(itemProvider: PointOfSaleItemServiceProtocol) { | ||
| self.itemProvider = itemProvider | ||
|
|
@@ -42,6 +50,11 @@ protocol PointOfSaleItemsControllerProtocol { | |
| await loadFirstPage(base: base) | ||
| } | ||
|
|
||
| func toggleItemType() async { | ||
| itemType = (itemType == .products) ? .coupons : .products | ||
| await loadFirstPage(base: .root) | ||
| } | ||
|
|
||
| @MainActor | ||
| private func loadFirstPage(base: ItemListBaseItem) async { | ||
| switch base { | ||
|
|
@@ -158,14 +171,6 @@ protocol PointOfSaleItemsControllerProtocol { | |
| } | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| private extension PointOfSaleItemsController { | ||
| func loadPointOfSaleCoupons() { | ||
| let posCoupons = itemProvider.providePointOfSaleCoupons() | ||
| debugPrint(posCoupons) | ||
| } | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| private extension PointOfSaleItemsController { | ||
| func setLoadingState(base: ItemListBaseItem) { | ||
|
|
@@ -201,7 +206,10 @@ private extension PointOfSaleItemsController { | |
| @MainActor | ||
| func fetchItems(pageNumber: Int, appendToExistingItems: Bool = true) async throws -> Bool { | ||
| do { | ||
| let pagedItems = try await itemProvider.providePointOfSaleItems(pageNumber: pageNumber) | ||
| let pagedItems = itemType == .products | ||
| ? try await itemProvider.providePointOfSaleItems(pageNumber: pageNumber) | ||
| : try itemProvider.providePointOfSaleCoupons() | ||
|
|
||
iamgabrielma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let newItems = pagedItems.items | ||
| var allItems = appendToExistingItems ? itemsViewState.itemsStack.root.items : [] | ||
| let uniqueNewItems = newItems.filter { newItem in | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -92,6 +92,11 @@ protocol PointOfSaleAggregateModelProtocol { | |
| // MARK: - ItemList | ||
| @available(iOS 17.0, *) | ||
| extension PointOfSaleAggregateModel { | ||
| @MainActor | ||
| func toggleItemType() async { | ||
iamgabrielma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await itemsController.toggleItemType() | ||
| } | ||
|
|
||
| @MainActor | ||
| func loadItems(base: ItemListBaseItem) async { | ||
| await itemsController.loadItems(base: base) | ||
|
|
@@ -120,6 +125,7 @@ private extension POSItem { | |
| case .variableParentProduct: | ||
| return nil | ||
| case .coupon: | ||
| debugPrint("Not implemented. TODO: Make POSCoupon POSOrderable") | ||
iamgabrielma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return nil | ||
| } | ||
| } | ||
|
|
||
17 changes: 17 additions & 0 deletions
17
WooCommerce/Classes/POS/Presentation/Item Selector/CouponCardView.swift
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,17 @@ | ||
| import SwiftUI | ||
| import struct Yosemite.POSCoupon | ||
|
|
||
| struct CouponCardView: View { | ||
| private let coupon: POSCoupon | ||
|
|
||
| init(coupon: POSCoupon) { | ||
| self.coupon = coupon | ||
| } | ||
|
|
||
| var body: some View { | ||
| HStack { | ||
| Text(coupon.id.uuidString) | ||
| Text(coupon.couponID.description) | ||
| } | ||
| } | ||
| } |
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
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.

Uh oh!
There was an error while loading. Please reload this page.