variant fix

This commit is contained in:
merdan 2022-09-03 18:27:46 +05:00
parent 8b42aa0503
commit 29ee783bca
4 changed files with 33 additions and 32 deletions

View File

@ -45,20 +45,39 @@ func Start(w http.ResponseWriter, route *http.Request) {
//get attribute families from mysql with gorutine //get attribute families from mysql with gorutine
go func() { go func() {
defer famAndSellerWG.Done() defer famAndSellerWG.Done()
families = gm.GetFamilies(baza)
families, err = gm.GetFamilies(baza)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}() }()
//get sellers families from mysql with gorutine //get sellers families from mysql with gorutine
go func() { go func() {
defer famAndSellerWG.Done() defer famAndSellerWG.Done()
for _, vendor := range gm.GetSellers(baza) { var vendors, err = gm.GetSellers(baza)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, vendor := range vendors {
sellers[vendor.Url] = vendor sellers[vendor.Url] = vendor
} }
}() }()
go func() { go func() {
defer famAndSellerWG.Done() defer famAndSellerWG.Done()
var attributes = gm.GetAttributes(baza) var attributes, err = gm.GetAttributes(baza)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, atrattribute := range attributes { for _, atrattribute := range attributes {
attributesMap[atrattribute.Code] = atrattribute attributesMap[atrattribute.Code] = atrattribute
} }
@ -216,7 +235,7 @@ func importProduct(product models.Product, db *gorm.DB) {
iproduct.Images = append(iproduct.Images, gm.ProductImage{Type: "cdn", Path: element}) iproduct.Images = append(iproduct.Images, gm.ProductImage{Type: "cdn", Path: element})
} }
if product.ColorVariantCount > 0 { if len(product.ColorVariants) > 0 {
iproduct.SuperAttributes = append(iproduct.SuperAttributes, attributesMap["color"]) iproduct.SuperAttributes = append(iproduct.SuperAttributes, attributesMap["color"])
} }
@ -418,7 +437,6 @@ func importProduct(product models.Product, db *gorm.DB) {
} }
mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat) mainProductFlat.Variants = append(mainProductFlat.Variants, variantFlat)
} }
} }

View File

@ -32,18 +32,12 @@ type AttributeGroup struct {
Attributes []Attribute `gorm:"many2many:attribute_group_mappings;"` Attributes []Attribute `gorm:"many2many:attribute_group_mappings;"`
} }
func GetFamilies(db *gorm.DB) []AttributeFamily { func GetFamilies(db *gorm.DB) ([]AttributeFamily, error) {
var families []AttributeFamily var families []AttributeFamily
err := db.Model(&AttributeFamily{}).Preload("Groups").Order("id ASC").Find(&families).Error err := db.Model(&AttributeFamily{}).Preload("Groups").Order("id ASC").Find(&families).Error
if err != nil { return families, err
log.Println(err.Error())
} else {
log.Println("famililar alyndy", len(families))
}
return families
} }
func GetGroups(db *gorm.DB) []AttributeGroup { func GetGroups(db *gorm.DB) []AttributeGroup {
@ -57,15 +51,12 @@ func GetGroups(db *gorm.DB) []AttributeGroup {
return groups return groups
} }
func GetAttributes(db *gorm.DB) []Attribute { func GetAttributes(db *gorm.DB) ([]Attribute, error) {
var attributes []Attribute var attributes []Attribute
err := db.Model(&Attribute{}).Find(&attributes).Error err := db.Model(&Attribute{}).Find(&attributes).Error
if err != nil { return attributes, err
log.Println(err.Error())
}
return attributes
} }
func GetAttributeOption(db *gorm.DB, attrbuteID uint, value string) AttributeOption { func GetAttributeOption(db *gorm.DB, attrbuteID uint, value string) AttributeOption {

View File

@ -91,12 +91,8 @@ func (ProductFlat) TableName() string {
} }
func DeleteProducts(db *gorm.DB) error { func DeleteProducts(db *gorm.DB) error {
//todo delete non ordered & non favorited products
//select distinct ordered and favorited product ids
//todo delete from elastico //todo delete from elastico
//Delete from products where id in (select distinct)
//db.Exec("DELETE FROM products")
return db.Exec("DELETE FROM products").Error return db.Exec("DELETE p.* FROM products p, order_items oi,wishlist f WHERE oi.product_id != p.id AND oi.parent_id != p.id AND f.product_id != p.id").Error
} }

View File

@ -1,7 +1,6 @@
package gorm_models package gorm_models
import ( import (
"log"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -28,13 +27,10 @@ type MarketplaceSeller struct {
Url string Url string
} }
func GetSellers(db *gorm.DB) []MarketplaceSeller { func GetSellers(db *gorm.DB) ([]MarketplaceSeller, error) {
var sellers []MarketplaceSeller var sellers []MarketplaceSeller
err := db.Model(&MarketplaceSeller{}).Find(&sellers).Error err := db.Model(&MarketplaceSeller{}).Find(&sellers).Error
if err != nil { return sellers, err
log.Println(err.Error())
}
return sellers
} }