wishlist fix
This commit is contained in:
parent
4df4a070ec
commit
55f3c785c9
|
|
@ -46,6 +46,7 @@ func StartProductImport(w http.ResponseWriter, _ *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
importRepo.ImportWGroup.Wait()
|
importRepo.ImportWGroup.Wait()
|
||||||
|
//todo delete galan wishlist
|
||||||
|
|
||||||
//scout index flush
|
//scout index flush
|
||||||
if err = gm.Flush(); err != nil {
|
if err = gm.Flush(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
helper "db_service/pkg"
|
helper "db_service/pkg"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -107,13 +108,32 @@ func DeleteProducts(db *gorm.DB) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
//qb := "DELETE FROM products WHERE id NOT IN (select product_id as id from wishlist) AND id NOT IN (select product_id as id from order_items) AND id NOT IN (select parent_id as idfrom order_items);"
|
//qb := "DELETE FROM products WHERE id NOT IN (select product_id as id from wishlist) AND id NOT IN (select product_id as id from order_items) AND id NOT IN (select parent_id as idfrom order_items);"
|
||||||
qb := "DELETE p FROM products p LEFT JOIN order_items oi ON p.id = oi.product_id LEFT JOIN order_items op ON p.id = op.parent_id WHERE oi.id IS NULL AND op.id IS NULL AND product_id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1);"
|
qb := "DELETE p FROM products p " +
|
||||||
|
"LEFT JOIN order_items oi ON p.id = oi.product_id " +
|
||||||
|
"LEFT JOIN order_items op ON p.id = op.parent_id " +
|
||||||
|
"LEFT JOIN wishlist wp ON p.id = wp.product_id " +
|
||||||
|
"WHERE oi.id IS NULL AND op.id IS NULL AND wp.id IS NULL AND product_id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1);"
|
||||||
db.WithContext(ctx).Exec(qb)
|
db.WithContext(ctx).Exec(qb)
|
||||||
db.WithContext(ctx).Exec("UPDATE product_flat set sku=concat(id,\"-ordered\"), status=0 where status=1 AND product_id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1)" )
|
db.WithContext(ctx).Exec("UPDATE product_flat set sku=concat(id,\"-ordered\"), status=0 where status=1 AND product_id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1)" )
|
||||||
db.WithContext(ctx).Exec("UPDATE products set sku=concat(id,\"-ordered\") WHERE id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1)")
|
db.WithContext(ctx).Exec("UPDATE products set sku=concat(id,\"-ordered\") WHERE id IN (SELECT product_id from marketplace_products where marketplace_seller_id=1)")
|
||||||
return db.Error
|
return db.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetWishlistProducts(db *gorm.DB) ([]Product, error){
|
||||||
|
var products [] Product
|
||||||
|
err := db.Joins("JOIN wishlist wp ON products.id = wp.product_id").Joins("JOIN marketplace_products mp ON products.id = mp.product_id where marketplace_seller_id=1").Find(&products).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return products, nil
|
||||||
|
//qb := "SELECT p.id,p.sku FROM products p " +
|
||||||
|
// "JOIN wishlist wp ON p.id = wp.product_id " +
|
||||||
|
// "JOIN marketplace_products mp ON p.id = mp.product_id where marketplace_seller_id=1);"
|
||||||
|
}
|
||||||
|
|
||||||
//func DisableProducts (db *gorm.DB) error {
|
//func DisableProducts (db *gorm.DB) error {
|
||||||
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||||
// defer cancel()
|
// defer cancel()
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ type MarketplaceProduct struct {
|
||||||
CreatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
CreatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
UpdatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
UpdatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
ProductID uint
|
ProductID uint
|
||||||
|
Product Product
|
||||||
ParentID *uint `sql:"DEFAULT:NULL" gorm:"default:null"`
|
ParentID *uint `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
Condition string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
Condition string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
Price float64
|
Price float64
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package gorm_models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Wishlist struct {
|
||||||
|
ID uint `gorm:"primaryKey"`
|
||||||
|
CreatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
UpdatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
ProductID uint
|
||||||
|
Product Product
|
||||||
|
}
|
||||||
|
|
@ -22,6 +22,7 @@ type Importer struct {
|
||||||
baza *gorm.DB
|
baza *gorm.DB
|
||||||
families []gm.AttributeFamily
|
families []gm.AttributeFamily
|
||||||
sellers map[string]gm.MarketplaceSeller
|
sellers map[string]gm.MarketplaceSeller
|
||||||
|
wishlist map[string]gm.Product
|
||||||
AttributesMap map[string]gm.Attribute
|
AttributesMap map[string]gm.Attribute
|
||||||
Error error
|
Error error
|
||||||
ImportWGroup sync.WaitGroup
|
ImportWGroup sync.WaitGroup
|
||||||
|
|
@ -42,7 +43,7 @@ func ImporterInstance() (instance *Importer, err error) {
|
||||||
|
|
||||||
instance = &Importer{baza: db}
|
instance = &Importer{baza: db}
|
||||||
|
|
||||||
instance.ImportWGroup.Add(4)
|
instance.ImportWGroup.Add(5)
|
||||||
|
|
||||||
//load main categories to memory
|
//load main categories to memory
|
||||||
go func(db *gorm.DB) {
|
go func(db *gorm.DB) {
|
||||||
|
|
@ -114,6 +115,24 @@ func ImporterInstance() (instance *Importer, err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
//load wishlist to memory
|
||||||
|
go func(){
|
||||||
|
defer instance.ImportWGroup.Done()
|
||||||
|
|
||||||
|
var wishlist, err = gm.GetWishlistProducts(db)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
instance.Error = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.wishlist = make(map[string]gm.Product, len(wishlist))
|
||||||
|
|
||||||
|
for _, product := range wishlist {
|
||||||
|
instance.wishlist[product.Sku] = product
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if instance.Error != nil {
|
if instance.Error != nil {
|
||||||
log.Println(instance.Error)
|
log.Println(instance.Error)
|
||||||
return nil, instance.Error
|
return nil, instance.Error
|
||||||
|
|
@ -266,6 +285,13 @@ func (importer *Importer) ImportProduct(product models.Product) (instance *Impor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (importer *Importer) importVariant(product models.Product) (*gm.Product, error) {
|
func (importer *Importer) importVariant(product models.Product) (*gm.Product, error) {
|
||||||
|
|
||||||
|
// check if wishlisted then update if.
|
||||||
|
if _, ok := importer.wishlist[product.ProductNumber]; ok {
|
||||||
|
delete(importer.wishlist,product.ProductNumber)
|
||||||
|
return importer.updateVariant(product)
|
||||||
|
}
|
||||||
|
|
||||||
productRepo := InitProductRepo(&product, importer.GetColorOption(product.Color), importer.GetSexOption(product.Cinsiyet))
|
productRepo := InitProductRepo(&product, importer.GetColorOption(product.Color), importer.GetSexOption(product.Cinsiyet))
|
||||||
|
|
||||||
if categories, err := gm.GetCatKeywords(importer.baza, product.Categories); err != nil {
|
if categories, err := gm.GetCatKeywords(importer.baza, product.Categories); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue