Skip to content

Commit 7bc5cfa

Browse files
authored
Merge pull request #481 from Ecwid/swatches-option-import
Add SwatchesOption to FetchedProduct and UpdatedProduct
2 parents eb56282 + 91b369b commit 7bc5cfa

File tree

9 files changed

+64
-5
lines changed

9 files changed

+64
-5
lines changed

src/main/kotlin/com/ecwid/apiclient/v3/ApiClientHelper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ private fun createProductOptionsPolymorphicType(): PolymorphicType<ProductOption
524524
"select" to ProductOption.SelectOption::class.java,
525525
"size" to ProductOption.SizeOption::class.java,
526526
"radio" to ProductOption.RadioOption::class.java,
527+
"swatches" to ProductOption.SwatchesOption::class.java,
527528
"checkbox" to ProductOption.CheckboxOption::class.java,
528529
"textfield" to ProductOption.TextFieldOption::class.java,
529530
"textarea" to ProductOption.TextAreaOption::class.java,

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ fun FetchedProduct.ProductOption.toUpdated() = when (this) {
108108
is FetchedProduct.ProductOption.SelectOption -> toUpdated()
109109
is FetchedProduct.ProductOption.SizeOption -> toUpdated()
110110
is FetchedProduct.ProductOption.RadioOption -> toUpdated()
111+
is FetchedProduct.ProductOption.SwatchesOption -> toUpdated()
111112
is FetchedProduct.ProductOption.CheckboxOption -> toUpdated()
112113
is FetchedProduct.ProductOption.TextFieldOption -> toUpdated()
113114
is FetchedProduct.ProductOption.TextAreaOption -> toUpdated()
@@ -139,6 +140,15 @@ fun FetchedProduct.ProductOption.RadioOption.toUpdated() = UpdatedProduct.Produc
139140
required = required
140141
)
141142

143+
fun FetchedProduct.ProductOption.SwatchesOption.toUpdated() = UpdatedProduct.ProductOption.SwatchesOption(
144+
name = name,
145+
nameTranslated = nameTranslated,
146+
choices = choices.map { it.toUpdated() },
147+
defaultChoice = defaultChoice,
148+
required = required,
149+
useImageAsSwatchSelector = useImageAsSwatchSelector,
150+
)
151+
142152
fun FetchedProduct.ProductOption.CheckboxOption.toUpdated() = UpdatedProduct.ProductOption.CheckboxOption(
143153
name = name,
144154
nameTranslated = nameTranslated,
@@ -175,7 +185,9 @@ fun FetchedProduct.ProductOptionChoice.toUpdated() = UpdatedProduct.ProductOptio
175185
text = text,
176186
textTranslated = textTranslated,
177187
priceModifier = priceModifier,
178-
priceModifierType = priceModifierType
188+
priceModifierType = priceModifierType,
189+
hexCodes = hexCodes,
190+
imageId = imageId,
179191
)
180192

