Skip to content

Commit b75e4ef

Browse files
authored
Merge pull request #203 from Ecwid/product-filter-sections
Improvements for store profile's productFiltersSettings field
2 parents 9bbe27e + cede293 commit b75e4ef

9 files changed

Lines changed: 156 additions & 6 deletions

File tree

src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedStoreProfile.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fun FetchedStoreProfile.toUpdated(): UpdatedStoreProfile {
1717
zones = zones?.map(FetchedStoreProfile.Zone::toUpdated),
1818
businessRegistrationID = businessRegistrationID?.toUpdated(),
1919
legalPagesSettings = legalPagesSettings?.toUpdated(),
20+
productFiltersSettings = productFiltersSettings.toUpdated(),
2021
orderInvoiceSettings = orderInvoiceSettings?.toUpdated()
2122
)
2223
}
@@ -302,6 +303,21 @@ private fun FetchedStoreProfile.LegalPagesInfo.Display.toUpdated(): UpdatedStore
302303
}
303304
}
304305

306+
internal fun FetchedStoreProfile.ProductFiltersSettings.toUpdated(): UpdatedStoreProfile.ProductFiltersSettings {
307+
return UpdatedStoreProfile.ProductFiltersSettings(
308+
enabledInStorefront = enabledInStorefront,
309+
filterSections = filterSections.map { it.toUpdated() }
310+
)
311+
}
312+
313+
private fun FetchedStoreProfile.ProductFilterItem.toUpdated(): UpdatedStoreProfile.ProductFilterItem {
314+
return UpdatedStoreProfile.ProductFilterItem(
315+
name = name,
316+
type = type,
317+
enabled = enabled,
318+
)
319+
}
320+
305321
private fun FetchedStoreProfile.OrderInvoiceSettings.toUpdated(): UpdatedStoreProfile.OrderInvoiceSettings {
306322
return UpdatedStoreProfile.OrderInvoiceSettings(
307323
displayOrderInvoices = displayOrderInvoices,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ecwid.apiclient.v3.dto.profile.enums
2+
3+
enum class ProductFilterType {
4+
IN_STOCK,
5+
ON_SALE,
6+
PRICE,
7+
CATEGORIES,
8+
SEARCH,
9+
OPTION,
10+
ATTRIBUTE,
11+
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedStoreProfile.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ecwid.apiclient.v3.dto.profile.request
33
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind
55
import com.ecwid.apiclient.v3.dto.common.ProductCondition
6+
import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType
67
import com.ecwid.apiclient.v3.dto.profile.result.FetchedStoreProfile
78

89
data class UpdatedStoreProfile(
@@ -18,6 +19,7 @@ data class UpdatedStoreProfile(
1819
val zones: List<Zone>? = null,
1920
val businessRegistrationID: BusinessRegistrationID? = null,
2021
val legalPagesSettings: LegalPagesSettingsDetails? = null,
22+
val productFiltersSettings: ProductFiltersSettings? = null,
2123
val orderInvoiceSettings: OrderInvoiceSettings? = null
2224
) : ApiUpdatedDTO {
2325

@@ -226,6 +228,17 @@ data class UpdatedStoreProfile(
226228
}
227229
}
228230

231+
data class ProductFilterItem(
232+
val name: String? = null,
233+
val type: ProductFilterType = ProductFilterType.IN_STOCK,
234+
val enabled: Boolean = false,
235+
)
236+
237+
data class ProductFiltersSettings(
238+
val enabledInStorefront: Boolean = false,
239+
val filterSections: List<ProductFilterItem> = listOf(),
240+
)
241+
229242
data class OrderInvoiceSettings(
230243
val displayOrderInvoices: Boolean? = null,
231244
val attachInvoiceToOrderEmailNotifications: AttachValue? = null,

src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/result/FetchedStoreProfile.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ecwid.apiclient.v3.dto.profile.result
33
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
44
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
55
import com.ecwid.apiclient.v3.dto.common.ProductCondition
6+
import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType
67
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile
78
import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName
89

@@ -22,7 +23,7 @@ data class FetchedStoreProfile(
2223
val payment: PaymentInfo? = null,
2324
val featureToggles: List<FeatureTogglesInfo>? = null,
2425
val designSettings: DesignSettings? = null,
25-
val productFiltersSettings: ProductFiltersSettings? = null,
26+
val productFiltersSettings: ProductFiltersSettings = ProductFiltersSettings(),
2627
val fbMessengerSettings: FBMessengerSettings? = null,
2728
val orderInvoiceSettings: OrderInvoiceSettings? = null,
2829
val giftCardSettings: GiftCardSettings? = null,
@@ -726,8 +727,15 @@ data class FetchedStoreProfile(
726727
val showRootCategories: Boolean? = null,
727728
)
728729

730+
data class ProductFilterItem(
731+
val name: String? = null,
732+
val type: ProductFilterType = ProductFilterType.IN_STOCK,
733+
val enabled: Boolean = false,
734+
)
735+
729736
data class ProductFiltersSettings(
730-
val enabledInStorefront: Boolean? = null
737+
val enabledInStorefront: Boolean = false,
738+
val filterSections: List<ProductFilterItem> = listOf(),
731739
)
732740

733741
data class FBMessengerSettings(

src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.ecwid.apiclient.v3.dto.product.result.ProductsSearchResult
2828
import com.ecwid.apiclient.v3.dto.producttype.request.ProductTypeDeleteRequest
2929
import com.ecwid.apiclient.v3.dto.producttype.request.ProductTypesGetAllRequest
3030
import com.ecwid.apiclient.v3.dto.producttype.result.FetchedProductType
31+
import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType
3132
import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileUpdateRequest
3233
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile
3334
import com.ecwid.apiclient.v3.dto.variation.request.DeleteAllProductVariationsRequest
@@ -83,6 +84,46 @@ abstract class BaseEntityTest {
8384
automaticTaxEnabled = false,
8485
taxes = listOf(),
8586
pricesIncludeTax = false
87+
),
88+
productFiltersSettings = UpdatedStoreProfile.ProductFiltersSettings(
89+
enabledInStorefront = true,
90+
filterSections = listOf(
91+
UpdatedStoreProfile.ProductFilterItem(
92+
type = ProductFilterType.PRICE,
93+
enabled = false,
94+
),
95+
UpdatedStoreProfile.ProductFilterItem(
96+
type = ProductFilterType.IN_STOCK,
97+
enabled = true,
98+
),
99+
UpdatedStoreProfile.ProductFilterItem(
100+
type = ProductFilterType.ON_SALE,
101+
enabled = true,
102+
),
103+
UpdatedStoreProfile.ProductFilterItem(
104+
type = ProductFilterType.CATEGORIES,
105+
enabled = false,
106+
),
107+
UpdatedStoreProfile.ProductFilterItem(
108+
type = ProductFilterType.SEARCH,
109+
enabled = true,
110+
),
111+
UpdatedStoreProfile.ProductFilterItem(
112+
name = "Color",
113+
type = ProductFilterType.OPTION,
114+
enabled = true,
115+
),
116+
UpdatedStoreProfile.ProductFilterItem(
117+
name = "Brand",
118+
type = ProductFilterType.ATTRIBUTE,
119+
enabled = true,
120+
),
121+
UpdatedStoreProfile.ProductFilterItem(
122+
name = "UPC",
123+
type = ProductFilterType.ATTRIBUTE,
124+
enabled = true,
125+
),
126+
),
86127
)
87128
)
88129

src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.ecwid.apiclient.v3.entity
22

3+
import com.ecwid.apiclient.v3.converter.toUpdated
34
import com.ecwid.apiclient.v3.dto.common.ProductCondition
5+
import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType
46
import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileRequest
57
import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileUpdateRequest
68
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile
@@ -168,6 +170,10 @@ class StoreProfileTest : BaseEntityTest() {
168170
)
169171
)
170172
),
173+
productFiltersSettings = UpdatedStoreProfile.ProductFiltersSettings(
174+
enabledInStorefront = true,
175+
filterSections = createTestFilterSections(),
176+
),
171177
orderInvoiceSettings = UpdatedStoreProfile.OrderInvoiceSettings(
172178
displayOrderInvoices = true,
173179
attachInvoiceToOrderEmailNotifications = UpdatedStoreProfile.OrderInvoiceSettings.AttachValue.ATTACH_TO_ALL_EMAILS,
@@ -263,5 +269,54 @@ class StoreProfileTest : BaseEntityTest() {
263269
assertTrue(tikTokPixel.advancedMatching)
264270

265271
assertEquals(FetchedStoreProfile.VolumeUnit.L, formatsAndUnits.volumeUnit)
272+
273+
assertEquals(
274+
expectedProfile.productFiltersSettings,
275+
actualProfile.productFiltersSettings.toUpdated()
276+
)
266277
}
278+
279+
private fun createTestFilterSections() = listOf(
280+
UpdatedStoreProfile.ProductFilterItem(
281+
type = ProductFilterType.IN_STOCK,
282+
enabled = true,
283+
),
284+
UpdatedStoreProfile.ProductFilterItem(
285+
type = ProductFilterType.ON_SALE,
286+
enabled = true,
287+
),
288+
UpdatedStoreProfile.ProductFilterItem(
289+
type = ProductFilterType.PRICE,
290+
enabled = false,
291+
),
292+
UpdatedStoreProfile.ProductFilterItem(
293+
type = ProductFilterType.CATEGORIES,
294+
enabled = false,
295+
),
296+
UpdatedStoreProfile.ProductFilterItem(
297+
type = ProductFilterType.SEARCH,
298+
enabled = true,
299+
),
300+
UpdatedStoreProfile.ProductFilterItem(
301+
name = "Option 1",
302+
type = ProductFilterType.OPTION,
303+
enabled = true,
304+
),
305+
UpdatedStoreProfile.ProductFilterItem(
306+
name = "Option 2",
307+
type = ProductFilterType.OPTION,
308+
enabled = true,
309+
),
310+
UpdatedStoreProfile.ProductFilterItem(
311+
name = "Attribute 2",
312+
type = ProductFilterType.ATTRIBUTE,
313+
enabled = true,
314+
),
315+
UpdatedStoreProfile.ProductFilterItem(
316+
name = "Attribute 1",
317+
type = ProductFilterType.ATTRIBUTE,
318+
enabled = true,
319+
),
320+
)
321+
267322
}

src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(
208208
Ignored(FetchedStoreProfile::payment),
209209
Ignored(FetchedStoreProfile::featureToggles),
210210
Ignored(FetchedStoreProfile::designSettings),
211-
Ignored(FetchedStoreProfile::productFiltersSettings),
212211
Ignored(FetchedStoreProfile::fbMessengerSettings),
213212
Ignored(FetchedStoreProfile::giftCardSettings),
214213
ReadOnly(FetchedStoreProfile.Settings::googleProductCategoryName),

src/test/kotlin/com/ecwid/apiclient/v3/rule/NonnullPropertyRules.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.ecwid.apiclient.v3.dto.coupon.request.UpdatedCoupon
55
import com.ecwid.apiclient.v3.dto.customer.request.UpdatedCustomer
66
import com.ecwid.apiclient.v3.dto.customergroup.request.UpdatedCustomerGroup
77
import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct
8+
import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile
89
import com.ecwid.apiclient.v3.dto.storage.request.UpdatedStorageData
910
import com.ecwid.apiclient.v3.dto.variation.request.UpdatedVariation
1011
import com.ecwid.apiclient.v3.rule.NonnullPropertyRule.AllowNonnull
@@ -23,6 +24,7 @@ val nonnullPropertyRules: List<NonnullPropertyRule<*, *>> = listOf(
2324
AllowNonnull(UpdatedProduct.ProductOption.TextAreaOption::required),
2425
AllowNonnull(UpdatedProduct.ProductOption.TextFieldOption::required),
2526
AllowNonnull(UpdatedProduct.CustomPriceTier::value),
27+
2628
AllowNonnull(UpdatedStorageData::key),
2729
AllowNonnull(UpdatedStorageData::value),
2830

@@ -61,7 +63,12 @@ val nonnullPropertyRules: List<NonnullPropertyRule<*, *>> = listOf(
6163
IgnoreNonnull(UpdatedProduct.WholesalePrice::quantity),
6264

6365
IgnoreNonnull(UpdatedVariation.WholesalePrice::price),
64-
IgnoreNonnull(UpdatedVariation.WholesalePrice::quantity)
66+
IgnoreNonnull(UpdatedVariation.WholesalePrice::quantity),
67+
68+
AllowNonnull(UpdatedStoreProfile.ProductFilterItem::enabled),
69+
AllowNonnull(UpdatedStoreProfile.ProductFilterItem::type),
70+
AllowNonnull(UpdatedStoreProfile.ProductFiltersSettings::enabledInStorefront),
71+
AllowNonnull(UpdatedStoreProfile.ProductFiltersSettings::filterSections),
6572
)
6673

6774
sealed class NonnullPropertyRule<T, R>(

src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedStoreProfileRules.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ val fetchedStoreProfileNullablePropertyRules: List<NullablePropertyRule<*, *>> =
232232
IgnoreNullable(FetchedStoreProfile.PaymentOptionInfo::paymentProcessorId),
233233
IgnoreNullable(FetchedStoreProfile.PaymentOptionInfo::paymentProcessorTitle),
234234
AllowNullable(FetchedStoreProfile.PaymentOptionInfo::shippingSettings),
235-
IgnoreNullable(FetchedStoreProfile.ProductFiltersSettings::enabledInStorefront),
235+
AllowNullable(FetchedStoreProfile.ProductFilterItem::name),
236236
IgnoreNullable(FetchedStoreProfile::registrationAnswers),
237237
IgnoreNullable(FetchedStoreProfile.RegistrationAnswers::alreadySelling),
238238
IgnoreNullable(FetchedStoreProfile.RegistrationAnswers::facebook),
@@ -337,5 +337,5 @@ val fetchedStoreProfileNullablePropertyRules: List<NullablePropertyRule<*, *>> =
337337
IgnoreNullable(FetchedStoreProfile.Zone::postCodes),
338338
IgnoreNullable(FetchedStoreProfile.Zone::stateOrProvinceCodes),
339339
AllowNullable(FetchedStoreProfile.Settings::googleProductCategory),
340-
AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName)
340+
AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName),
341341
)

0 commit comments

Comments
 (0)