diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedStoreProfile.kt b/src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedStoreProfile.kt index 72e209ac3..cdedadc15 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedStoreProfile.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/converter/FetchedStoreProfile.kt @@ -17,6 +17,7 @@ fun FetchedStoreProfile.toUpdated(): UpdatedStoreProfile { zones = zones?.map(FetchedStoreProfile.Zone::toUpdated), businessRegistrationID = businessRegistrationID?.toUpdated(), legalPagesSettings = legalPagesSettings?.toUpdated(), + productFiltersSettings = productFiltersSettings.toUpdated(), orderInvoiceSettings = orderInvoiceSettings?.toUpdated() ) } @@ -302,6 +303,21 @@ private fun FetchedStoreProfile.LegalPagesInfo.Display.toUpdated(): UpdatedStore } } +internal fun FetchedStoreProfile.ProductFiltersSettings.toUpdated(): UpdatedStoreProfile.ProductFiltersSettings { + return UpdatedStoreProfile.ProductFiltersSettings( + enabledInStorefront = enabledInStorefront, + filterSections = filterSections.map { it.toUpdated() } + ) +} + +private fun FetchedStoreProfile.ProductFilterItem.toUpdated(): UpdatedStoreProfile.ProductFilterItem { + return UpdatedStoreProfile.ProductFilterItem( + name = name, + type = type, + enabled = enabled, + ) +} + private fun FetchedStoreProfile.OrderInvoiceSettings.toUpdated(): UpdatedStoreProfile.OrderInvoiceSettings { return UpdatedStoreProfile.OrderInvoiceSettings( displayOrderInvoices = displayOrderInvoices, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/ProductFilterType.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/ProductFilterType.kt new file mode 100644 index 000000000..913bbb373 --- /dev/null +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/enums/ProductFilterType.kt @@ -0,0 +1,11 @@ +package com.ecwid.apiclient.v3.dto.profile.enums + +enum class ProductFilterType { + IN_STOCK, + ON_SALE, + PRICE, + CATEGORIES, + SEARCH, + OPTION, + ATTRIBUTE, +} diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedStoreProfile.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedStoreProfile.kt index 5fa3da8c3..5c41a00cf 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedStoreProfile.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/request/UpdatedStoreProfile.kt @@ -3,6 +3,7 @@ package com.ecwid.apiclient.v3.dto.profile.request import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO import com.ecwid.apiclient.v3.dto.common.ApiUpdatedDTO.ModifyKind import com.ecwid.apiclient.v3.dto.common.ProductCondition +import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType import com.ecwid.apiclient.v3.dto.profile.result.FetchedStoreProfile data class UpdatedStoreProfile( @@ -18,6 +19,7 @@ data class UpdatedStoreProfile( val zones: List? = null, val businessRegistrationID: BusinessRegistrationID? = null, val legalPagesSettings: LegalPagesSettingsDetails? = null, + val productFiltersSettings: ProductFiltersSettings? = null, val orderInvoiceSettings: OrderInvoiceSettings? = null ) : ApiUpdatedDTO { @@ -226,6 +228,17 @@ data class UpdatedStoreProfile( } } + data class ProductFilterItem( + val name: String? = null, + val type: ProductFilterType = ProductFilterType.IN_STOCK, + val enabled: Boolean = false, + ) + + data class ProductFiltersSettings( + val enabledInStorefront: Boolean = false, + val filterSections: List = listOf(), + ) + data class OrderInvoiceSettings( val displayOrderInvoices: Boolean? = null, val attachInvoiceToOrderEmailNotifications: AttachValue? = null, diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/result/FetchedStoreProfile.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/result/FetchedStoreProfile.kt index 129e12378..ed2a4bec4 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/result/FetchedStoreProfile.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/profile/result/FetchedStoreProfile.kt @@ -3,6 +3,7 @@ package com.ecwid.apiclient.v3.dto.profile.result import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind import com.ecwid.apiclient.v3.dto.common.ProductCondition +import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile import com.ecwid.apiclient.v3.jsontransformer.JsonFieldName @@ -22,7 +23,7 @@ data class FetchedStoreProfile( val payment: PaymentInfo? = null, val featureToggles: List? = null, val designSettings: DesignSettings? = null, - val productFiltersSettings: ProductFiltersSettings? = null, + val productFiltersSettings: ProductFiltersSettings = ProductFiltersSettings(), val fbMessengerSettings: FBMessengerSettings? = null, val orderInvoiceSettings: OrderInvoiceSettings? = null, val giftCardSettings: GiftCardSettings? = null, @@ -726,8 +727,15 @@ data class FetchedStoreProfile( val showRootCategories: Boolean? = null, ) + data class ProductFilterItem( + val name: String? = null, + val type: ProductFilterType = ProductFilterType.IN_STOCK, + val enabled: Boolean = false, + ) + data class ProductFiltersSettings( - val enabledInStorefront: Boolean? = null + val enabledInStorefront: Boolean = false, + val filterSections: List = listOf(), ) data class FBMessengerSettings( diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt index aedb875df..7f2ef2c5f 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt @@ -28,6 +28,7 @@ import com.ecwid.apiclient.v3.dto.product.result.ProductsSearchResult import com.ecwid.apiclient.v3.dto.producttype.request.ProductTypeDeleteRequest import com.ecwid.apiclient.v3.dto.producttype.request.ProductTypesGetAllRequest import com.ecwid.apiclient.v3.dto.producttype.result.FetchedProductType +import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileUpdateRequest import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile import com.ecwid.apiclient.v3.dto.variation.request.DeleteAllProductVariationsRequest @@ -83,6 +84,46 @@ abstract class BaseEntityTest { automaticTaxEnabled = false, taxes = listOf(), pricesIncludeTax = false + ), + productFiltersSettings = UpdatedStoreProfile.ProductFiltersSettings( + enabledInStorefront = true, + filterSections = listOf( + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.PRICE, + enabled = false, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.IN_STOCK, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.ON_SALE, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.CATEGORIES, + enabled = false, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.SEARCH, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Color", + type = ProductFilterType.OPTION, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Brand", + type = ProductFilterType.ATTRIBUTE, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "UPC", + type = ProductFilterType.ATTRIBUTE, + enabled = true, + ), + ), ) ) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt index adad78bd1..aecc803a1 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt @@ -1,6 +1,8 @@ package com.ecwid.apiclient.v3.entity +import com.ecwid.apiclient.v3.converter.toUpdated import com.ecwid.apiclient.v3.dto.common.ProductCondition +import com.ecwid.apiclient.v3.dto.profile.enums.ProductFilterType import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileRequest import com.ecwid.apiclient.v3.dto.profile.request.StoreProfileUpdateRequest import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile @@ -168,6 +170,10 @@ class StoreProfileTest : BaseEntityTest() { ) ) ), + productFiltersSettings = UpdatedStoreProfile.ProductFiltersSettings( + enabledInStorefront = true, + filterSections = createTestFilterSections(), + ), orderInvoiceSettings = UpdatedStoreProfile.OrderInvoiceSettings( displayOrderInvoices = true, attachInvoiceToOrderEmailNotifications = UpdatedStoreProfile.OrderInvoiceSettings.AttachValue.ATTACH_TO_ALL_EMAILS, @@ -263,5 +269,54 @@ class StoreProfileTest : BaseEntityTest() { assertTrue(tikTokPixel.advancedMatching) assertEquals(FetchedStoreProfile.VolumeUnit.L, formatsAndUnits.volumeUnit) + + assertEquals( + expectedProfile.productFiltersSettings, + actualProfile.productFiltersSettings.toUpdated() + ) } + + private fun createTestFilterSections() = listOf( + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.IN_STOCK, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.ON_SALE, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.PRICE, + enabled = false, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.CATEGORIES, + enabled = false, + ), + UpdatedStoreProfile.ProductFilterItem( + type = ProductFilterType.SEARCH, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Option 1", + type = ProductFilterType.OPTION, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Option 2", + type = ProductFilterType.OPTION, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Attribute 2", + type = ProductFilterType.ATTRIBUTE, + enabled = true, + ), + UpdatedStoreProfile.ProductFilterItem( + name = "Attribute 1", + type = ProductFilterType.ATTRIBUTE, + enabled = true, + ), + ) + } diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt index 8669ff331..260277417 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt @@ -208,7 +208,6 @@ val nonUpdatablePropertyRules: List> = listOf( Ignored(FetchedStoreProfile::payment), Ignored(FetchedStoreProfile::featureToggles), Ignored(FetchedStoreProfile::designSettings), - Ignored(FetchedStoreProfile::productFiltersSettings), Ignored(FetchedStoreProfile::fbMessengerSettings), Ignored(FetchedStoreProfile::giftCardSettings), ReadOnly(FetchedStoreProfile.Settings::googleProductCategoryName), diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonnullPropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonnullPropertyRules.kt index d7a5a47cc..9190fce49 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonnullPropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonnullPropertyRules.kt @@ -5,6 +5,7 @@ import com.ecwid.apiclient.v3.dto.coupon.request.UpdatedCoupon import com.ecwid.apiclient.v3.dto.customer.request.UpdatedCustomer import com.ecwid.apiclient.v3.dto.customergroup.request.UpdatedCustomerGroup import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct +import com.ecwid.apiclient.v3.dto.profile.request.UpdatedStoreProfile import com.ecwid.apiclient.v3.dto.storage.request.UpdatedStorageData import com.ecwid.apiclient.v3.dto.variation.request.UpdatedVariation import com.ecwid.apiclient.v3.rule.NonnullPropertyRule.AllowNonnull @@ -23,6 +24,7 @@ val nonnullPropertyRules: List> = listOf( AllowNonnull(UpdatedProduct.ProductOption.TextAreaOption::required), AllowNonnull(UpdatedProduct.ProductOption.TextFieldOption::required), AllowNonnull(UpdatedProduct.CustomPriceTier::value), + AllowNonnull(UpdatedStorageData::key), AllowNonnull(UpdatedStorageData::value), @@ -61,7 +63,12 @@ val nonnullPropertyRules: List> = listOf( IgnoreNonnull(UpdatedProduct.WholesalePrice::quantity), IgnoreNonnull(UpdatedVariation.WholesalePrice::price), - IgnoreNonnull(UpdatedVariation.WholesalePrice::quantity) + IgnoreNonnull(UpdatedVariation.WholesalePrice::quantity), + + AllowNonnull(UpdatedStoreProfile.ProductFilterItem::enabled), + AllowNonnull(UpdatedStoreProfile.ProductFilterItem::type), + AllowNonnull(UpdatedStoreProfile.ProductFiltersSettings::enabledInStorefront), + AllowNonnull(UpdatedStoreProfile.ProductFiltersSettings::filterSections), ) sealed class NonnullPropertyRule( diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedStoreProfileRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedStoreProfileRules.kt index 90f434819..0b866e1af 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedStoreProfileRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedStoreProfileRules.kt @@ -232,7 +232,7 @@ val fetchedStoreProfileNullablePropertyRules: List> = IgnoreNullable(FetchedStoreProfile.PaymentOptionInfo::paymentProcessorId), IgnoreNullable(FetchedStoreProfile.PaymentOptionInfo::paymentProcessorTitle), AllowNullable(FetchedStoreProfile.PaymentOptionInfo::shippingSettings), - IgnoreNullable(FetchedStoreProfile.ProductFiltersSettings::enabledInStorefront), + AllowNullable(FetchedStoreProfile.ProductFilterItem::name), IgnoreNullable(FetchedStoreProfile::registrationAnswers), IgnoreNullable(FetchedStoreProfile.RegistrationAnswers::alreadySelling), IgnoreNullable(FetchedStoreProfile.RegistrationAnswers::facebook), @@ -337,5 +337,5 @@ val fetchedStoreProfileNullablePropertyRules: List> = IgnoreNullable(FetchedStoreProfile.Zone::postCodes), IgnoreNullable(FetchedStoreProfile.Zone::stateOrProvinceCodes), AllowNullable(FetchedStoreProfile.Settings::googleProductCategory), - AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName) + AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName), )