ready link import fx 1
This commit is contained in:
parent
080f9ea922
commit
e75815f183
|
|
@ -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,7 +548,9 @@ func (importer *Importer) UpdateOrCreate(product models.Product) (instance *Impo
|
|||
}
|
||||
continue
|
||||
|
||||
} else if variant, err = importer.importVariant(colorVariant); err != nil {
|
||||
} else {
|
||||
|
||||
if variant, err = importer.importVariant(colorVariant); err != nil {
|
||||
|
||||
if variant, importer.Error = importer.updateVariant(colorVariant); importer.Error != nil {
|
||||
return importer
|
||||
|
|
@ -574,13 +558,28 @@ func (importer *Importer) UpdateOrCreate(product models.Product) (instance *Impo
|
|||
|
||||
linkedProducts = append(linkedProducts, *variant)
|
||||
|
||||
} else {
|
||||
newProducts = append(newProducts, *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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,12 @@ func (pr *ProductRepo) makeProduct(imp *Importer) gm.Product {
|
|||
|
||||
if pr.HasSizeVariants() {
|
||||
product.Type = "configurable"
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue