categories update2
This commit is contained in:
parent
7653bb5b9d
commit
a6631c6067
|
|
@ -319,29 +319,32 @@ func (importer *Importer) importVariant(product models.Product) (*gm.Product, er
|
|||
byteErr, _ := json.Marshal(err)
|
||||
var newError GormErr
|
||||
|
||||
if err2 := json.Unmarshal((byteErr), &newError);err2!=nil{
|
||||
if err1:= json.Unmarshal((byteErr), &newError);err1!=nil{
|
||||
tx.Rollback()
|
||||
log.Println(err1)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
switch newError.Number{
|
||||
case 1062:
|
||||
if newError.Number == 1062{
|
||||
var barProduct gm.Product
|
||||
if err2 := tx.First(&barProduct,"sku = ?",mainPorduct.Sku).Error;err2 !=nil {
|
||||
tx.Rollback()
|
||||
log.Println(err2)
|
||||
return nil, err2
|
||||
}
|
||||
|
||||
if err3:= tx.Model(&barProduct).Association("Categories").Append(mainPorduct.Categories); err3!=nil{
|
||||
tx.Rollback()
|
||||
log.Println(err3)
|
||||
return nil, err3
|
||||
}
|
||||
|
||||
return &barProduct,nil
|
||||
}else{
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
mainFlat := productRepo.makeProductFlat(mainPorduct.ID)
|
||||
|
|
@ -506,6 +509,9 @@ func (importer *Importer) updateVariant(product models.Product) (*gm.Product, er
|
|||
var flat gm.ProductFlat
|
||||
err := importer.baza.Preload("Product").Preload("Variants").First(&flat, "sku = ?", product.ProductNumber).Error
|
||||
if err != nil {
|
||||
if errors.Is(err,gorm.ErrRecordNotFound) {
|
||||
return importer.importVariant(product)
|
||||
}
|
||||
//todo not found bolsa create etmeli
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue