Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -534,7 +534,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 @@ -544,7 +545,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 @@ -585,7 +587,8 @@ class ProductRestClient @Inject constructor(
skuSearchOptions: SkuSearchOptions,
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 @@ -601,7 +604,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 @@ -1586,6 +1603,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 @@ -1596,7 +1614,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
Loading