transaction
This commit is contained in:
parent
e1e0756b40
commit
627964796f
|
|
@ -213,11 +213,21 @@ func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) {
|
|||
var categories []gm.Category
|
||||
var keywords string
|
||||
|
||||
if len(mainCategories) > 0 {
|
||||
for _, item := range mainCategories {
|
||||
for _, id := range catIDs {
|
||||
if item.ID == uint(id) {
|
||||
categories = append(categories, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errCat := db.Preload("Translations").Find(&categories, catIDs).Error
|
||||
|
||||
if errCat != nil {
|
||||
return categories, keywords, errCat
|
||||
}
|
||||
}
|
||||
|
||||
for _, cat := range categories {
|
||||
if len(cat.Translations) > 0 && cat.Translations[0].MetaKeywords != "" {
|
||||
|
|
@ -301,7 +311,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
tx := db.Begin()
|
||||
|
||||
if errMainProduct := tx.Omit("Categories.*", "SuperAttributes.*", "ParentID").Create(&iproduct).Error; errMainProduct != nil {
|
||||
log.Println(errMainProduct.Error())
|
||||
log.Println("ERR1" + errMainProduct.Error())
|
||||
tx.Rollback()
|
||||
return errMainProduct
|
||||
}
|
||||
|
|
@ -312,7 +322,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
if errProductMainFlat := tx.Create(&mainProductFlat).Error; errProductMainFlat != nil {
|
||||
tx.Rollback()
|
||||
log.Println(errProductMainFlat)
|
||||
log.Println("ERR2" + errProductMainFlat.Error())
|
||||
return errProductMainFlat
|
||||
}
|
||||
|
||||
|
|
@ -352,7 +362,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||
log.Println(errProdVariant)
|
||||
log.Println("ERR3" + errProdVariant.Error())
|
||||
tx.RollbackTo(savePoint)
|
||||
continue
|
||||
}
|
||||
|
|
@ -419,7 +429,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
if attError := tx.Create(&attributes).Error; attError != nil {
|
||||
tx.RollbackTo(savePoint)
|
||||
log.Println(attError)
|
||||
log.Println("ERR4" + attError.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -432,7 +442,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
if errVariant := tx.Create(&flatVariant).Error; errVariant != nil {
|
||||
log.Println(errVariant)
|
||||
log.Println("ERR5" + errVariant.Error())
|
||||
tx.RollbackTo(savePoint)
|
||||
continue
|
||||
}
|
||||
|
|
@ -472,7 +482,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||
log.Println(errProdVariant)
|
||||
log.Println("ERR5" + errProdVariant.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -483,7 +493,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
variantFlat.ParentID = mainProductFlat.ID
|
||||
|
||||
if errVariant := tx.Create(&variantFlat).Error; errVariant != nil {
|
||||
log.Println(errVariant)
|
||||
log.Println("ERR6" + errVariant.Error())
|
||||
tx.RollbackTo(colorSavePoint)
|
||||
continue
|
||||
}
|
||||
|
|
@ -591,14 +601,14 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
if errSizeVar := tx.Omit("Categories.*").Create(&sizeVariantProduct).Error; errSizeVar != nil {
|
||||
log.Println(errSizeVar)
|
||||
log.Println("ERR7" + errSizeVar.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
flatVariant.ProductID = sizeVariantProduct.ID
|
||||
|
||||
if errVariant := tx.Create(&flatVariant).Error; errVariant != nil {
|
||||
log.Println(errVariant)
|
||||
log.Println("ERR8" + errVariant.Error())
|
||||
tx.RollbackTo(sizeSavePoint)
|
||||
continue
|
||||
}
|
||||
|
|
@ -620,7 +630,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
if errFlat != nil {
|
||||
log.Println(errFlat)
|
||||
log.Println("ERR9" + errFlat.Error())
|
||||
tx.Rollback()
|
||||
return errFlat
|
||||
}
|
||||
|
|
@ -630,7 +640,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
errSProduct := tx.Create(&sProduct).Error
|
||||
|
||||
if errSProduct != nil {
|
||||
log.Println(errSProduct)
|
||||
log.Println("ERR10" + errSProduct.Error())
|
||||
tx.Rollback()
|
||||
return errSProduct
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue