variant fix
This commit is contained in:
parent
8b42aa0503
commit
29ee783bca
|
|
@ -45,20 +45,39 @@ func Start(w http.ResponseWriter, route *http.Request) {
|
|||
//get attribute families from mysql with gorutine
|
||||
go func() {
|
||||
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
|
||||
go func() {
|
||||
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
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
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 {
|
||||
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})
|
||||
}
|
||||
|
||||
if product.ColorVariantCount > 0 {
|
||||
if len(product.ColorVariants) > 0 {
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,18 +32,12 @@ type AttributeGroup struct {
|
|||
Attributes []Attribute `gorm:"many2many:attribute_group_mappings;"`
|
||||
}
|
||||
|
||||
func GetFamilies(db *gorm.DB) []AttributeFamily {
|
||||
func GetFamilies(db *gorm.DB) ([]AttributeFamily, error) {
|
||||
var families []AttributeFamily
|
||||
|
||||
err := db.Model(&AttributeFamily{}).Preload("Groups").Order("id ASC").Find(&families).Error
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
|
||||
} else {
|
||||
log.Println("famililar alyndy", len(families))
|
||||
}
|
||||
|
||||
return families
|
||||
return families, err
|
||||
}
|
||||
|
||||
func GetGroups(db *gorm.DB) []AttributeGroup {
|
||||
|
|
@ -57,15 +51,12 @@ func GetGroups(db *gorm.DB) []AttributeGroup {
|
|||
return groups
|
||||
}
|
||||
|
||||
func GetAttributes(db *gorm.DB) []Attribute {
|
||||
func GetAttributes(db *gorm.DB) ([]Attribute, error) {
|
||||
var attributes []Attribute
|
||||
|
||||
err := db.Model(&Attribute{}).Find(&attributes).Error
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
|
||||
}
|
||||
return attributes
|
||||
return attributes, err
|
||||
}
|
||||
|
||||
func GetAttributeOption(db *gorm.DB, attrbuteID uint, value string) AttributeOption {
|
||||
|
|
|
|||
|
|
@ -91,12 +91,8 @@ func (ProductFlat) TableName() string {
|
|||
}
|
||||
|
||||
func DeleteProducts(db *gorm.DB) error {
|
||||
//todo delete non ordered & non favorited products
|
||||
//select distinct ordered and favorited product ids
|
||||
//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
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package gorm_models
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -28,13 +27,10 @@ type MarketplaceSeller struct {
|
|||
Url string
|
||||
}
|
||||
|
||||
func GetSellers(db *gorm.DB) []MarketplaceSeller {
|
||||
func GetSellers(db *gorm.DB) ([]MarketplaceSeller, error) {
|
||||
var sellers []MarketplaceSeller
|
||||
|
||||
err := db.Model(&MarketplaceSeller{}).Find(&sellers).Error
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
|
||||
}
|
||||
return sellers
|
||||
return sellers, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue