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
|
//itearate 100 row products
|
||||||
for _, element := range response.Rows {
|
for _, element := range response.Rows {
|
||||||
ImportProduct(element.Doc, db)
|
err := ImportProduct(element.Doc, db)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -341,13 +344,13 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
||||||
|
|
||||||
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, colorVariant.Color)
|
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, colorVariant.Color)
|
||||||
|
|
||||||
//colorSavePoint := "ColorSavePoint" + string(colorIndex)
|
colorSavePoint := "ColorSavePoint" + strconv.Itoa(colorIndex)
|
||||||
|
|
||||||
if len(colorVariant.SizeVariants) > 0 {
|
if len(colorVariant.SizeVariants) > 0 {
|
||||||
|
|
||||||
for index, sizeVariant := range colorVariant.SizeVariants {
|
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)
|
log.Println(savePoint)
|
||||||
|
|
||||||
|
|
@ -462,52 +465,52 @@ func ImportProduct(product models.Product, db *gorm.DB) error {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, colorVariant.Color)
|
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, colorVariant.Color)
|
||||||
//attributes, variantFlat := collectAttributes(&colorVariant, &colorOption)
|
attributes, variantFlat := collectAttributes(&colorVariant, &colorOption)
|
||||||
//attributes = append(attributes, gm.ProductAttributeValue{AttributeID: AttributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: AttributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
||||||
//
|
|
||||||
//if mainProductFlat.MinPrice > variantFlat.MinPrice || mainProductFlat.MinPrice == 0 {
|
if mainProductFlat.MinPrice > variantFlat.MinPrice || mainProductFlat.MinPrice == 0 {
|
||||||
// mainProductFlat.MinPrice = variantFlat.MinPrice
|
mainProductFlat.MinPrice = variantFlat.MinPrice
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//if mainProductFlat.MaxPrice < variantFlat.MaxPrice {
|
if mainProductFlat.MaxPrice < variantFlat.MaxPrice {
|
||||||
// mainProductFlat.MaxPrice = variantFlat.MaxPrice
|
mainProductFlat.MaxPrice = variantFlat.MaxPrice
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//sku := fmt.Sprintf("%s-%s-%s-%s", iproduct.Sku, colorVariant.ProductNumber, colorVariant.ProductCode, colorVariant.Color)
|
sku := fmt.Sprintf("%s-%s-%s-%s", iproduct.Sku, colorVariant.ProductNumber, colorVariant.ProductCode, colorVariant.Color)
|
||||||
//
|
|
||||||
//productVariant := gm.Product{
|
productVariant := gm.Product{
|
||||||
// ParentID: mainProductFlat.ProductID,
|
ParentID: mainProductFlat.ProductID,
|
||||||
// Type: "simple",
|
Type: "simple",
|
||||||
// Sku: sku,
|
Sku: sku,
|
||||||
// BrandID: mainProductFlat.BrandID,
|
BrandID: mainProductFlat.BrandID,
|
||||||
// AttributeValues: attributes,
|
AttributeValues: attributes,
|
||||||
// AttributeFamilyID: iproduct.AttributeFamilyID,
|
AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||||
// Categories: categories,
|
Categories: categories,
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//for _, element := range colorVariant.Images {
|
for _, element := range colorVariant.Images {
|
||||||
// productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
if errProdVariant := tx.Omit("Categories.*").Create(&productVariant).Error; errProdVariant != nil {
|
||||||
// log.Println("ERR5" + errProdVariant.Error())
|
log.Println("ERR5" + errProdVariant.Error())
|
||||||
// continue
|
continue
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//variantFlat.ProductID = productVariant.ID
|
variantFlat.ProductID = productVariant.ID
|
||||||
//variantFlat.Color = int(colorOption.ID)
|
variantFlat.Color = int(colorOption.ID)
|
||||||
//variantFlat.ColorLabel = colorOption.AdminName
|
variantFlat.ColorLabel = colorOption.AdminName
|
||||||
//variantFlat.MetaKeywords = keywords
|
variantFlat.MetaKeywords = keywords
|
||||||
//variantFlat.ParentID = mainProductFlat.ID
|
variantFlat.ParentID = mainProductFlat.ID
|
||||||
//
|
|
||||||
//if errVariant := tx.Create(&variantFlat).Error; errVariant != nil {
|
if errVariant := tx.Create(&variantFlat).Error; errVariant != nil {
|
||||||
// log.Println("ERR6" + errVariant.Error())
|
log.Println("ERR6" + errVariant.Error())
|
||||||
// tx.RollbackTo(colorSavePoint)
|
tx.RollbackTo(colorSavePoint)
|
||||||
// continue
|
continue
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat)
|
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)
|
colorOption := gm.GetAttributeOption(db, AttributesMap["color"].ID, product.Color)
|
||||||
for index, sizeVariant := range product.SizeVariants {
|
for index, sizeVariant := range product.SizeVariants {
|
||||||
|
|
||||||
sizeSavePoint := "size" + string(index)
|
sizeSavePoint := "size" + strconv.Itoa(index)
|
||||||
tx.SavePoint(sizeSavePoint)
|
tx.SavePoint(sizeSavePoint)
|
||||||
|
|
||||||
if sizeVariant.ItemNumber == 0 {
|
if sizeVariant.ItemNumber == 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue