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)
|
r := new(big.Int)
|
||||||
fmt.Println("start import", r.Binomial(1000, 10))
|
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 {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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())
|
log.Println("ERR0001" + errCat.Error())
|
||||||
return errCat
|
return errCat
|
||||||
} else {
|
} else {
|
||||||
log.Println("Import" + product.Name)
|
log.Println(product.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
var brand gm.Brand
|
brand, err := gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
||||||
|
if err != nil {
|
||||||
if product.Brand != "" {
|
tx.Rollback()
|
||||||
brand = gm.FindOrCreateBrand(&tx, product.Brand, categories)
|
log.Println(err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes, mainProductFlat := prepearAttributesWithFlat(&product)
|
attributes, mainProductFlat := prepearAttributesWithFlat(&product)
|
||||||
|
|
@ -378,8 +379,6 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
||||||
return errProdVariant
|
return errProdVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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 errSProduct
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return tx.Commit().Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
func createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ type Brand struct {
|
||||||
Categories []Category `gorm:"many2many:category_brands;"`
|
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
|
var brandObject Brand
|
||||||
|
|
||||||
|
|
@ -31,11 +31,12 @@ func FindOrCreateBrand(db *gorm.DB, brand string, categories []Category) Brand {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERR0000000000000001" + err.Error())
|
log.Println("ERR0000000000000001" + err.Error())
|
||||||
|
return brandObject, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// var brandObject Brand
|
// var brandObject Brand
|
||||||
|
|
||||||
return brandObject
|
return brandObject, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue