Skip to content
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 @@ -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()
)
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ecwid.apiclient.v3.dto.profile.enums

enum class ProductFilterType {
IN_STOCK,
ON_SALE,
PRICE,
CATEGORIES,
SEARCH,
OPTION,
ATTRIBUTE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -18,6 +19,7 @@ data class UpdatedStoreProfile(
val zones: List<Zone>? = null,
val businessRegistrationID: BusinessRegistrationID? = null,
val legalPagesSettings: LegalPagesSettingsDetails? = null,
val productFiltersSettings: ProductFiltersSettings? = null,
val orderInvoiceSettings: OrderInvoiceSettings? = null
) : ApiUpdatedDTO {

Expand Down Expand Up @@ -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<ProductFilterItem> = listOf(),
)

data class OrderInvoiceSettings(
val displayOrderInvoices: Boolean? = null,
val attachInvoiceToOrderEmailNotifications: AttachValue? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,7 +23,7 @@ data class FetchedStoreProfile(
val payment: PaymentInfo? = null,
val featureToggles: List<FeatureTogglesInfo>? = 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,
Expand Down Expand Up @@ -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<ProductFilterItem> = listOf(),
)

data class FBMessengerSettings(
Expand Down
41 changes: 41 additions & 0 deletions src/test/kotlin/com/ecwid/apiclient/v3/entity/BaseEntityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
),
)
)

Expand Down
55 changes: 55 additions & 0 deletions src/test/kotlin/com/ecwid/apiclient/v3/entity/StoreProfileTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(
Ignored(FetchedStoreProfile::payment),
Ignored(FetchedStoreProfile::featureToggles),
Ignored(FetchedStoreProfile::designSettings),
Ignored(FetchedStoreProfile::productFiltersSettings),
Ignored(FetchedStoreProfile::fbMessengerSettings),
Ignored(FetchedStoreProfile::giftCardSettings),
ReadOnly(FetchedStoreProfile.Settings::googleProductCategoryName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +24,7 @@ val nonnullPropertyRules: List<NonnullPropertyRule<*, *>> = listOf(
AllowNonnull(UpdatedProduct.ProductOption.TextAreaOption::required),
AllowNonnull(UpdatedProduct.ProductOption.TextFieldOption::required),
AllowNonnull(UpdatedProduct.CustomPriceTier::value),

AllowNonnull(UpdatedStorageData::key),
AllowNonnull(UpdatedStorageData::value),

Expand Down Expand Up @@ -61,7 +63,12 @@ val nonnullPropertyRules: List<NonnullPropertyRule<*, *>> = 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<T, R>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ val fetchedStoreProfileNullablePropertyRules: List<NullablePropertyRule<*, *>> =
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),
Expand Down Expand Up @@ -337,5 +337,5 @@ val fetchedStoreProfileNullablePropertyRules: List<NullablePropertyRule<*, *>> =
IgnoreNullable(FetchedStoreProfile.Zone::postCodes),
IgnoreNullable(FetchedStoreProfile.Zone::stateOrProvinceCodes),
AllowNullable(FetchedStoreProfile.Settings::googleProductCategory),
AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName)
AllowNullable(FetchedStoreProfile.Settings::googleProductCategoryName),
)