kategoria tekst
This commit is contained in:
parent
d0613a0d2c
commit
5bb2e790e3
|
|
@ -175,7 +175,10 @@ func importCategoryProducts(dbName string, db *gorm.DB) {
|
|||
|
||||
//itearate 100 row products
|
||||
for _, element := range response.Rows {
|
||||
ImportProduct(element.Doc, db)
|
||||
err := ImportProduct(element.Doc, db)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -341,13 +344,13 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, colorVariant.Color)
|
||||
|
||||
//colorSavePoint := "ColorSavePoint" + string(colorIndex)
|
||||
colorSavePoint := "ColorSavePoint" + strconv.Itoa(colorIndex)
|
||||
|
||||
if len(colorVariant.SizeVariants) > 0 {
|
||||
|
||||
for index, sizeVariant := range colorVariant.SizeVariants {
|
||||
|
||||
savePoint := "Size" + string(colorIndex) + "sp" + string(index)
|
||||
savePoint := "Size" + strconv.Itoa(colorIndex) + "sp" + strconv.Itoa(index)
|
||||
|
||||
log.Println(savePoint)
|
||||
|
||||
|
|
@ -462,52 +465,52 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
|
||||
} else {
|
||||
|
||||
//colorOption := gm.GetAttributeOption(db, 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"})
|
||||
//
|
||||
//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, colorVariant.ProductCode, colorVariant.Color)
|
||||
//
|
||||
//productVariant := gm.Product{
|
||||
// ParentID: mainProductFlat.ProductID,
|
||||
// Type: "simple",
|
||||
// Sku: sku,
|
||||
// BrandID: mainProductFlat.BrandID,
|
||||
// AttributeValues: attributes,
|
||||
// AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||
// Categories: categories,
|
||||
//}
|
||||
//
|
||||
//for _, element := range colorVariant.Images {
|
||||
// productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
||||
//}
|
||||
//
|
||||
//if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||
// log.Println("ERR5" + errProdVariant.Error())
|
||||
// continue
|
||||
//}
|
||||
//
|
||||
//variantFlat.ProductID = productVariant.ID
|
||||
//variantFlat.Color = int(colorOption.ID)
|
||||
//variantFlat.ColorLabel = colorOption.AdminName
|
||||
//variantFlat.MetaKeywords = keywords
|
||||
//variantFlat.ParentID = mainProductFlat.ID
|
||||
//
|
||||
//if errVariant := tx.Create(&variantFlat).Error; errVariant != nil {
|
||||
// log.Println("ERR6" + errVariant.Error())
|
||||
// tx.RollbackTo(colorSavePoint)
|
||||
// continue
|
||||
//}
|
||||
//
|
||||
//mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat)
|
||||
colorOption := gm.GetAttributeOption(db, 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"})
|
||||
|
||||
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, colorVariant.ProductCode, colorVariant.Color)
|
||||
|
||||
productVariant := gm.Product{
|
||||
ParentID: mainProductFlat.ProductID,
|
||||
Type: "simple",
|
||||
Sku: sku,
|
||||
BrandID: mainProductFlat.BrandID,
|
||||
AttributeValues: attributes,
|
||||
AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||
Categories: categories,
|
||||
}
|
||||
|
||||
for _, element := range colorVariant.Images {
|
||||
productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
||||
}
|
||||
|
||||
if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||
log.Println("ERR5" + errProdVariant.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
variantFlat.ProductID = productVariant.ID
|
||||
variantFlat.Color = int(colorOption.ID)
|
||||
variantFlat.ColorLabel = colorOption.AdminName
|
||||
variantFlat.MetaKeywords = keywords
|
||||
variantFlat.ParentID = mainProductFlat.ID
|
||||
|
||||
if errVariant := tx.Create(&variantFlat).Error; errVariant != nil {
|
||||
log.Println("ERR6" + errVariant.Error())
|
||||
tx.RollbackTo(colorSavePoint)
|
||||
continue
|
||||
}
|
||||
|
||||
mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -523,7 +526,7 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
|||
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, product.Color)
|
||||
for index, sizeVariant := range product.SizeVariants {
|
||||
|
||||
sizeSavePoint := "size" + string(index)
|
||||
sizeSavePoint := "size" + strconv.Itoa(index)
|
||||
tx.SavePoint(sizeSavePoint)
|
||||
|
||||
if sizeVariant.ItemNumber == 0 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue