fix relations
This commit is contained in:
parent
1ce9a63b68
commit
65b4e8e00b
|
|
@ -241,9 +241,18 @@ func (importer *Importer) ImportProduct(product models.Product) (instance *Impor
|
|||
var relation []gm.ProductRelation
|
||||
for index, variant := range linkedProducts {
|
||||
//spoint := "color" + strconv.Itoa(index)
|
||||
for _, item := range append(linkedProducts[:index], linkedProducts[index+1:]...) {
|
||||
relation = append(relation, gm.ProductRelation{ParentID: variant.ID, ChildID: item.ID})
|
||||
temp := make([]gm.Product, len(linkedProducts))
|
||||
|
||||
copy(temp, linkedProducts)
|
||||
|
||||
if index+1 <= len(temp) {
|
||||
temp = append(temp[:index], temp[index+1:]...)
|
||||
|
||||
for _, item := range temp {
|
||||
relation = append(relation, gm.ProductRelation{ParentID: variant.ID, ChildID: item.ID})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if err := importer.baza.Create(&relation).Error; err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue