fix relations

This commit is contained in:
merdan 2022-10-15 15:27:56 +05:00
parent 1ce9a63b68
commit 65b4e8e00b
1 changed files with 11 additions and 2 deletions

View File

@ -241,11 +241,20 @@ 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:]...) {
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 {
log.Println(err)
}