diff --git a/repositories/ImportRepository.go b/repositories/ImportRepository.go index a218fda..219edb4 100644 --- a/repositories/ImportRepository.go +++ b/repositories/ImportRepository.go @@ -237,7 +237,7 @@ func (importer *Importer) ImportProduct(product models.Product) (instance *Impor } if len(linkedProducts) > 1 { - //todo link products + var relation []gm.ProductRelation for index, variant := range linkedProducts { //spoint := "color" + strconv.Itoa(index) @@ -408,24 +408,6 @@ func (importer *Importer) GetSexOption(optionName string) gm.AttributeOption { func (importer *Importer) updateVariant(product models.Product) (*gm.Product, error) { - //if len(*product.SizeVariants) > 0{ - // for _, sizeVariant := range *product.SizeVariants { - // - // if !sizeVariant.Sellable{ - // importer.baza.Model(&gm.ProductFlat{}). - // Where("sku like ? AND size_label = ?", product.ProductNumber+"-%",sizeVariant.AttributeValue). - // Update("status",false) - // }else { - // //todo update price - // //todo insert if not exists - // - // } - // } - //}else { - // var flat gm.ProductFlat - // err := importer.baza.Preload("Product").First(&flat,"sku = ?", product.ProductNumber).Error - // - //} var flat gm.ProductFlat err := importer.baza.Preload("Product", "Variants").First(&flat, "sku = ?", product.ProductNumber).Error if err != nil { @@ -566,21 +548,38 @@ func (importer *Importer) UpdateOrCreate(product models.Product) (instance *Impo } continue - } else if variant, err = importer.importVariant(colorVariant); err != nil { + } else { - if variant, importer.Error = importer.updateVariant(colorVariant); importer.Error != nil { - return importer + if variant, err = importer.importVariant(colorVariant); err != nil { + + if variant, importer.Error = importer.updateVariant(colorVariant); importer.Error != nil { + return importer + } + + linkedProducts = append(linkedProducts, *variant) + + } else { + newProducts = append(newProducts, *variant) } - - linkedProducts = append(linkedProducts, *variant) - } - newProducts = append(newProducts, *variant) } if len(newProducts) > 0 { - //todo relation + // relation + + var relation []gm.ProductRelation + for _, linkedProduct := range linkedProducts { + + for _, newProd := range newProducts { + relation = append(relation, gm.ProductRelation{ParentID: linkedProduct.ID, ChildID: newProd.ID}) + relation = append(relation, gm.ProductRelation{ParentID: newProd.ID, ChildID: linkedProduct.ID}) + } + } + + if err := importer.baza.Create(&relation).Error; err != nil { + log.Println(err) + } } } diff --git a/repositories/ProductRepository.go b/repositories/ProductRepository.go index 7fd34e4..32ea479 100644 --- a/repositories/ProductRepository.go +++ b/repositories/ProductRepository.go @@ -87,7 +87,12 @@ func (pr *ProductRepo) makeProduct(imp *Importer) gm.Product { if pr.HasSizeVariants() { product.Type = "configurable" - product.SuperAttributes = []gm.Attribute{imp.AttributesMap["size"]} + if (*pr.Data.SizeVariants)[0].AttributeName == "Beden" { + product.SuperAttributes = []gm.Attribute{imp.AttributesMap["size"]} + } else { + product.SuperAttributes = []gm.Attribute{imp.AttributesMap["boyut"]} + } + } else { product.Type = "simple" price := pr.Data.Price