diff --git a/pkg/helper.go b/pkg/helper.go index d5cd44d..784aa10 100644 --- a/pkg/helper.go +++ b/pkg/helper.go @@ -92,4 +92,13 @@ func IsLCWSizeVariantsAdded(items []models.Variant, keyItem models.Variant) bool } } return false +} + +func IsImageAdded(images []string, image string) bool { + for _, img := range images { + if img == image { + return true + } + } + return false } \ No newline at end of file diff --git a/repositories/ImportRepository.go b/repositories/ImportRepository.go index 87c6e63..c210eae 100644 --- a/repositories/ImportRepository.go +++ b/repositories/ImportRepository.go @@ -994,7 +994,7 @@ func (importer *Importer) UpdateOrCreateLCW(product models.Product) (instance *I for _, colorVariant := range *product.ColorVariants { var ( - variant *gm.Product + variant gm.Product err error ) if !colorVariant.IsSellable { @@ -1007,16 +1007,16 @@ func (importer *Importer) UpdateOrCreateLCW(product models.Product) (instance *I } else { //todo check parsed import variant - if variant, err = importer.importVariant(colorVariant); err != nil { + if variant, err = importer.importParsedVariant(colorVariant); err != nil { - if variant, importer.Error = importer.updateVariant(colorVariant); importer.Error != nil { + if variant, importer.Error = importer.updateParsedVariant(colorVariant); importer.Error != nil { return importer } - linkedProducts = append(linkedProducts, *variant) + linkedProducts = append(linkedProducts, variant) } else { - newProducts = append(newProducts, *variant) + newProducts = append(newProducts, variant) } } diff --git a/repositories/scraper_lcw.go b/repositories/scraper_lcw.go index 67c0cda..97087b5 100644 --- a/repositories/scraper_lcw.go +++ b/repositories/scraper_lcw.go @@ -27,7 +27,7 @@ func NewLCWScraper(link string) LCWScraper { func (s LCWScraper) InitProductDetailParsing() (models.Product, error) { - product := models.Product{Vendor: "lcw"} + product := models.Product{} // load page with js html, err := loadPage(s.link) @@ -45,7 +45,7 @@ func (s LCWScraper) InitProductDetailParsing() (models.Product, error) { } product = parseDocument(doc, true) - + product.Vendor = "lcw" return product, nil } @@ -237,7 +237,10 @@ func setupSizeImages(product *models.Product, doc *goquery.Document) { doc.Find("img").Each(func(i int, s *goquery.Selection) { if image, ok := s.Attr("smallimages"); ok { - product.Images = append(product.Images, image) + isAdded := helper.IsImageAdded(product.Images,image) + if !isAdded { + product.Images = append(product.Images, image) + } } }) }