Skip to content

Commit 420685a

Browse files
committed
Add swatchesOption in FetchedProduct and UpdatedProduct
1 parent eb56282 commit 420685a

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
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: 19 additions & 0 deletions
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.toSwatchChoiceUpdated() },
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,
@@ -178,6 +188,15 @@ fun FetchedProduct.ProductOptionChoice.toUpdated() = UpdatedProduct.ProductOptio
178188
priceModifierType = priceModifierType
179189
)
180190

191+
fun FetchedProduct.ProductOptionChoice.toSwatchChoiceUpdated() = UpdatedProduct.ProductOptionChoice(
192+
text = text,
193+
textTranslated = textTranslated,
194+
priceModifier = priceModifier,
195+
priceModifierType = priceModifierType,
196+
hexCodes = hexCodes ?: emptyList(),
197+
imageId = imageId,
198+
)
199+
181200
fun FetchedProduct.ShippingSettings.toUpdated() = UpdatedProduct.ShippingSettings(
182201
type = type,
183202
methodMarkup = methodMarkup,

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(

0 commit comments

Comments
 (0)