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