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