This commit is contained in:
parent
a2083e4e09
commit
a8e9ae2546
|
|
@ -246,8 +246,11 @@ func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) {
|
|||
func ImportProduct(product models.Product, db *gorm.DB) error {
|
||||
|
||||
famAndSellerWG.Wait() //wait until attribute families and sellers are not get from mysql
|
||||
//BEGIN TRANSACTION
|
||||
// begin a transaction
|
||||
|
||||
categories, keywords, errCat := getCats(db, product.Categories)
|
||||
tx := *db.Begin()
|
||||
categories, keywords, errCat := getCats(&tx, product.Categories)
|
||||
|
||||
if errCat != nil {
|
||||
log.Println("ERR0001" + errCat.Error())
|
||||
|
|
@ -259,12 +262,12 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
var brand gm.Brand
|
||||
|
||||
if product.Brand != "" {
|
||||
brand = gm.FindOrCreateBrand(db, product.Brand, categories)
|
||||
brand = gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
||||
}
|
||||
|
||||
attributes, mainProductFlat := prepearAttributesWithFlat(&product)
|
||||
|
||||
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, product.Color)
|
||||
colorOption := gm.GetAttributeOption(&tx, AttributesMap["color"].ID, product.Color)
|
||||
|
||||
mainProductFlat.Color = int(colorOption.ID)
|
||||
mainProductFlat.ColorLabel = product.Color
|
||||
|
|
@ -311,10 +314,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
iproduct.AttributeFamilyID = famID
|
||||
}
|
||||
//BEGIN TRANSACTION
|
||||
// begin a transaction
|
||||
|
||||
tx := db.Begin()
|
||||
|
||||
if errMainProduct := tx.Omit("Categories.*", "SuperAttributes.*", "ParentID").Create(&iproduct).Error; errMainProduct != nil {
|
||||
log.Println("ERR1" + errMainProduct.Error())
|
||||
|
|
@ -342,7 +341,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
description += "<p>" + desc.Description + "</p>"
|
||||
}
|
||||
|
||||
colorOption := gm.GetAttributeOption(tx, AttributesMap["color"].ID, colorVariant.Color)
|
||||
colorOption := gm.GetAttributeOption(&tx, AttributesMap["color"].ID, colorVariant.Color)
|
||||
|
||||
if len(colorVariant.SizeVariants) > 0 {
|
||||
|
||||
|
|
@ -381,7 +380,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
log.Println("Variant product saved")
|
||||
|
||||
sizeOption := gm.GetAttributeOption(tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
sizeOption := gm.GetAttributeOption(&tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
|
||||
productNumber := fmt.Sprintf("%s-%d", colorVariant.ProductNumber, sizeVariant.ItemNumber)
|
||||
|
||||
|
|
@ -469,7 +468,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
colorSavePoint := "ColorSavePoint" + strconv.Itoa(colorIndex)
|
||||
tx.SavePoint(colorSavePoint)
|
||||
|
||||
colorOption := gm.GetAttributeOption(tx, AttributesMap["color"].ID, colorVariant.Color)
|
||||
colorOption := gm.GetAttributeOption(&tx, AttributesMap["color"].ID, colorVariant.Color)
|
||||
attributes, variantFlat := collectAttributes(&colorVariant, &colorOption)
|
||||
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: AttributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
||||
|
||||
|
|
@ -528,7 +527,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
} else if len(product.SizeVariants) > 0 {
|
||||
|
||||
weight, _ := strconv.ParseFloat(product.Weight, 64)
|
||||
colorOption := gm.GetAttributeOption(tx, AttributesMap["color"].ID, product.Color)
|
||||
colorOption := gm.GetAttributeOption(&tx, AttributesMap["color"].ID, product.Color)
|
||||
for index, sizeVariant := range product.SizeVariants {
|
||||
|
||||
sizeSavePoint := "size" + strconv.Itoa(index)
|
||||
|
|
@ -539,7 +538,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
}
|
||||
|
||||
sku := fmt.Sprintf("%s-%s-%d-%d", iproduct.Sku, product.ProductNumber, sizeVariant.ItemNumber, index)
|
||||
sizeOption := gm.GetAttributeOption(tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
sizeOption := gm.GetAttributeOption(&tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
|
||||
attributes := []gm.ProductAttributeValue{
|
||||
{AttributeID: AttributesMap["source"].ID, TextValue: product.URLKey},
|
||||
|
|
|
|||
Loading…
Reference in New Issue