diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/GetProductFiltersRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/GetProductFiltersRequest.kt index 9eedf5595..03953254d 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/GetProductFiltersRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/GetProductFiltersRequest.kt @@ -51,21 +51,17 @@ data class GetProductFiltersRequest( data class Option( private val optionName: String = "" ) : FilterFieldType() { - override fun getFilterFieldName() = "option_" + escapeName(optionName) + override fun getFilterFieldName() = "option_$optionName" } data class Attribute( private val attributeName: String = "" ) : FilterFieldType() { - override fun getFilterFieldName() = "attribute_" + escapeName(attributeName) + override fun getFilterFieldName() = "attribute_$attributeName" } abstract fun getFilterFieldName(): String - protected fun escapeName(name: String): String { - return name.replace(",", "\\,").replace("\\", "\\\\") - } - } @Suppress("unused") @@ -176,16 +172,26 @@ data class GetProductFiltersRequest( } private fun List.toFilterFields(): String { - return joinToString(separator = ",", transform = FilterFieldType::getFilterFieldName) + return joinToString(separator = ",") { filterFieldType -> + escapeProductFilterName(filterFieldType.getFilterFieldName()) + } } private fun Map.toFilterFacetLimitValue(): String { return toList() .joinToString(separator = ",") { (filterFieldType, filterFacetLimit) -> - "${filterFieldType.getFilterFieldName()}:${filterFacetLimit.getFilterFacetLimitValue()}" + val filterName = escapeProductFilterName(filterFieldType.getFilterFieldName()) + val filterFacetLimitValue = filterFacetLimit.getFilterFacetLimitValue() + "$filterName:$filterFacetLimitValue" } } +private fun escapeProductFilterName(name: String): String { + return name + .replace("\\", "\\\\") + .replace(",", "\\,") +} + private fun List.toCategoriesValue(): String { val categoriesValue = joinToString(separator = ",") { categoryId -> categoryId.getFilterParentCategoryIdValue()