Skip to content

Commit

Permalink
Merge pull request #3117 from wordpress-mobile/issue/13061-integrate-…
Browse files Browse the repository at this point in the history
…api-change

[Woo POS][non-simple products] Integrate include_types parameter for products endpoint
  • Loading branch information
samiuelson authored Dec 9, 2024
2 parents d9a3dcb + 4ad2e36 commit 7cb4939
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,44 @@ class WCProductStoreTest {
assertThat(storedProduct?.product).isEqualTo(product)
assertThat(storedProduct?.metaData).isEqualTo(metadata)
}

@Test
fun `given include_type simple, then return type Simple` () {
assertThat(WCProductStore.IncludeType.fromValue("simple")).isEqualTo(WCProductStore.IncludeType.Simple)
}

@Test
fun `given include_type variable, then return type Variable` () {
assertThat(
WCProductStore.IncludeType.fromValue("variable")
).isEqualTo(WCProductStore.IncludeType.Variable)
}

@Test
fun `given include_type external, then return type External` () {
assertThat(
WCProductStore.IncludeType.fromValue("external")
).isEqualTo(WCProductStore.IncludeType.External)
}

@Test
fun `given include_type grouped, then return type Grouped` () {
assertThat(
WCProductStore.IncludeType.fromValue("grouped")
).isEqualTo(WCProductStore.IncludeType.Grouped)
}

@Test
fun `given include_type empty, then return type null` () {
assertThat(
WCProductStore.IncludeType.fromValue("")
).isNull()
}

@Test
fun `given include_type invalid, then return type null` () {
assertThat(
WCProductStore.IncludeType.fromValue("invalid")
).isNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ class ProductRestClient @Inject constructor(
excludedProductIds: List<Long>? = null,
searchQuery: String? = null,
skuSearchOptions: SkuSearchOptions = SkuSearchOptions.Disabled,
filterOptions: Map<ProductFilterOption, String>? = null
filterOptions: Map<ProductFilterOption, String>? = null,
includeTypes: List<WCProductStore.IncludeType> = emptyList()
): WooPayload<List<ProductWithMetaData>> {
val params = buildProductParametersMap(
pageSize = pageSize,
Expand All @@ -568,7 +569,8 @@ class ProductRestClient @Inject constructor(
skuSearchOptions = skuSearchOptions,
includedProductIds = includedProductIds,
excludedProductIds = excludedProductIds,
filterOptions = filterOptions
filterOptions = filterOptions,
includeTypes = includeTypes,
)

val url = WOOCOMMERCE.products.pathV3
Expand Down Expand Up @@ -610,7 +612,8 @@ class ProductRestClient @Inject constructor(
globalUniqueIdSearchQuery: String? = null,
includedProductIds: List<Long>? = null,
excludedProductIds: List<Long>? = null,
filterOptions: Map<ProductFilterOption, String>? = null
filterOptions: Map<ProductFilterOption, String>? = null,
includeTypes: List<WCProductStore.IncludeType> = emptyList()
): MutableMap<String, String> {
fun ProductSorting.asOrderByParameter() = when (this) {
TITLE_ASC, TITLE_DESC -> "title"
Expand All @@ -626,7 +629,8 @@ class ProductRestClient @Inject constructor(
"per_page" to pageSize.toString(),
"orderby" to sortType.asOrderByParameter(),
"order" to sortType.asSortOrderParameter(),
"offset" to offset.toString()
"offset" to offset.toString(),
"include_types" to includeTypes.joinToString(",") { it.value }
)

includedProductIds?.let { includedIds ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ class WCProductStore @Inject constructor(
const val VARIATIONS_CREATION_LIMIT = 100
}

sealed class IncludeType(val value: String) {
data object Simple : IncludeType("simple")
data object Variable : IncludeType("variable")
data object External : IncludeType("external")
data object Grouped : IncludeType("grouped")

companion object {
fun fromValue(value: String): IncludeType? = when (value) {
"simple" -> Simple
"variable" -> Variable
"external" -> External
"grouped" -> Grouped
else -> null
}
}
}

/**
* Defines the filter options currently supported in the app
*/
Expand Down Expand Up @@ -1617,6 +1634,7 @@ class WCProductStore @Inject constructor(
includedProductIds: List<Long> = emptyList(),
excludedProductIds: List<Long> = emptyList(),
filterOptions: Map<ProductFilterOption, String> = emptyMap(),
includeTypes: List<IncludeType> = emptyList(),
forceRefresh: Boolean = true
): WooResult<Boolean> {
return coroutineEngine.withDefaultContext(API, this, "fetchProducts") {
Expand All @@ -1627,7 +1645,8 @@ class WCProductStore @Inject constructor(
sortType = sortType,
includedProductIds = includedProductIds,
excludedProductIds = excludedProductIds,
filterOptions = filterOptions
filterOptions = filterOptions,
includeTypes = includeTypes,
)
when {
response.isError -> WooResult(response.error)
Expand Down

0 comments on commit 7cb4939

Please sign in to comment.