ready link import
This commit is contained in:
parent
d4ff2a48b3
commit
7482e6181a
|
|
@ -360,6 +360,10 @@ func (importer *Importer) importVariant(product models.Product) (*gm.Product, er
|
|||
func calcPrice(variants []gm.ProductFlat, flat *gm.ProductFlat) {
|
||||
for _, variant := range variants {
|
||||
|
||||
if !variant.Status {
|
||||
continue
|
||||
}
|
||||
|
||||
if flat.MinPrice == 0 || flat.MinPrice > variant.MinPrice {
|
||||
flat.MinPrice = variant.MinPrice
|
||||
}
|
||||
|
|
@ -429,13 +433,73 @@ func (importer *Importer) updateVariant(product models.Product) (*gm.Product, er
|
|||
}
|
||||
|
||||
if flat.Product.Type == "configurable" {
|
||||
//todo update variant prices
|
||||
//todo create none existing variant
|
||||
//todo update min max price
|
||||
|
||||
productRepo := InitProductRepo(&product, importer.GetColorOption(product.Color), importer.GetSexOption(product.Cinsiyet))
|
||||
|
||||
for _, variant := range *product.SizeVariants {
|
||||
|
||||
found := false
|
||||
for _, flatVariant := range flat.Variants {
|
||||
|
||||
if variant.AttributeValue == flatVariant.BoyutLabel || variant.AttributeValue == flatVariant.SizeLabel {
|
||||
|
||||
if !variant.Sellable {
|
||||
importer.baza.Model(&flatVariant).Update("status", false)
|
||||
} else {
|
||||
|
||||
price := product.Price
|
||||
importer.updatePrice(variant.Price, &flatVariant)
|
||||
|
||||
if !flatVariant.Status {
|
||||
|
||||
importer.baza.Model(&flatVariant).Update("status", true)
|
||||
}
|
||||
}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if variant.Sellable && !found {
|
||||
// insert variant
|
||||
var sizeOPtion gm.AttributeOption
|
||||
|
||||
if variant.AttributeName == "Beden" {
|
||||
sizeOPtion = gm.GetAttributeOption(importer.baza, importer.AttributesMap["size"].ID, variant.AttributeValue)
|
||||
} else {
|
||||
sizeOPtion = gm.GetAttributeOption(importer.baza, importer.AttributesMap["boyut"].ID, variant.AttributeValue)
|
||||
}
|
||||
|
||||
sku := fmt.Sprintf("%s-%d", product.ProductNumber, variant.ItemNumber)
|
||||
variantProduct := productRepo.makeVariant(flat.ProductID, flat.Product.AttributeFamilyID, sku)
|
||||
|
||||
variantProduct.AttributeValues = productRepo.getVariantAttributes(importer.AttributesMap, &variant, sizeOPtion.ID)
|
||||
|
||||
if err := importer.baza.Omit("Categories.*").Create(&variantProduct).Error; err != nil {
|
||||
log.Println("Variant Product Create Error: " + err.Error())
|
||||
}
|
||||
|
||||
variantFlat := productRepo.makeVariantFlat(variant, sizeOPtion.ID, flat.ID, variantProduct.ID)
|
||||
|
||||
if err := importer.baza.Create(&variantFlat).Error; err != nil {
|
||||
log.Println("Variant Flat Create Error: " + err.Error())
|
||||
|
||||
}
|
||||
flat.Variants = append(flat.Variants, variantFlat)
|
||||
}
|
||||
}
|
||||
|
||||
calcPrice(flat.Variants, &flat)
|
||||
importer.baza.Omit("ParentID", "CreatedAt", "Variants", "SpecialPrice").Save(&flat)
|
||||
|
||||
} else { //simple
|
||||
|
||||
importer.updatePrice(product.Price, &flat)
|
||||
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (importer *Importer) updatePrice(price models.Price, flat *gm.ProductFlat) {
|
||||
if price.OriginalPrice.Value > price.DiscountedPrice.Value {
|
||||
|
||||
importer.baza.Model(&flat).Updates(map[string]interface{}{
|
||||
|
|
@ -468,8 +532,6 @@ func (importer *Importer) updateVariant(product models.Product) (*gm.Product, er
|
|||
importer.baza.Where("attribute_id = 13 and product_id = ?", flat.ProductID).
|
||||
Delete(&gm.ProductAttributeValue{})
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (importer *Importer) UpdateOrCreate(product models.Product) (instance *Importer) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue