2022-08-12 08:59:03 +00:00
package gorm_models
2022-09-01 11:53:11 +00:00
import (
2022-09-05 12:35:26 +00:00
helper "db_service/pkg"
2022-09-01 11:53:11 +00:00
"gorm.io/gorm"
2022-09-05 12:35:26 +00:00
"os"
2022-09-01 11:53:11 +00:00
"time"
)
2022-08-12 08:59:03 +00:00
type Product struct {
ID uint ` gorm:"primary_key" `
CreatedAt time . Time
UpdatedAt time . Time
Sku string
Type string
ParentID uint ` sql:"DEFAULT:NULL" `
AttributeFamilyID uint
AttributeFamily AttributeFamily
BrandID uint ` sql:"DEFAULT:NULL" `
Brand Brand
Images [ ] ProductImage
Categories [ ] Category ` gorm:"many2many:product_categories;" `
AttributeValues [ ] ProductAttributeValue
2022-08-15 05:15:49 +00:00
SuperAttributes [ ] Attribute ` gorm:"many2many:product_super_attributes;" `
2022-08-12 08:59:03 +00:00
}
type ProductFlat struct {
2022-09-01 07:57:57 +00:00
ID uint ` gorm:"primary_key" `
Sku string
ProductNumber string ` sql:"DEFAULT:NULL" gorm:"default:null" `
Name string ` sql:"DEFAULT:''" gorm:"default:''" `
Weight float64 ` sql:"DEFAULT:NULL" gorm:"type:decimal(12,4);default:null" `
Status bool ` sql:"DEFAULT:NULL" gorm:"default:null" `
//Source string `sql:"DEFAULT:NULL" gorm:"default:null"`
2022-08-25 05:39:59 +00:00
VisibleIndividually bool ` sql:"DEFAULT:NULL" gorm:"default:null" `
Price float64 ` gorm:"type:decimal(12,4)" `
MinPrice float64 ` gorm:"type:decimal(12,4)" `
MaxPrice float64 ` gorm:"type:decimal(12,4)" `
SpecialPrice float64 ` gorm:"type:decimal(12,4)" `
UrlKey string ` sql:"DEFAULT:NULL" gorm:"default:null" `
ShortDescription string ` sql:"DEFAULT:NULL" gorm:"default:null" `
Description string ` sql:"DEFAULT:NULL" gorm:"default:null" `
2022-08-25 06:33:20 +00:00
FavoritesCount uint ` sql:"DEFAULT:NULL" gorm:"default:null;column:favoritesCount" `
2022-08-25 05:39:59 +00:00
CreatedAt time . Time ` sql:"DEFAULT:NULL" gorm:"default:null" `
UpdatedAt time . Time ` sql:"DEFAULT:NULL" gorm:"default:null" `
2022-08-15 05:15:49 +00:00
ProductID uint
2022-08-12 08:59:03 +00:00
Product Product
2022-08-25 05:39:59 +00:00
Channel string ` sql:"DEFAULT:default" gorm:"default:default" `
Locale string ` sql:"DEFAULT:tm" gorm:"default:tm" `
2022-09-01 07:49:31 +00:00
ParentID uint ` sql:"DEFAULT:NULL" gorm:"default:null" `
2022-08-25 05:39:59 +00:00
Variants [ ] ProductFlat ` gorm:"foreignKey:ParentID" `
Color int ` sql:"DEFAULT:NULL" gorm:"default:null" `
ColorLabel string ` sql:"DEFAULT:NULL" gorm:"default:null" `
Size int ` sql:"DEFAULT:NULL" gorm:"default:null" `
SizeLabel string ` sql:"DEFAULT:NULL" gorm:"default:null" `
MetaTitle string ` sql:"DEFAULT:NULL" gorm:"default:null" `
MetaKeywords string ` sql:"DEFAULT:NULL" gorm:"default:null" `
BrandID uint ` sql:"DEFAULT:NULL" gorm:"default:null" `
Brand Brand
2022-08-12 08:59:03 +00:00
}
type ProductImage struct {
ID uint ` gorm:"primary_key" `
Type string
Path string
ProductID uint
}
type ProductAttributeValue struct {
2022-08-25 05:39:59 +00:00
ID uint ` gorm:"primary_key" `
Locale string ` sql:"DEFAULT:NULL" gorm:"default:null" `
Channel string ` sql:"DEFAULT:NULL" gorm:"default:null" `
2022-08-12 08:59:03 +00:00
ProductID uint
AttributeID uint
2022-08-25 05:39:59 +00:00
TextValue string ` sql:"DEFAULT:NULL" gorm:"default:null" `
BooleanValue bool ` sql:"DEFAULT:NULL" gorm:"default:null" `
IntegerValue int ` sql:"DEFAULT:NULL" gorm:"default:null" `
FloatValue float64 ` sql:"DEFAULT:NULL" gorm:"type:decimal(12,4);default:null" `
2022-08-12 08:59:03 +00:00
}
type ProductSuperAttribute struct {
ProductID uint
AttributeID uint
}
2022-08-25 05:39:59 +00:00
type Tabler interface {
TableName ( ) string
}
// TableName overrides the table name used by User to `profiles`
func ( ProductFlat ) TableName ( ) string {
return "product_flat"
}
2022-09-01 11:53:11 +00:00
func DeleteProducts ( db * gorm . DB ) error {
//todo delete from elastico
2022-09-06 11:31:20 +00:00
return db . Exec ( "DELETE p.* FROM products p, order_items oi WHERE p.id NOT IN (select product_id from wishlist) AND p.id NOT IN (select product_id from order_items) AND p.id NOT IN (select parent_id from order_items)" ) . Error
2022-09-01 11:53:11 +00:00
}
2022-09-05 12:35:26 +00:00
func Flush ( ) error {
2022-09-05 12:37:22 +00:00
_ , err := helper . SendRequest ( "GET" , os . Getenv ( "scout_flash" ) , nil , "" , true )
2022-09-05 12:35:26 +00:00
return err
}