fix
This commit is contained in:
parent
8356a1ec58
commit
08c4e79836
|
|
@ -345,8 +345,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
savePoint := "Size" + strconv.Itoa(colorIndex) + "sp" + strconv.Itoa(index)
|
||||
|
||||
log.Println(savePoint)
|
||||
|
||||
tx.SavePoint(savePoint)
|
||||
|
||||
if sizeVariant.ItemNumber == 0 {
|
||||
|
|
@ -371,7 +369,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||
log.Println("ERR3" + errProdVariant.Error())
|
||||
tx.RollbackTo(savePoint)
|
||||
return errProdVariant
|
||||
continue
|
||||
}
|
||||
|
||||
sizeOption := gm.GetAttributeOption(&tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
|
|
@ -440,6 +438,12 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if errVariant := tx.Create(&flatVariant).Error; errVariant != nil {
|
||||
log.Println("ERR5" + errVariant.Error())
|
||||
tx.RollbackTo(savePoint)
|
||||
continue
|
||||
}
|
||||
|
||||
if mainProductFlat.MinPrice > flatVariant.MinPrice || mainProductFlat.MinPrice == 0.0 {
|
||||
mainProductFlat.MinPrice = flatVariant.MinPrice
|
||||
}
|
||||
|
|
@ -448,12 +452,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
mainProductFlat.MaxPrice = flatVariant.MaxPrice
|
||||
}
|
||||
|
||||
if errVariant := tx.Create(&flatVariant).Error; errVariant != nil {
|
||||
log.Println("ERR5" + errVariant.Error())
|
||||
tx.RollbackTo(savePoint)
|
||||
continue
|
||||
}
|
||||
|
||||
mainProductFlat.Variants = append(mainProductFlat.Variants, flatVariant)
|
||||
|
||||
}
|
||||
|
|
@ -466,14 +464,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
attributes, variantFlat := collectAttributes(&colorVariant, &colorOption)
|
||||
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: AttributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
||||
|
||||
if mainProductFlat.MinPrice > variantFlat.MinPrice || mainProductFlat.MinPrice == 0 {
|
||||
mainProductFlat.MinPrice = variantFlat.MinPrice
|
||||
}
|
||||
|
||||
if mainProductFlat.MaxPrice < variantFlat.MaxPrice {
|
||||
mainProductFlat.MaxPrice = variantFlat.MaxPrice
|
||||
}
|
||||
|
||||
sku := fmt.Sprintf("%s-%s-%s-%s", iproduct.Sku, colorVariant.ProductNumber, colorIndex, colorVariant.Color)
|
||||
|
||||
productVariant := gm.Product{
|
||||
|
|
@ -508,14 +498,21 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if mainProductFlat.MinPrice > variantFlat.MinPrice || mainProductFlat.MinPrice == 0 {
|
||||
mainProductFlat.MinPrice = variantFlat.MinPrice
|
||||
}
|
||||
|
||||
if mainProductFlat.MaxPrice < variantFlat.MaxPrice {
|
||||
mainProductFlat.MaxPrice = variantFlat.MaxPrice
|
||||
}
|
||||
|
||||
mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(mainProductFlat.Variants) == 0 {
|
||||
tx.Rollback()
|
||||
return nil
|
||||
return tx.Rollback().Error
|
||||
}
|
||||
|
||||
} else if len(product.SizeVariants) > 0 {
|
||||
|
|
@ -588,14 +585,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
flatVariant.MaxPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||
}
|
||||
|
||||
if mainProductFlat.MinPrice > flatVariant.MinPrice || mainProductFlat.MinPrice == 0 {
|
||||
mainProductFlat.MinPrice = flatVariant.MinPrice
|
||||
}
|
||||
|
||||
if mainProductFlat.MaxPrice < flatVariant.MaxPrice {
|
||||
mainProductFlat.MaxPrice = flatVariant.MaxPrice
|
||||
}
|
||||
|
||||
sizeVariantProduct := gm.Product{
|
||||
ParentID: mainProductFlat.ProductID,
|
||||
Type: "simple",
|
||||
|
|
@ -624,12 +613,20 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if mainProductFlat.MinPrice > flatVariant.MinPrice || mainProductFlat.MinPrice == 0 {
|
||||
mainProductFlat.MinPrice = flatVariant.MinPrice
|
||||
}
|
||||
|
||||
if mainProductFlat.MaxPrice < flatVariant.MaxPrice {
|
||||
mainProductFlat.MaxPrice = flatVariant.MaxPrice
|
||||
}
|
||||
|
||||
mainProductFlat.Variants = append(mainProductFlat.Variants, flatVariant)
|
||||
}
|
||||
|
||||
if len(mainProductFlat.Variants) == 0 {
|
||||
tx.Rollback()
|
||||
return nil
|
||||
return tx.Rollback().Error
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -652,10 +649,9 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
if errSProduct != nil {
|
||||
log.Println("ERR10" + errSProduct.Error())
|
||||
return tx.Rollback().Error
|
||||
tx.Rollback()
|
||||
return errSProduct
|
||||
} else {
|
||||
log.Println(product.Name)
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue