Skip to content

Commit 01a2f9f

Browse files
committed
Fetch all variations from the ProductsViewController
1 parent 951145f commit 01a2f9f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,7 @@ private extension ProductVariationsViewController {
612612
case .single:
613613
self.createVariation()
614614
case .all:
615-
// TODO: Start generate all variations flow
616-
break
615+
self.generateAllVariations()
617616
}
618617

619618
}
@@ -692,6 +691,16 @@ extension ProductVariationsViewController: SyncingCoordinatorDelegate {
692691
}
693692
}
694693
}
694+
695+
/// Generates all possible variations for the product attibutes.
696+
///
697+
private func generateAllVariations() {
698+
viewModel.generateAllVariations(for: product)
699+
// TODO:
700+
// - Show Loading Indicator
701+
// - Alert if there are more than 100 variations to create
702+
// - Hide Loading Indicator
703+
}
695704
}
696705

697706
// MARK: - Finite State Machine Management

WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewModel.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ final class ProductVariationsViewModel {
2525
useCase.generateVariation(onCompletion: onCompletion)
2626
}
2727

28+
/// Generates all missing variations for a product. Up to 100 variations.
29+
///
30+
func generateAllVariations(for product: Product) {
31+
let action = ProductVariationAction.synchronizeAllProductVariations(siteID: product.siteID, productID: product.productID) { result in
32+
// Temp
33+
let fetched = ServiceLocator.storageManager.viewStorage.loadProductVariations(siteID: product.siteID, productID: product.productID)
34+
print("Synchronized \(fetched?.count ?? 0) variations")
35+
}
36+
stores.dispatch(action)
37+
38+
// TODO:
39+
// - Generate all variations locally
40+
// - Substract already created variations
41+
// - Alert if there are more than 100 variations to create
42+
// - Create variations remotely
43+
}
44+
2845
/// Updates the internal `formType` to `edit` if the given product exists remotely and previous formType was `.add`
2946
///
3047
func updatedFormTypeIfNeeded(newProduct: Product) {

Yosemite/Yosemite/Stores/ProductVariationStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private extension ProductVariationStore {
6666
/// Synchronizes all the product reviews associated with a given Site ID (if any!).
6767
///
6868
func synchronizeAllProductVariations(siteID: Int64, productID: Int64, onCompletion: @escaping (Result<Void, Error>) -> Void) {
69-
let maxPageSize = 30 // API only allows to fetch a max of 100 variations at a time
69+
let maxPageSize = 100 // API only allows to fetch a max of 100 variations at a time
7070
recursivelySyncAllVariations(siteID: siteID,
7171
productID: productID,
7272
pageNumber: Default.firstPageNumber,

0 commit comments

Comments
 (0)