allvariants
This commit is contained in:
parent
ac9c946b56
commit
cf78df9279
|
|
@ -102,3 +102,11 @@ func IsImageAdded(images []string, image string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
func IsVariantsAdded(variants []models.Variant, itemNumber int) bool {
|
||||||
|
for _, variant := range variants {
|
||||||
|
if variant.ItemNumber == itemNumber {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
helper "db_service/pkg"
|
helper "db_service/pkg"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -287,34 +288,81 @@ func CreateJSONFromModel(model models.TrendyolProductDetailModel) map[string]int
|
||||||
variants = append(variants, variant)
|
variants = append(variants, variant)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(model.AllVariants); i++ {
|
||||||
|
singleVariant := model.AllVariants[i]
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
},
|
||||||
|
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: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
exists := helper.IsVariantsAdded(variants, variant.ItemNumber)
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
variants = append(variants, variant)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(model.AlternativeVariants); i++ {
|
for i := 0; i < len(model.AlternativeVariants); i++ {
|
||||||
alternativeVariant := model.AlternativeVariants[i]
|
alternativeVariant := model.AlternativeVariants[i]
|
||||||
|
|
||||||
//stockType := reflect.TypeOf(alternativeVariant.Stock)
|
|
||||||
|
|
||||||
if len(variants) > 0 {
|
if len(variants) > 0 {
|
||||||
|
|
||||||
// get the first variant for attribute info
|
// get the first variant for attribute info
|
||||||
fv := variants[0]
|
fv := variants[0]
|
||||||
|
|
||||||
variant := models.Variant{
|
variant := models.Variant{
|
||||||
AttributeID: fv.AttributeID,
|
AttributeID: fv.AttributeID, //
|
||||||
AttributeName: fv.AttributeName,
|
AttributeName: fv.AttributeName, // Sample: "Beden"
|
||||||
AttributeType: fv.AttributeType,
|
AttributeType: fv.AttributeType, // Sample: "Size"
|
||||||
AttributeValue: alternativeVariant.AttributeValue,
|
AttributeValue: alternativeVariant.AttributeValue,
|
||||||
Price: alternativeVariant.Price,
|
Price: alternativeVariant.Price,
|
||||||
Sellable: true,
|
|
||||||
ItemNumber: alternativeVariant.ItemNumber,
|
ItemNumber: alternativeVariant.ItemNumber,
|
||||||
|
Sellable: true,
|
||||||
}
|
}
|
||||||
|
exists := helper.IsVariantsAdded(variants, variant.ItemNumber)
|
||||||
|
|
||||||
|
if !exists {
|
||||||
variants = append(variants, variant)
|
variants = append(variants, variant)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json["size_variants"] = variants
|
json["size_variants"] = variants
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue