Skip to content

Commit

Permalink
Merge pull request #3124 from wordpress-mobile/issue/13206-add-status…
Browse files Browse the repository at this point in the history
…-for-variations-endpoint

Pass in status filter options for variations endpoint
  • Loading branch information
samiuelson authored Jan 10, 2025
2 parents 8555e9e + 43bea2c commit 0264533
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ class ProductRestClient @Inject constructor(
offset: Int,
includedVariationIds: List<Long> = emptyList(),
searchQuery: String? = null,
excludedVariationIds: List<Long> = emptyList()
excludedVariationIds: List<Long> = emptyList(),
filterOptions: Map<WCProductStore.VariationFilterOption, String>? = null,
): WooPayload<List<WCProductVariationModel>> {
val params = mutableMapOf(
"per_page" to pageSize.toString(),
Expand All @@ -950,6 +951,10 @@ class ProductRestClient @Inject constructor(
.putIfNotEmpty("include" to includedVariationIds.map { it }.joinToString())
.putIfNotEmpty("exclude" to excludedVariationIds.map { it }.joinToString())

filterOptions?.let { options ->
params.putAll(options.map { it.key.toString() to it.value })
}

val url = WOOCOMMERCE.products.id(productId).variations.pathV3

val response = wooNetwork.executeGetGsonRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class WCProductStore @Inject constructor(
override fun toString() = name.lowercase(Locale.US)
}

enum class VariationFilterOption {
STATUS;

override fun toString() = name.lowercase(Locale.US)
}

enum class SkuSearchOptions {
Disabled, ExactSearch, PartialMatch
}
Expand Down Expand Up @@ -1754,7 +1760,8 @@ class WCProductStore @Inject constructor(
offset: Int = 0,
pageSize: Int = DEFAULT_PRODUCT_VARIATIONS_PAGE_SIZE,
includedVariationIds: List<Long> = emptyList(),
excludedVariationIds: List<Long> = emptyList()
excludedVariationIds: List<Long> = emptyList(),
filterOptions: Map<VariationFilterOption, String>? = null,
): WooResult<Boolean> {
return coroutineEngine.withDefaultContext(API, this, "fetchProductVariations") {
val response = wcProductRestClient.fetchProductVariationsWithSyncRequest(
Expand All @@ -1763,7 +1770,8 @@ class WCProductStore @Inject constructor(
offset = offset,
pageSize = pageSize,
includedVariationIds = includedVariationIds,
excludedVariationIds = excludedVariationIds
excludedVariationIds = excludedVariationIds,
filterOptions = filterOptions
)
when {
response.isError -> WooResult(response.error)
Expand Down

0 comments on commit 0264533

Please sign in to comment.