181193
fun FetchedProduct.ShippingSettings.toUpdated() = UpdatedProduct.ShippingSettings(

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/enums/ProductOptionType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ enum class ProductOptionType {
88
TEXTAREA,
99
DATE,
1010
FILES,
11-
SIZE
11+
SIZE,
12+
SWATCHES,
1213
}

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/request/UpdatedProduct.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ data class UpdatedProduct(
139139
override val required: Boolean? = null
140140
) : ProductOption(ProductOptionType.RADIO), ChoiceBased
141141

142+
143+
data class SwatchesOption(
144+
override val name: String = "",
145+
override val nameTranslated: LocalizedValueMap? = null,
146+
override val choices: List<ProductOptionChoice> = listOf(),
147+
override val defaultChoice: Int? = null,
148+
override val required: Boolean? = null,
149+
val useImageAsSwatchSelector: Boolean = false,
150+
) : ProductOption(ProductOptionType.SWATCHES), ChoiceBased
151+
142152
data class CheckboxOption(
143153
override val name: String = "",
144154
override val nameTranslated: LocalizedValueMap? = null,
@@ -215,6 +225,22 @@ data class UpdatedProduct(
215225
required = required
216226
)
217227

228+
fun createSwatchesOption(
229+
name: String = "",
230+
nameTranslated: LocalizedValueMap? = null,
231+
choices: List<ProductOptionChoice> = listOf(),
232+
defaultChoice: Int? = null,
233+
required: Boolean? = null,
234+
useImageAsSwatchSelector: Boolean = false,
235+
) = SwatchesOption(
236+
name = name,
237+
nameTranslated = nameTranslated,
238+
choices = choices,
239+
defaultChoice = defaultChoice,
240+
required = required,
241+
useImageAsSwatchSelector = useImageAsSwatchSelector,
242+
)
243+
218244
fun createCheckboxOption(
219245
name: String = "",
220246
nameTranslated: LocalizedValueMap? = null,
@@ -276,6 +302,8 @@ data class UpdatedProduct(
276302
val textTranslated: LocalizedValueMap? = null,
277303
val priceModifier: Double? = null,
278304
val priceModifierType: PriceModifierType? = null,
305+
val hexCodes: List<String>? = null,
306+
val imageId: String? = null,
279307
)
280308

281309
data class ShippingSettings(

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ data class FetchedProduct(
240240
override val required: Boolean = false
241241
) : ProductOption(ProductOptionType.RADIO), ChoiceBased
242242

243+
data class SwatchesOption(
244+
override val name: String = "",
245+
override val nameTranslated: LocalizedValueMap? = null,
246+
override val choices: List<ProductOptionChoice> = listOf(),
247+
override val defaultChoice: Int = 0,
248+
override val required: Boolean = false,
249+
val useImageAsSwatchSelector: Boolean = false,
250+
) : ProductOption(ProductOptionType.SWATCHES), ChoiceBased
251+
243252
data class CheckboxOption(
244253
override val name: String = "",
245254
override val nameTranslated: LocalizedValueMap? = null,
@@ -277,7 +286,9 @@ data class FetchedProduct(
277286
val text: String = "",
278287
val textTranslated: LocalizedValueMap? = null,
279288
val priceModifier: Double = 0.0,
280-
val priceModifierType: PriceModifierType = PriceModifierType.ABSOLUTE
289+
val priceModifierType: PriceModifierType = PriceModifierType.ABSOLUTE,
290+
val hexCodes: List<String>? = null,
291+
val imageId: String? = null,
281292
)
282293

283294
data class ShippingSettings(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class CategoriesTest : BaseEntityTest() {
290290
// Searching categories with different combinations of baseUrl and cleanUrls parameters
291291
assertCategoryUrlMatchesRegex(
292292
categorySearchRequest = CategoriesSearchRequest(),
293-
urlPattern = "https://.*.company.site.*/products/Category-.*c.*"
293+
urlPattern = "https://.*.company.site.*/products#!/Category-.*c.*"
294294
)
295295
assertCategoryUrlMatchesRegex(
296296
categorySearchRequest = CategoriesSearchRequest(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ProductsTest : BaseEntityTest() {
242242
// Searching products with different combinations of baseUrl and cleanUrls parameters
243243
assertProductUrlMatchesRegex(
244244
productSearchRequest = ByFilters(keyword = productCreateRequest.newProduct.sku),
245-
urlPattern = "https://.*.company.site.*/products/Product-.*p.*"
245+
urlPattern = "https://.*.company.site.*/products#!/Product-.*p.*"
246246
)
247247
assertProductUrlMatchesRegex(
248248
productSearchRequest = ByFilters(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ val nonnullPropertyRules: List<NonnullPropertyRule<*, *>> = listOf(
3636
IgnoreNonnull(UpdatedProduct.ProductOption.SelectOption::name),
3737
IgnoreNonnull(UpdatedProduct.ProductOption.SizeOption::choices),
3838
IgnoreNonnull(UpdatedProduct.ProductOption.SizeOption::name),
39+
IgnoreNonnull(UpdatedProduct.ProductOption.SwatchesOption::choices),
40+
IgnoreNonnull(UpdatedProduct.ProductOption.SwatchesOption::name),
41+
IgnoreNonnull(UpdatedProduct.ProductOption.SwatchesOption::useImageAsSwatchSelector),
3942
IgnoreNonnull(UpdatedProduct.ProductOption.TextAreaOption::name),
4043
IgnoreNonnull(UpdatedProduct.ProductOption.TextFieldOption::name),
4144
IgnoreNonnull(UpdatedProduct.ProductOptionChoice::text),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,12 @@ val fetchedProductNullablePropertyRules: List<NullablePropertyRule<*, *>> = list
130130
IgnoreNullable(FetchedProduct.ProductOption.RadioOption::nameTranslated),
131131
IgnoreNullable(FetchedProduct.ProductOption.SelectOption::nameTranslated),
132132
IgnoreNullable(FetchedProduct.ProductOption.SizeOption::nameTranslated),
133+
AllowNullable(FetchedProduct.ProductOption.SwatchesOption::nameTranslated),
133134
IgnoreNullable(FetchedProduct.ProductOption.TextAreaOption::nameTranslated),
134135
IgnoreNullable(FetchedProduct.ProductOption.TextFieldOption::nameTranslated),
135136
IgnoreNullable(FetchedProduct.ProductOptionChoice::textTranslated),
137+
AllowNullable(FetchedProduct.ProductOptionChoice::hexCodes),
138+
AllowNullable(FetchedProduct.ProductOptionChoice::imageId),
136139
IgnoreNullable(FetchedProduct.RelatedCategory::categoryId),
137140
IgnoreNullable(FetchedProduct.RelatedCategory::enabled),
138141
IgnoreNullable(FetchedProduct.RelatedCategory::productCount),

0 commit comments

Comments
 (0)