This commit is contained in:
parent
a8e9ae2546
commit
f2c67e33ec
|
|
@ -51,7 +51,7 @@ func StartImport(w http.ResponseWriter, route *http.Request) {
|
|||
r := new(big.Int)
|
||||
fmt.Println("start import", r.Binomial(1000, 10))
|
||||
|
||||
baza, err := gorm.Open(mysql.Open(os.Getenv("database_url")), &gorm.Config{})
|
||||
baza, err := gorm.Open(mysql.Open(os.Getenv("database_url")), &gorm.Config{SkipDefaultTransaction: true})
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
|
@ -256,13 +256,14 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
log.Println("ERR0001" + errCat.Error())
|
||||
return errCat
|
||||
} else {
|
||||
log.Println("Import" + product.Name)
|
||||
log.Println(product.Name)
|
||||
}
|
||||
|
||||
var brand gm.Brand
|
||||
|
||||
if product.Brand != "" {
|
||||
brand = gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
||||
brand, err := gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
attributes, mainProductFlat := prepearAttributesWithFlat(&product)
|
||||
|
|
@ -378,8 +379,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
return errProdVariant
|
||||
}
|
||||
|
||||
log.Println("Variant product saved")
|
||||
|
||||
sizeOption := gm.GetAttributeOption(&tx, AttributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||
|
||||
productNumber := fmt.Sprintf("%s-%d", colorVariant.ProductNumber, sizeVariant.ItemNumber)
|
||||
|
|
@ -662,7 +661,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
return errSProduct
|
||||
}
|
||||
|
||||
return nil
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
func createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type Brand struct {
|
|||
Categories []Category `gorm:"many2many:category_brands;"`
|
||||
}
|
||||
|
||||
func FindOrCreateBrand(db *gorm.DB, brand string, categories []Category) Brand {
|
||||
func FindOrCreateBrand(db *gorm.DB, brand string, categories []Category) (Brand, error) {
|
||||
|
||||
var brandObject Brand
|
||||
|
||||
|
|
@ -31,11 +31,12 @@ func FindOrCreateBrand(db *gorm.DB, brand string, categories []Category) Brand {
|
|||
|
||||
if err != nil {
|
||||
log.Println("ERR0000000000000001" + err.Error())
|
||||
return brandObject, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// var brandObject Brand
|
||||
|
||||
return brandObject
|
||||
return brandObject, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue