seller product
This commit is contained in:
parent
d3275ef104
commit
9753896fe5
|
|
@ -342,6 +342,9 @@ func (importer *Importer) importVariant(product models.Product) (*gm.Product, er
|
|||
calcPrice(sizeVariants, &mainFlat)
|
||||
|
||||
err := tx.Omit("ParentID", "CreatedAt", "Variants", "SpecialPrice").Save(&mainFlat).Error
|
||||
|
||||
mainFlat.Variants = sizeVariants
|
||||
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, err
|
||||
|
|
@ -350,6 +353,13 @@ func (importer *Importer) importVariant(product models.Product) (*gm.Product, er
|
|||
|
||||
}
|
||||
|
||||
sProduct := importer.createSellerProduct(&mainFlat,product.Vendor)
|
||||
|
||||
if errSProduct := tx.Create(&sProduct).Error; errSProduct != nil{
|
||||
tx.Rollback()
|
||||
return nil, errSProduct
|
||||
}
|
||||
|
||||
if err := tx.Commit().Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -357,6 +367,36 @@ func (importer *Importer) importVariant(product models.Product) (*gm.Product, er
|
|||
return &mainPorduct, nil
|
||||
}
|
||||
|
||||
func (importer *Importer) createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
||||
sellerID := importer.sellers[sellerURL].ID
|
||||
|
||||
if sellerID == 0 {
|
||||
sellerID = 1
|
||||
}
|
||||
|
||||
sellerProduct := gm.MarketplaceProduct{
|
||||
MarketplaceSellerID: sellerID,
|
||||
IsApproved: true,
|
||||
Condition: "new",
|
||||
Description: "scraped",
|
||||
IsOwner: true,
|
||||
ProductID: flat.ProductID,
|
||||
}
|
||||
|
||||
for _, variant := range flat.Variants {
|
||||
sellerProduct.Variants = append(sellerProduct.Variants, gm.MarketplaceProduct{
|
||||
ProductID: variant.ProductID,
|
||||
IsOwner: true,
|
||||
IsApproved: true,
|
||||
MarketplaceSellerID: sellerID,
|
||||
Condition: "new",
|
||||
})
|
||||
}
|
||||
|
||||
return sellerProduct
|
||||
|
||||
}
|
||||
|
||||
func calcPrice(variants []gm.ProductFlat, flat *gm.ProductFlat) {
|
||||
for _, variant := range variants {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue