finish
This commit is contained in:
parent
894c0847dd
commit
b40eba85d8
|
|
@ -12,7 +12,7 @@ type Brand struct {
|
||||||
ID uint `gorm:"primary_key"`
|
ID uint `gorm:"primary_key"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
Name string
|
Name string `gorm:"default:TESTBRAND"`
|
||||||
Code string
|
Code string
|
||||||
Status bool
|
Status bool
|
||||||
Categories []Category `gorm:"many2many:category_brands;"`
|
Categories []Category `gorm:"many2many:category_brands;"`
|
||||||
|
|
|
||||||
|
|
@ -19,42 +19,39 @@ type Product struct {
|
||||||
SuperAttributes []Attribute `gorm:"many2many:product_super_attributes;"`
|
SuperAttributes []Attribute `gorm:"many2many:product_super_attributes;"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// $main_attributes = [
|
|
||||||
//
|
|
||||||
// 'sku' => $parentProduct->sku,
|
|
||||||
// 'product_number' => $data['product_number'],
|
|
||||||
// 'name' => $data['name'],
|
|
||||||
// 'weight' => $data['weight'] ?? 0.45,
|
|
||||||
// 'source' => $data['url_key'],
|
|
||||||
// 'status' => 1,
|
|
||||||
// 'visible_individually' => 1,
|
|
||||||
// 'url_key' => $parentProduct->sku,
|
|
||||||
// 'short_description' => $desc,
|
|
||||||
// 'description' => $desc,
|
|
||||||
// 'favoritesCount' => $data['favorite_count']
|
|
||||||
//
|
|
||||||
// ];
|
|
||||||
type ProductFlat struct {
|
type ProductFlat struct {
|
||||||
ID uint `gorm:"primary_key"`
|
ID uint `gorm:"primary_key"`
|
||||||
Sku string
|
Sku string
|
||||||
ProductNumber string
|
ProductNumber string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
Name string
|
Name string `sql:"DEFAULT:''" gorm:"default:''"`
|
||||||
Weight float64 `gorm:"type:decimal(12,4)"`
|
Weight float64 `sql:"DEFAULT:NULL" gorm:"type:decimal(12,4);default:null"`
|
||||||
Status bool
|
Status bool `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
Source string
|
Source string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
VisibleIndividually bool
|
VisibleIndividually bool `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
UrlKey string
|
Price float64 `gorm:"type:decimal(12,4)"`
|
||||||
ShortDescription string
|
MinPrice float64 `gorm:"type:decimal(12,4)"`
|
||||||
Description string
|
MaxPrice float64 `gorm:"type:decimal(12,4)"`
|
||||||
FavoritesCount uint
|
SpecialPrice float64 `gorm:"type:decimal(12,4)"`
|
||||||
CreatedAt time.Time
|
UrlKey string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
UpdatedAt time.Time
|
ShortDescription string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
Description string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
FavoritesCount uint `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
CreatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
UpdatedAt time.Time `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
ProductID uint
|
ProductID uint
|
||||||
Product Product
|
Product Product
|
||||||
Channel string `sql:"DEFAULT:default"`
|
Channel string `sql:"DEFAULT:default" gorm:"default:default"`
|
||||||
Locale string `sql:"DEFAULT:tm"`
|
Locale string `sql:"DEFAULT:tm" gorm:"default:tm"`
|
||||||
ParentID uint `sql:"DEFAULT:NULL"`
|
ParentID *uint `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
BrandID uint
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductImage struct {
|
type ProductImage struct {
|
||||||
|
|
@ -65,18 +62,27 @@ type ProductImage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductAttributeValue struct {
|
type ProductAttributeValue struct {
|
||||||
ID uint `gorm:"primary_key"`
|
ID uint `gorm:"primary_key"`
|
||||||
Locale string
|
Locale string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
Channel string
|
Channel string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
ProductID uint
|
ProductID uint
|
||||||
AttributeID uint
|
AttributeID uint
|
||||||
TextValue string
|
TextValue string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
BooleanValue bool
|
BooleanValue bool `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
IntegerValue int
|
IntegerValue int `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
FloatValue float64 `gorm:"type:decimal(12,4)"`
|
FloatValue float64 `sql:"DEFAULT:NULL" gorm:"type:decimal(12,4);default:null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductSuperAttribute struct {
|
type ProductSuperAttribute struct {
|
||||||
ProductID uint
|
ProductID uint
|
||||||
AttributeID uint
|
AttributeID uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tabler interface {
|
||||||
|
TableName() string
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName overrides the table name used by User to `profiles`
|
||||||
|
func (ProductFlat) TableName() string {
|
||||||
|
return "product_flat"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,27 @@ package gorm_models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MarketplaceProduct 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
|
||||||
|
ParentID *uint `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
Condition string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
Price float64
|
||||||
|
Description string `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
IsApproved bool `sql:"DEFAULT:NULL" gorm:"default:null"`
|
||||||
|
IsOwner bool
|
||||||
|
MarketplaceSellerID uint
|
||||||
|
MarketplaceSeller MarketplaceSeller
|
||||||
|
Variants []MarketplaceProduct `gorm:"foreignKey:ParentID"`
|
||||||
|
}
|
||||||
|
|
||||||
type MarketplaceSeller struct {
|
type MarketplaceSeller struct {
|
||||||
ID uint `gorm:"primaryKey"`
|
ID uint `gorm:"primaryKey"`
|
||||||
Url string
|
Url string
|
||||||
|
|
|
||||||
509
test/testit.go
509
test/testit.go
|
|
@ -19,7 +19,7 @@ var mainCategories []gm.Category
|
||||||
var baza *gorm.DB
|
var baza *gorm.DB
|
||||||
var mainImportWG, famAndSellerWG sync.WaitGroup
|
var mainImportWG, famAndSellerWG sync.WaitGroup
|
||||||
var families []gm.AttributeFamily
|
var families []gm.AttributeFamily
|
||||||
var sellers []gm.MarketplaceSeller
|
var sellers = make(map[string]gm.MarketplaceSeller)
|
||||||
var attributesMap = make(map[string]gm.Attribute)
|
var attributesMap = make(map[string]gm.Attribute)
|
||||||
|
|
||||||
func StartTest() error {
|
func StartTest() error {
|
||||||
|
|
@ -42,7 +42,9 @@ func StartTest() error {
|
||||||
//get sellers families from mysql with gorutine
|
//get sellers families from mysql with gorutine
|
||||||
go func() {
|
go func() {
|
||||||
defer famAndSellerWG.Done()
|
defer famAndSellerWG.Done()
|
||||||
sellers = gm.GetSellers(baza)
|
for _, vendor := range gm.GetSellers(baza) {
|
||||||
|
sellers[vendor.Url] = vendor
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -140,57 +142,92 @@ func getTotalDocumentCount(db string) int {
|
||||||
|
|
||||||
// todo defailt variant
|
// todo defailt variant
|
||||||
// productflat
|
// productflat
|
||||||
|
|
||||||
|
func getCats(db *gorm.DB, catIDs []int) ([]gm.Category, string, error) {
|
||||||
|
var categories []gm.Category
|
||||||
|
var keywords string
|
||||||
|
|
||||||
|
errCat := db.Preload("Translations").Find(&categories, catIDs).Error
|
||||||
|
|
||||||
|
if errCat != nil {
|
||||||
|
return categories, keywords, errCat
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, cat := range categories {
|
||||||
|
if len(cat.Translations) > 0 && cat.Translations[0].MetaKeywords != "" {
|
||||||
|
translation := cat.Translations[0]
|
||||||
|
|
||||||
|
keywords += "," + translation.MetaKeywords
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories, keywords, nil
|
||||||
|
}
|
||||||
|
|
||||||
func importProduct(product models.Product, db *gorm.DB) {
|
func importProduct(product models.Product, db *gorm.DB) {
|
||||||
|
|
||||||
famAndSellerWG.Wait() //wait until attribute families and sellers are not get from mysql
|
famAndSellerWG.Wait() //wait until attribute families and sellers are not get from mysql
|
||||||
|
|
||||||
var categories []gm.Category
|
categories, keywords, errCat := getCats(db, product.Categories)
|
||||||
var brand gm.Brand
|
|
||||||
|
|
||||||
errCat := db.Find(&categories, product.Categories).Error
|
|
||||||
|
|
||||||
if errCat != nil {
|
if errCat != nil {
|
||||||
log.Println(errCat)
|
log.Println(errCat)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var brand gm.Brand
|
||||||
|
|
||||||
if product.Brand != "" {
|
if product.Brand != "" {
|
||||||
brand = gm.FindOrCreateBrand(db, product.Brand, categories)
|
brand = gm.FindOrCreateBrand(db, product.Brand, categories)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attributes, mainProductFlat := prepearAttributesWithFlat(&product)
|
||||||
|
|
||||||
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
||||||
|
|
||||||
iproduct := gm.Product{
|
iproduct := gm.Product{
|
||||||
Sku: product.ProductGroupID,
|
Sku: product.ProductGroupID,
|
||||||
Type: "simple",
|
Type: "simple",
|
||||||
AttributeFamilyID: families[0].ID,
|
AttributeFamilyID: families[0].ID,
|
||||||
Brand: brand,
|
Brand: brand,
|
||||||
Categories: categories,
|
Categories: categories,
|
||||||
AttributeValues: assignAttributes(&product),
|
AttributeValues: attributes,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, element := range product.Images {
|
for _, element := range product.Images {
|
||||||
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 || len(product.SizeVariants) > 0 {
|
if product.ColorVariantCount > 0 {
|
||||||
|
iproduct.SuperAttributes = append(iproduct.SuperAttributes, attributesMap["color"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(product.SizeVariants) > 0 {
|
||||||
|
iproduct.SuperAttributes = append(iproduct.SuperAttributes, attributesMap["size"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(iproduct.SuperAttributes) > 0 {
|
||||||
iproduct.Type = "configurable"
|
iproduct.Type = "configurable"
|
||||||
iproduct.AttributeFamilyID = families[1].ID
|
iproduct.AttributeFamilyID = families[1].ID
|
||||||
}
|
}
|
||||||
|
//todo insert attribute values manytomany
|
||||||
|
mainProductFlat.Product = iproduct
|
||||||
|
mainProductFlat.Brand = brand
|
||||||
|
mainProductFlat.MetaKeywords = keywords
|
||||||
|
|
||||||
err := db.Omit("Categories").Select("Sku", "Type", "AttributeFamilyID", "CreatedAt", "UpdatedAt").Create(&iproduct).Error
|
errProduct := db.Omit("Product.ParentID", "Product.SuperAttributes.*", "Product.Categories.*").Create(&mainProductFlat).Error
|
||||||
|
|
||||||
if err != nil {
|
if errProduct != nil {
|
||||||
log.Println(err)
|
log.Println(errProduct)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if iproduct.Type == "configurable" {
|
if iproduct.Type == "configurable" {
|
||||||
|
|
||||||
var productVariants []gm.Product
|
var productFlatVariants []gm.ProductFlat
|
||||||
var superAttributes []gm.Attribute
|
|
||||||
|
|
||||||
if len(product.ColorVariants) > 0 {
|
if len(product.ColorVariants) > 0 {
|
||||||
//attach super attributes color
|
|
||||||
superAttributes = append(superAttributes, attributesMap["color"])
|
|
||||||
|
|
||||||
var description string
|
var description string
|
||||||
for _, colorVariant := range product.ColorVariants {
|
for _, colorVariant := range product.ColorVariants {
|
||||||
|
|
@ -203,25 +240,25 @@ func importProduct(product models.Product, db *gorm.DB) {
|
||||||
colorOption := gm.GetAttributeOption(db, attributesMap["color"].ID, colorVariant.Color)
|
colorOption := gm.GetAttributeOption(db, attributesMap["color"].ID, colorVariant.Color)
|
||||||
|
|
||||||
if len(colorVariant.SizeVariants) > 0 {
|
if len(colorVariant.SizeVariants) > 0 {
|
||||||
if len(superAttributes) < 2 {
|
|
||||||
superAttributes = append(superAttributes, attributesMap["size"])
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sizeVariant := range colorVariant.SizeVariants {
|
for _, sizeVariant := range colorVariant.SizeVariants {
|
||||||
|
|
||||||
if sizeVariant.Sellable {
|
if sizeVariant.Sellable {
|
||||||
sku := fmt.Sprintf("%s-%s-%d-col-size", colorVariant.ProductGroupID, colorVariant.ProductNumber, sizeVariant.ItemNumber)
|
sku := fmt.Sprintf("%s-%s-%d-col-size", colorVariant.ProductGroupID, colorVariant.ProductNumber, sizeVariant.ItemNumber)
|
||||||
sizeOption := gm.GetAttributeOption(db, attributesMap["size"].ID, sizeVariant.AttributeValue)
|
sizeOption := gm.GetAttributeOption(db, attributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||||
|
productNumber := fmt.Sprintf("%s-%d", colorVariant.ProductNumber, sizeVariant.ItemNumber)
|
||||||
attributes := []gm.ProductAttributeValue{
|
attributes := []gm.ProductAttributeValue{
|
||||||
|
// {AttributeID: attributesMap["source"].ID, TextValue: colorVariant.URLKey, Channel: "default", Locale: "tm"},
|
||||||
|
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: colorVariant.FavoriteCount, Channel: "default", Locale: "tm"},
|
||||||
|
// {AttributeID: attributesMap["meta_keywords"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["sku"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["sku"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["product_number"].ID, TextValue: fmt.Sprintf("%s-%d", colorVariant.ProductNumber, sizeVariant.ItemNumber), Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["product_number"].ID, TextValue: productNumber, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["name"].ID, TextValue: colorVariant.Name, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["name"].ID, TextValue: colorVariant.Name, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["weight"].ID, FloatValue: weight, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["weight"].ID, FloatValue: weight, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["source"].ID, TextValue: colorVariant.URLKey, Channel: "default", Locale: "tm"},
|
|
||||||
{AttributeID: attributesMap["status"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["status"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["url_key"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["url_key"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
||||||
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: colorVariant.FavoriteCount, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"},
|
||||||
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
{
|
{
|
||||||
AttributeID: attributesMap["color"].ID,
|
AttributeID: attributesMap["color"].ID,
|
||||||
|
|
@ -236,48 +273,108 @@ func importProduct(product models.Product, db *gorm.DB) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if sizeVariant.Price.OriginalPrice.Value > sizeVariant.Price.DiscountedPrice.Value {
|
|
||||||
attributes = append(attributes, []gm.ProductAttributeValue{
|
|
||||||
{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
{AttributeID: attributesMap["special_price"].ID, FloatValue: sizeVariant.Price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
}...)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"})
|
|
||||||
}
|
|
||||||
|
|
||||||
productVariant := gm.Product{
|
productVariant := gm.Product{
|
||||||
ParentID: iproduct.ID,
|
ParentID: mainProductFlat.ProductID,
|
||||||
Type: "simple",
|
Type: "simple",
|
||||||
AttributeFamily: iproduct.AttributeFamily,
|
|
||||||
Sku: sku,
|
|
||||||
Brand: iproduct.Brand,
|
|
||||||
AttributeValues: attributes,
|
|
||||||
AttributeFamilyID: iproduct.AttributeFamilyID,
|
AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||||
|
Sku: sku,
|
||||||
|
BrandID: mainProductFlat.BrandID,
|
||||||
|
AttributeValues: attributes,
|
||||||
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})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errProdVariant := db.Omit("Categories.*").Create(&productVariant).Error
|
||||||
|
|
||||||
|
if errProdVariant != nil {
|
||||||
|
log.Println(errProdVariant)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//todo assign images
|
//todo assign images
|
||||||
productVariants = append(productVariants, productVariant)
|
flatVariant := gm.ProductFlat{
|
||||||
|
ProductID: productVariant.ID,
|
||||||
|
BrandID: mainProductFlat.BrandID,
|
||||||
|
Status: true,
|
||||||
|
VisibleIndividually: true,
|
||||||
|
Name: colorVariant.Name,
|
||||||
|
Sku: sku,
|
||||||
|
ProductNumber: productNumber,
|
||||||
|
Description: description,
|
||||||
|
UrlKey: sku,
|
||||||
|
Weight: weight,
|
||||||
|
// Source: colorVariant.URLKey,
|
||||||
|
// FavoritesCount: uint(colorVariant.FavoriteCount),
|
||||||
|
Color: int(colorOption.ID),
|
||||||
|
Size: int(sizeOption.ID),
|
||||||
|
ColorLabel: colorOption.AdminName,
|
||||||
|
SizeLabel: sizeOption.AdminName,
|
||||||
|
MetaKeywords: keywords,
|
||||||
|
ParentID: &mainProductFlat.ID,
|
||||||
|
}
|
||||||
|
|
||||||
|
if sizeVariant.Price.OriginalPrice.Value > sizeVariant.Price.DiscountedPrice.Value {
|
||||||
|
attributes = append(attributes, []gm.ProductAttributeValue{
|
||||||
|
{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
||||||
|
{AttributeID: attributesMap["special_price"].ID, FloatValue: sizeVariant.Price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
||||||
|
}...)
|
||||||
|
|
||||||
|
flatVariant.Price = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
flatVariant.SpecialPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MinPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MaxPrice = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
|
||||||
|
} else {
|
||||||
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"})
|
||||||
|
|
||||||
|
flatVariant.Price = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
flatVariant.MinPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MaxPrice = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
if mainProductFlat.MinPrice > flatVariant.MinPrice {
|
||||||
|
mainProductFlat.MinPrice = flatVariant.MinPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
if mainProductFlat.MaxPrice < flatVariant.MaxPrice {
|
||||||
|
mainProductFlat.MaxPrice = flatVariant.MaxPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
errVariant := db.Create(&flatVariant).Error
|
||||||
|
|
||||||
|
if errVariant != nil {
|
||||||
|
log.Println(errVariant)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
productFlatVariants = append(productFlatVariants, flatVariant)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if colorVariant.IsSellable {
|
} else if colorVariant.IsSellable {
|
||||||
|
|
||||||
colorOption := gm.GetAttributeOption(db, attributesMap["color"].ID, colorVariant.Color)
|
colorOption := gm.GetAttributeOption(db, attributesMap["color"].ID, colorVariant.Color)
|
||||||
attributes := collectAttributes(&colorVariant, &colorOption)
|
attributes, variantFlat := collectAttributes(&colorVariant, &colorOption)
|
||||||
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"})
|
||||||
|
|
||||||
sku := fmt.Sprintf("%s-%s-col-%s", iproduct.Sku, colorVariant.ProductNumber, colorVariant.Color)
|
if mainProductFlat.MinPrice > variantFlat.MinPrice {
|
||||||
|
mainProductFlat.MinPrice = variantFlat.MinPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
if mainProductFlat.MaxPrice < variantFlat.MaxPrice {
|
||||||
|
mainProductFlat.MaxPrice = variantFlat.MaxPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
sku := fmt.Sprintf("%s-%s-%s", iproduct.Sku, colorVariant.ProductNumber, colorVariant.ProductCode)
|
||||||
|
|
||||||
productVariant := gm.Product{
|
productVariant := gm.Product{
|
||||||
ParentID: iproduct.ID,
|
ParentID: mainProductFlat.ProductID,
|
||||||
Type: "simple",
|
Type: "simple",
|
||||||
AttributeFamily: iproduct.AttributeFamily,
|
|
||||||
Sku: sku,
|
Sku: sku,
|
||||||
Brand: iproduct.Brand,
|
BrandID: mainProductFlat.BrandID,
|
||||||
AttributeValues: attributes,
|
AttributeValues: attributes,
|
||||||
AttributeFamilyID: iproduct.AttributeFamilyID,
|
AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||||
Categories: categories,
|
Categories: categories,
|
||||||
|
|
@ -287,16 +384,33 @@ func importProduct(product models.Product, db *gorm.DB) {
|
||||||
productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
productVariant.Images = append(productVariant.Images, gm.ProductImage{Type: "cdn", Path: element})
|
||||||
}
|
}
|
||||||
|
|
||||||
productVariants = append(productVariants, productVariant)
|
errProdVariant := db.Omit("Categories.*").Create(&productVariant).Error
|
||||||
|
|
||||||
|
if errProdVariant != nil {
|
||||||
|
log.Println(errProdVariant)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
variantFlat.ProductID = productVariant.ID
|
||||||
|
variantFlat.Color = int(colorOption.ID)
|
||||||
|
variantFlat.ColorLabel = colorOption.AdminName
|
||||||
|
variantFlat.MetaKeywords = keywords
|
||||||
|
variantFlat.ParentID = &mainProductFlat.ID
|
||||||
|
|
||||||
|
errVariant := db.Create(&variantFlat).Error
|
||||||
|
|
||||||
|
if errVariant != nil {
|
||||||
|
log.Println(errVariant)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
productFlatVariants = append(productFlatVariants, variantFlat)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(product.SizeVariants) > 0 {
|
if len(product.SizeVariants) > 0 {
|
||||||
//attach super attributes size
|
|
||||||
if len(superAttributes) < 2 {
|
|
||||||
superAttributes = append(superAttributes, attributesMap["size"])
|
|
||||||
}
|
|
||||||
|
|
||||||
var description string
|
var description string
|
||||||
for _, desc := range product.Descriptions {
|
for _, desc := range product.Descriptions {
|
||||||
|
|
@ -311,126 +425,129 @@ func importProduct(product models.Product, db *gorm.DB) {
|
||||||
sizeOption := gm.GetAttributeOption(db, attributesMap["size"].ID, sizeVariant.AttributeValue)
|
sizeOption := gm.GetAttributeOption(db, attributesMap["size"].ID, sizeVariant.AttributeValue)
|
||||||
|
|
||||||
attributes := []gm.ProductAttributeValue{
|
attributes := []gm.ProductAttributeValue{
|
||||||
{AttributeID: attributesMap["sku"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["source"].ID, TextValue: product.URLKey},
|
||||||
{AttributeID: attributesMap["product_number"].ID, TextValue: string(sizeVariant.ItemNumber), Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: product.FavoriteCount},
|
||||||
|
// {AttributeID: attributesMap["meta_keywords"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
|
{AttributeID: attributesMap["sku"].ID, TextValue: sku},
|
||||||
|
{AttributeID: attributesMap["product_number"].ID, TextValue: fmt.Sprint(sizeVariant.ItemNumber)},
|
||||||
{AttributeID: attributesMap["name"].ID, TextValue: product.Name, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["name"].ID, TextValue: product.Name, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["weight"].ID, FloatValue: weight, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["weight"].ID, FloatValue: weight},
|
||||||
{AttributeID: attributesMap["source"].ID, TextValue: product.URLKey, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["status"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["status"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["url_key"].ID, TextValue: sku},
|
||||||
{AttributeID: attributesMap["url_key"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["meta_keywords"].ID, TextValue: keywords, Channel: "default", Locale: "tm"},
|
||||||
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: product.FavoriteCount, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["size"].ID, IntegerValue: int(sizeOption.ID)},
|
||||||
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
{
|
}
|
||||||
AttributeID: attributesMap["size"].ID,
|
|
||||||
IntegerValue: int(sizeOption.ID),
|
flatVariant := gm.ProductFlat{
|
||||||
Channel: "default",
|
|
||||||
Locale: "tm",
|
Status: true,
|
||||||
|
VisibleIndividually: true,
|
||||||
|
Name: product.Name,
|
||||||
|
Sku: sku,
|
||||||
|
ProductNumber: fmt.Sprint(sizeVariant.ItemNumber),
|
||||||
|
UrlKey: sku,
|
||||||
|
Weight: weight,
|
||||||
|
Size: int(sizeOption.ID),
|
||||||
|
SizeLabel: sizeOption.AdminName,
|
||||||
|
MetaKeywords: keywords,
|
||||||
|
Product: gm.Product{
|
||||||
|
ParentID: mainProductFlat.ProductID,
|
||||||
|
Type: "simple",
|
||||||
|
Sku: sku,
|
||||||
|
BrandID: mainProductFlat.BrandID,
|
||||||
|
AttributeValues: attributes,
|
||||||
|
AttributeFamilyID: iproduct.AttributeFamilyID,
|
||||||
|
Categories: categories,
|
||||||
},
|
},
|
||||||
|
// Source: product.URLKey,
|
||||||
|
// FavoritesCount: uint(product.FavoriteCount),
|
||||||
|
ParentID: &mainProductFlat.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if sizeVariant.Price.OriginalPrice.Value > sizeVariant.Price.DiscountedPrice.Value {
|
if sizeVariant.Price.OriginalPrice.Value > sizeVariant.Price.DiscountedPrice.Value {
|
||||||
attributes = append(attributes, []gm.ProductAttributeValue{
|
attributes = append(attributes, []gm.ProductAttributeValue{
|
||||||
{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value},
|
||||||
{AttributeID: attributesMap["special_price"].ID, FloatValue: sizeVariant.Price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["special_price"].ID, FloatValue: sizeVariant.Price.DiscountedPrice.Value},
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
|
flatVariant.Price = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
flatVariant.SpecialPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MinPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MaxPrice = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"})
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: sizeVariant.Price.OriginalPrice.Value})
|
||||||
|
|
||||||
|
flatVariant.Price = sizeVariant.Price.OriginalPrice.Value
|
||||||
|
flatVariant.MinPrice = sizeVariant.Price.DiscountedPrice.Value
|
||||||
|
flatVariant.MaxPrice = sizeVariant.Price.OriginalPrice.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
productVariant := gm.Product{
|
if mainProductFlat.MinPrice > flatVariant.MinPrice {
|
||||||
ParentID: iproduct.ID,
|
mainProductFlat.MinPrice = flatVariant.MinPrice
|
||||||
Type: "simple",
|
|
||||||
AttributeFamily: iproduct.AttributeFamily,
|
|
||||||
Sku: sku,
|
|
||||||
Brand: iproduct.Brand,
|
|
||||||
AttributeValues: attributes,
|
|
||||||
AttributeFamilyID: iproduct.AttributeFamilyID,
|
|
||||||
Categories: categories,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for _, element := range colorVariant.Images {
|
if mainProductFlat.MaxPrice < flatVariant.MaxPrice {
|
||||||
// productVariant.Images = append(iproduct.Images, gm.ProductImage{Type: "cdn", Path: element})
|
mainProductFlat.MaxPrice = flatVariant.MaxPrice
|
||||||
// }
|
}
|
||||||
|
errVariant := db.Omit("Product.Categories.*").Create(&flatVariant).Error
|
||||||
|
|
||||||
productVariants = append(productVariants, productVariant)
|
if errVariant != nil {
|
||||||
|
log.Println(errVariant)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
productFlatVariants = append(productFlatVariants, flatVariant)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saErr := db.Model(&iproduct).Association("SuperAttributes").Append(superAttributes)
|
errFlat := db.Omit("Product.ParentID", "Product.SuperAttributes.*", "Product.Categories.*", "Source", "FavoritesCount", "CreatedAt").Save(&mainProductFlat)
|
||||||
|
|
||||||
|
if errFlat != nil {
|
||||||
|
log.Println(errFlat)
|
||||||
|
|
||||||
if saErr != nil {
|
|
||||||
log.Println(saErr)
|
|
||||||
}
|
}
|
||||||
|
mainProductFlat.Variants = productFlatVariants
|
||||||
errVariants := db.Omit("Categories").Create(&productVariants).Error
|
|
||||||
|
|
||||||
if errVariants != nil {
|
|
||||||
log.Println(errVariants)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sProduct := createSellerProduct(&mainProductFlat, product.Vendor)
|
||||||
//todo seller product, meta keys
|
//todo seller product, meta keys
|
||||||
// if($data['vendor'] && $seller = $this->vendorRepository->findOneByField('url',$data['vendor'])){
|
errSProduct := db.Create(&sProduct).Error
|
||||||
// $this->createSellerProduct($parentProduct, $seller->id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if product.Vendor != "" {
|
if errSProduct != nil {
|
||||||
for i := range sellers {
|
log.Println(errSProduct)
|
||||||
if sellers[i].Url == product.Vendor {
|
}
|
||||||
createSellerProduct()
|
}
|
||||||
break
|
|
||||||
}
|
func createSellerProduct(flat *gm.ProductFlat, sellerURL string) gm.MarketplaceProduct {
|
||||||
}
|
sellerProduct := gm.MarketplaceProduct{
|
||||||
|
MarketplaceSeller: sellers[sellerURL],
|
||||||
|
IsApproved: true,
|
||||||
|
Condition: "new",
|
||||||
|
Description: "scraped",
|
||||||
|
IsOwner: true,
|
||||||
|
ProductID: flat.ProductID,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
for _, variant := range flat.Variants {
|
||||||
|
sellerProduct.Variants = append(sellerProduct.Variants, gm.MarketplaceProduct{
|
||||||
func createFlat(product gm.Product) gm.ProductFlat {
|
ProductID: variant.ProductID,
|
||||||
flat := gm.ProductFlat{
|
IsOwner: true,
|
||||||
ProductID: product.ID,
|
IsApproved: true,
|
||||||
BrandID: product.BrandID,
|
MarketplaceSeller: sellers[sellerURL],
|
||||||
Status: true,
|
Condition: "new",
|
||||||
VisibleIndividually: true,
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return flat
|
return sellerProduct
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSellerProduct() {
|
func collectAttributes(variant *models.Product, option *gm.AttributeOption) ([]gm.ProductAttributeValue, gm.ProductFlat) {
|
||||||
/*
|
|
||||||
Event::dispatch('marketplace.catalog.product.create.before');
|
|
||||||
|
|
||||||
$sellerProduct = $this->vendorProductRepository->create([
|
|
||||||
'marketplace_seller_id' => $seller_id,
|
|
||||||
'is_approved' => 1,
|
|
||||||
'condition' => 'new',
|
|
||||||
'description' => 'scraped product',
|
|
||||||
'is_owner' => 1,
|
|
||||||
'product_id' => $product->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
foreach ($sellerProduct->product->variants as $baseVariant) {
|
|
||||||
$this->vendorProductRepository->create([
|
|
||||||
'parent_id' => $sellerProduct->id,
|
|
||||||
'product_id' => $baseVariant->id,
|
|
||||||
'is_owner' => 1,
|
|
||||||
'marketplace_seller_id' => $seller_id,
|
|
||||||
'is_approved' => 1,
|
|
||||||
'condition' => 'new',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Event::dispatch('marketplace.catalog.product.create.after', $sellerProduct);
|
|
||||||
|
|
||||||
return $sellerProduct;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
func collectAttributes(variant *models.Product, option *gm.AttributeOption) []gm.ProductAttributeValue {
|
|
||||||
sku := fmt.Sprintf("%s-%s", variant.ProductGroupID, variant.ProductNumber)
|
sku := fmt.Sprintf("%s-%s", variant.ProductGroupID, variant.ProductNumber)
|
||||||
weight, _ := strconv.ParseFloat(variant.Weight, 64)
|
weight, _ := strconv.ParseFloat(variant.Weight, 64)
|
||||||
// var description string
|
// var description string
|
||||||
|
|
@ -438,35 +555,56 @@ func collectAttributes(variant *models.Product, option *gm.AttributeOption) []gm
|
||||||
// for _, desc := range variant.Descriptions {
|
// for _, desc := range variant.Descriptions {
|
||||||
// description += "<p>" + desc.Description + "</p>"
|
// description += "<p>" + desc.Description + "</p>"
|
||||||
// }
|
// }
|
||||||
|
flat := gm.ProductFlat{
|
||||||
|
|
||||||
|
Status: true,
|
||||||
|
VisibleIndividually: true,
|
||||||
|
Name: variant.Name,
|
||||||
|
Sku: sku,
|
||||||
|
ProductNumber: variant.ProductNumber,
|
||||||
|
UrlKey: sku,
|
||||||
|
Weight: weight,
|
||||||
|
// Source: variant.URLKey,
|
||||||
|
// FavoritesCount: uint(variant.FavoriteCount),
|
||||||
|
}
|
||||||
|
|
||||||
attributes := []gm.ProductAttributeValue{
|
attributes := []gm.ProductAttributeValue{
|
||||||
{AttributeID: attributesMap["sku"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: variant.FavoriteCount},
|
||||||
{AttributeID: attributesMap["product_number"].ID, TextValue: variant.ProductNumber, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["source"].ID, TextValue: variant.URLKey},
|
||||||
|
{AttributeID: attributesMap["sku"].ID, TextValue: sku},
|
||||||
|
{AttributeID: attributesMap["product_number"].ID, TextValue: variant.ProductNumber},
|
||||||
{AttributeID: attributesMap["name"].ID, TextValue: variant.Name, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["name"].ID, TextValue: variant.Name, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["weight"].ID, FloatValue: weight, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["weight"].ID, FloatValue: weight},
|
||||||
{AttributeID: attributesMap["source"].ID, TextValue: variant.URLKey, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["status"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["status"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["url_key"].ID, TextValue: sku},
|
||||||
{AttributeID: attributesMap["url_key"].ID, TextValue: sku, Channel: "default", Locale: "tm"},
|
|
||||||
{AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: variant.FavoriteCount, Channel: "default", Locale: "tm"},
|
|
||||||
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: option.AttributeID, IntegerValue: int(option.ID), Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["meta_keywords"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
|
{AttributeID: option.AttributeID, IntegerValue: int(option.ID)},
|
||||||
}
|
}
|
||||||
|
|
||||||
if variant.Price.OriginalPrice.Value > variant.Price.DiscountedPrice.Value {
|
if variant.Price.OriginalPrice.Value > variant.Price.DiscountedPrice.Value {
|
||||||
attributes = append(attributes, []gm.ProductAttributeValue{
|
attributes = append(attributes, []gm.ProductAttributeValue{
|
||||||
{AttributeID: attributesMap["price"].ID, FloatValue: variant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["price"].ID, FloatValue: variant.Price.OriginalPrice.Value},
|
||||||
{AttributeID: attributesMap["special_price"].ID, FloatValue: variant.Price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["special_price"].ID, FloatValue: variant.Price.DiscountedPrice.Value},
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
|
flat.Price = variant.Price.OriginalPrice.Value
|
||||||
|
flat.SpecialPrice = variant.Price.DiscountedPrice.Value
|
||||||
|
flat.MinPrice = variant.Price.DiscountedPrice.Value
|
||||||
|
flat.MaxPrice = variant.Price.OriginalPrice.Value
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: variant.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"})
|
attributes = append(attributes, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: variant.Price.OriginalPrice.Value})
|
||||||
|
flat.Price = variant.Price.OriginalPrice.Value
|
||||||
|
flat.MinPrice = variant.Price.DiscountedPrice.Value
|
||||||
|
flat.MaxPrice = variant.Price.OriginalPrice.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
return attributes
|
return attributes, flat
|
||||||
}
|
}
|
||||||
|
|
||||||
func assignAttributes(data *models.Product) []gm.ProductAttributeValue {
|
func prepearAttributesWithFlat(data *models.Product) ([]gm.ProductAttributeValue, gm.ProductFlat) {
|
||||||
|
|
||||||
weight, _ := strconv.ParseFloat(data.Weight, 64)
|
weight, _ := strconv.ParseFloat(data.Weight, 64)
|
||||||
|
|
||||||
|
|
@ -478,51 +616,54 @@ func assignAttributes(data *models.Product) []gm.ProductAttributeValue {
|
||||||
//$desc = implode(array_map(fn($value): string => '<p>' . $value['description'] . '</p>', $data['descriptions']));
|
//$desc = implode(array_map(fn($value): string => '<p>' . $value['description'] . '</p>', $data['descriptions']));
|
||||||
|
|
||||||
var productAttributeValues = []gm.ProductAttributeValue{
|
var productAttributeValues = []gm.ProductAttributeValue{
|
||||||
{AttributeID: attributesMap["sku"].ID, TextValue: data.ProductGroupID, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["source"].ID, TextValue: data.URLKey},
|
||||||
{AttributeID: attributesMap["product_number"].ID, TextValue: data.ProductNumber, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: data.FavoriteCount},
|
||||||
|
{AttributeID: attributesMap["sku"].ID, TextValue: data.ProductGroupID},
|
||||||
|
{AttributeID: attributesMap["product_number"].ID, TextValue: data.ProductNumber},
|
||||||
{AttributeID: attributesMap["name"].ID, TextValue: data.Name, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["name"].ID, TextValue: data.Name, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["weight"].ID, FloatValue: weight, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["weight"].ID, FloatValue: weight},
|
||||||
{AttributeID: attributesMap["source"].ID, TextValue: data.URLKey, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["status"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["status"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true},
|
||||||
{AttributeID: attributesMap["visible_individually"].ID, BooleanValue: true, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["url_key"].ID, TextValue: data.ProductGroupID},
|
||||||
{AttributeID: attributesMap["url_key"].ID, TextValue: data.ProductGroupID, Channel: "default", Locale: "tm"},
|
|
||||||
{AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
{AttributeID: attributesMap["description"].ID, TextValue: description, Channel: "default", Locale: "tm"},
|
||||||
{AttributeID: attributesMap["favoritesCount"].ID, IntegerValue: data.FavoriteCount, Channel: "default", Locale: "tm"},
|
// {AttributeID: attributesMap["meta_keywords"].ID, TextValue: data.Name, Channel: "default", Locale: "tm"},
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.ColorVariantCount == 0 && len(data.SizeVariants) == 0 {
|
flat := gm.ProductFlat{
|
||||||
if data.Price.OriginalPrice.Value > data.Price.DiscountedPrice.Value {
|
|
||||||
productAttributeValues = append(productAttributeValues, []gm.ProductAttributeValue{
|
|
||||||
{AttributeID: attributesMap["price"].ID, FloatValue: data.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
{AttributeID: attributesMap["special_price"].ID, FloatValue: data.Price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
}...)
|
|
||||||
|
|
||||||
} else {
|
Status: true,
|
||||||
productAttributeValues = append(productAttributeValues, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: data.Price.OriginalPrice.Value, Channel: "default", Locale: "tm"})
|
VisibleIndividually: true,
|
||||||
|
Name: data.Name,
|
||||||
}
|
Sku: data.ProductGroupID,
|
||||||
|
ProductNumber: data.ProductNumber,
|
||||||
|
Description: description,
|
||||||
|
UrlKey: data.ProductGroupID,
|
||||||
|
Weight: weight,
|
||||||
|
// Source: data.URLKey,
|
||||||
|
// FavoritesCount: uint(data.FavoriteCount),
|
||||||
}
|
}
|
||||||
|
if data.Price.OriginalPrice.Value > data.Price.DiscountedPrice.Value {
|
||||||
|
productAttributeValues = append(productAttributeValues, []gm.ProductAttributeValue{
|
||||||
|
{AttributeID: attributesMap["price"].ID, FloatValue: data.Price.OriginalPrice.Value},
|
||||||
|
{AttributeID: attributesMap["special_price"].ID, FloatValue: data.Price.DiscountedPrice.Value},
|
||||||
|
}...)
|
||||||
|
|
||||||
return productAttributeValues
|
flat.Price = data.Price.OriginalPrice.Value
|
||||||
}
|
flat.SpecialPrice = data.Price.DiscountedPrice.Value
|
||||||
|
flat.MinPrice = data.Price.DiscountedPrice.Value
|
||||||
func getPriceAttributes(productID uint, price *models.Price) []gm.ProductAttributeValue {
|
flat.MaxPrice = data.Price.OriginalPrice.Value
|
||||||
var productAttributeValues []gm.ProductAttributeValue
|
|
||||||
if price.OriginalPrice.Value > price.DiscountedPrice.Value {
|
|
||||||
productAttributeValues = []gm.ProductAttributeValue{
|
|
||||||
{ProductID: productID, AttributeID: attributesMap["price"].ID, FloatValue: price.OriginalPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
{ProductID: productID, AttributeID: attributesMap["special_price"].ID, FloatValue: price.DiscountedPrice.Value, Channel: "default", Locale: "tm"},
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
productAttributeValues = []gm.ProductAttributeValue{{ProductID: productID, AttributeID: attributesMap["price"].ID, FloatValue: price.OriginalPrice.Value, Channel: "default", Locale: "tm"}}
|
productAttributeValues = append(productAttributeValues, gm.ProductAttributeValue{AttributeID: attributesMap["price"].ID, FloatValue: data.Price.OriginalPrice.Value})
|
||||||
|
flat.Price = data.Price.OriginalPrice.Value
|
||||||
|
flat.MinPrice = data.Price.OriginalPrice.Value
|
||||||
|
flat.MaxPrice = data.Price.OriginalPrice.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
return productAttributeValues
|
if data.ColorVariantCount != 0 || len(data.SizeVariants) != 0 {
|
||||||
}
|
flat.Price = 0
|
||||||
|
flat.SpecialPrice = 0
|
||||||
|
}
|
||||||
|
|
||||||
func getAttributeFamily() gm.AttributeFamily {
|
return productAttributeValues, flat
|
||||||
|
|
||||||
return families[0]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue