From 4201c053fb5ca0009f15851d897e9979e31ac128 Mon Sep 17 00:00:00 2001 From: merdan Date: Wed, 3 May 2023 18:59:34 +0500 Subject: [PATCH] variant test --- repositories/ParseRepository.go | 92 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/repositories/ParseRepository.go b/repositories/ParseRepository.go index 43a269e..0bdfade 100644 --- a/repositories/ParseRepository.go +++ b/repositories/ParseRepository.go @@ -291,58 +291,58 @@ func CreateJSONFromModel(model models.TrendyolProductDetailModel) map[string]int } } } + // NOTE: Modified here + if len(variants) > 0 { - for i := 0; i < len(model.AllVariants); i++ { - singleVariant := model.AllVariants[i] + for i := 0; i < len(model.AllVariants); i++ { + singleVariant := model.AllVariants[i] - // get the first variant for attribute info - fv := variants[0] + // get the first variant for attribute info + fv := variants[0] - variant := models.Variant{ - AttributeID: fv.AttributeID, // - AttributeName: fv.AttributeName, // Sample: "Beden" - AttributeType: fv.AttributeType, // Sample: "Size" - AttributeValue: singleVariant.Value, - Price: models.Price{ - ProfitMargin: 0, - DiscountedPrice: struct { - Text string "json:\"text\"" - Value float64 "json:\"value\"" - }{ - Text: fmt.Sprintf("%f", singleVariant.Price), - Value: singleVariant.Price, + variant := models.Variant{ + AttributeID: fv.AttributeID, // + AttributeName: fv.AttributeName, // Sample: "Beden" + AttributeType: fv.AttributeType, // Sample: "Size" + AttributeValue: singleVariant.Value, + Price: models.Price{ + ProfitMargin: 0, + DiscountedPrice: struct { + Text string "json:\"text\"" + Value float64 "json:\"value\"" + }{ + Text: fmt.Sprintf("%f", singleVariant.Price), + Value: singleVariant.Price, + }, + SellingPrice: struct { + Text string "json:\"text\"" + Value float64 "json:\"value\"" + }{ + Text: fmt.Sprintf("%f", singleVariant.Price), + Value: singleVariant.Price, + }, + OriginalPrice: struct { + Text string "json:\"text\"" + Value float64 "json:\"value\"" + }{ + Text: fmt.Sprintf("%f", singleVariant.Price), + Value: singleVariant.Price, + }, + Currency: singleVariant.Currency, }, - SellingPrice: struct { - Text string "json:\"text\"" - Value float64 "json:\"value\"" - }{ - Text: fmt.Sprintf("%f", singleVariant.Price), - Value: singleVariant.Price, - }, - OriginalPrice: struct { - Text string "json:\"text\"" - Value float64 "json:\"value\"" - }{ - Text: fmt.Sprintf("%f", singleVariant.Price), - Value: singleVariant.Price, - }, - Currency: singleVariant.Currency, - }, - ItemNumber: singleVariant.ItemNumber, - Sellable: singleVariant.InStock, + ItemNumber: singleVariant.ItemNumber, + Sellable: singleVariant.InStock, + } + + exists := helper.IsVariantsAdded(variants, variant.ItemNumber) + + if !exists { + variants = append(variants, variant) + } } - exists := helper.IsVariantsAdded(variants, variant.ItemNumber) - - if !exists { - variants = append(variants, variant) - } - } - - for i := 0; i < len(model.AlternativeVariants); i++ { - alternativeVariant := model.AlternativeVariants[i] - - if len(variants) > 0 { + for i := 0; i < len(model.AlternativeVariants); i++ { + alternativeVariant := model.AlternativeVariants[i] // get the first variant for attribute info fv := variants[0]