Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 7cb4939

Browse files
authored
Merge pull request #3117 from wordpress-mobile/issue/13061-integrate-api-change
[Woo POS][non-simple products] Integrate include_types parameter for products endpoint
2 parents d9a3dcb + 4ad2e36 commit 7cb4939

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

example/src/test/java/org/wordpress/android/fluxc/wc/product/WCProductStoreTest.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,4 +830,44 @@ class WCProductStoreTest {
830830
assertThat(storedProduct?.product).isEqualTo(product)
831831
assertThat(storedProduct?.metaData).isEqualTo(metadata)
832832
}
833+
834+
@Test
835+
fun `given include_type simple, then return type Simple` () {
836+
assertThat(WCProductStore.IncludeType.fromValue("simple")).isEqualTo(WCProductStore.IncludeType.Simple)
837+
}
838+
839+
@Test
840+
fun `given include_type variable, then return type Variable` () {
841+
assertThat(
842+
WCProductStore.IncludeType.fromValue("variable")
843+
).isEqualTo(WCProductStore.IncludeType.Variable)
844+
}
845+
846+
@Test
847+
fun `given include_type external, then return type External` () {
848+
assertThat(
849+
WCProductStore.IncludeType.fromValue("external")
850+
).isEqualTo(WCProductStore.IncludeType.External)
851+
}
852+
853+
@Test
854+
fun `given include_type grouped, then return type Grouped` () {
855+
assertThat(
856+
WCProductStore.IncludeType.fromValue("grouped")
857+
).isEqualTo(WCProductStore.IncludeType.Grouped)
858+
}
859+
860+
@Test
861+
fun `given include_type empty, then return type null` () {
862+
assertThat(
863+
WCProductStore.IncludeType.fromValue("")
864+
).isNull()
865+
}
866+
867+
@Test
868+
fun `given include_type invalid, then return type null` () {
869+
assertThat(
870+
WCProductStore.IncludeType.fromValue("invalid")
871+
).isNull()
872+
}
833873
}

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/ProductRestClient.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ class ProductRestClient @Inject constructor(
558558
excludedProductIds: List<Long>? = null,
559559
searchQuery: String? = null,
560560
skuSearchOptions: SkuSearchOptions = SkuSearchOptions.Disabled,
561-
filterOptions: Map<ProductFilterOption, String>? = null
561+
filterOptions: Map<ProductFilterOption, String>? = null,
562+
includeTypes: List<WCProductStore.IncludeType> = emptyList()
562563
): WooPayload<List<ProductWithMetaData>> {
563564
val params = buildProductParametersMap(
564565
pageSize = pageSize,
@@ -568,7 +569,8 @@ class ProductRestClient @Inject constructor(
568569
skuSearchOptions = skuSearchOptions,
569570
includedProductIds = includedProductIds,
570571
excludedProductIds = excludedProductIds,
571-
filterOptions = filterOptions
572+
filterOptions = filterOptions,
573+
includeTypes = includeTypes,
572574
)
573575

574576
val url = WOOCOMMERCE.products.pathV3
@@ -610,7 +612,8 @@ class ProductRestClient @Inject constructor(
610612
globalUniqueIdSearchQuery: String? = null,
611613
includedProductIds: List<Long>? = null,
612614
excludedProductIds: List<Long>? = null,
613-
filterOptions: Map<ProductFilterOption, String>? = null
615+
filterOptions: Map<ProductFilterOption, String>? = null,
616+
includeTypes: List<WCProductStore.IncludeType> = emptyList()
614617
): MutableMap<String, String> {
615618
fun ProductSorting.asOrderByParameter() = when (this) {
616619
TITLE_ASC, TITLE_DESC -> "title"
@@ -626,7 +629,8 @@ class ProductRestClient @Inject constructor(
626629
"per_page" to pageSize.toString(),
627630
"orderby" to sortType.asOrderByParameter(),
628631
"order" to sortType.asSortOrderParameter(),
629-
"offset" to offset.toString()
632+
"offset" to offset.toString(),
633+
"include_types" to includeTypes.joinToString(",") { it.value }
630634
)
631635

632636
includedProductIds?.let { includedIds ->

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/store/WCProductStore.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ class WCProductStore @Inject constructor(
8181
const val VARIATIONS_CREATION_LIMIT = 100
8282
}
8383

84+
sealed class IncludeType(val value: String) {
85+
data object Simple : IncludeType("simple")
86+
data object Variable : IncludeType("variable")
87+
data object External : IncludeType("external")
88+
data object Grouped : IncludeType("grouped")
89+
90+
companion object {
91+
fun fromValue(value: String): IncludeType? = when (value) {
92+
"simple" -> Simple
93+
"variable" -> Variable
94+
"external" -> External
95+
"grouped" -> Grouped
96+
else -> null
97+
}
98+
}
99+
}
100+
84101
/**
85102
* Defines the filter options currently supported in the app
86103
*/
@@ -1617,6 +1634,7 @@ class WCProductStore @Inject constructor(
16171634
includedProductIds: List<Long> = emptyList(),
16181635
excludedProductIds: List<Long> = emptyList(),
16191636
filterOptions: Map<ProductFilterOption, String> = emptyMap(),
1637+
includeTypes: List<IncludeType> = emptyList(),
16201638
forceRefresh: Boolean = true
16211639
): WooResult<Boolean> {
16221640
return coroutineEngine.withDefaultContext(API, this, "fetchProducts") {
@@ -1627,7 +1645,8 @@ class WCProductStore @Inject constructor(
16271645
sortType = sortType,
16281646
includedProductIds = includedProductIds,
16291647
excludedProductIds = excludedProductIds,
1630-
filterOptions = filterOptions
1648+
filterOptions = filterOptions,
1649+
includeTypes = includeTypes,
16311650
)
16321651
when {
16331652
response.isError -> WooResult(response.error)

0 commit comments

Comments
 (0)