diff --git a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt index c12d71b49f..c79ad951ea 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt @@ -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() + } } diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt index 9e34ac9261..5dc0bbc8bc 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt @@ -558,7 +558,8 @@ class ProductRestClient @Inject constructor( excludedProductIds: List? = null, searchQuery: String? = null, skuSearchOptions: SkuSearchOptions = SkuSearchOptions.Disabled, - filterOptions: Map? = null + filterOptions: Map? = null, + includeTypes: List = emptyList() ): WooPayload> { val params = buildProductParametersMap( pageSize = pageSize, @@ -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 @@ -610,7 +612,8 @@ class ProductRestClient @Inject constructor( globalUniqueIdSearchQuery: String? = null, includedProductIds: List? = null, excludedProductIds: List? = null, - filterOptions: Map? = null + filterOptions: Map? = null, + includeTypes: List = emptyList() ): MutableMap { fun ProductSorting.asOrderByParameter() = when (this) { TITLE_ASC, TITLE_DESC -> "title" @@ -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 -> diff --git a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt index be31af2439..f6241302b2 100644 --- a/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt +++ b/plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt @@ -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 */ @@ -1617,6 +1634,7 @@ class WCProductStore @Inject constructor( includedProductIds: List = emptyList(), excludedProductIds: List = emptyList(), filterOptions: Map = emptyMap(), + includeTypes: List = emptyList(), forceRefresh: Boolean = true ): WooResult { return coroutineEngine.withDefaultContext(API, this, "fetchProducts") { @@ -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)