import Bugfixes

This commit is contained in:
2026-08-22 22:44:47 +02:00
parent e38bcb0d4c
commit 8591764ab3
112 changed files with 234 additions and 30765 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ type ProductGroup struct {
type Product struct {
ID int `json:"id"`
Label string `json:"label"`
ExternalID string `json:"externalId"`
ExternalID string `json:"externalId,omitempty"`
Description string `json:"description"`
ProductGroupID int `json:"productGroupId"`
}
@@ -21,5 +21,5 @@ type Media struct {
Description string `json:"description"`
Media string `json:"media"`
MediaType string `json:"mediaType"`
ExternalID int `json:"externalId"`
ExternalID int `json:"externalId,omitempty"`
}
@@ -156,14 +156,14 @@ func (r *ImportRepository) ImportProductGroups(importData []models.ImportProduct
func (r *ImportRepository) ImportProduct(product models.ImportProduct) error {
if product.ID != 0 {
// Update existing Product
query := "UPDATE products SET label = $1, description = $2, productGroupId = $3 WHERE id = $4"
_, err := r.db.Exec(query, product.Label, product.Description, product.ProductGroupID, product.ID)
query := "UPDATE products SET label = $1, description = $2, externalId = $3, productGroupId = $4 WHERE id = $5"
_, err := r.db.Exec(query, product.Label, product.Description, product.ExternalID, product.ProductGroupID, product.ID)
if err != nil {
return err
}
} else {
// Insert new Product
err := r.db.QueryRow("INSERT INTO products (label, description, productGroupId) VALUES ($1, $2, $3) RETURNING id", product.Label, product.Description, product.ProductGroupID).Scan(&product.ID)
err := r.db.QueryRow("INSERT INTO products (label, description, externalId, productGroupId) VALUES ($1, $2, $3, $4) RETURNING id", product.Label, product.Description, product.ExternalID, product.ProductGroupID).Scan(&product.ID)
if err != nil {
return err
}
@@ -173,7 +173,15 @@ func (r *ImportRepository) ImportProduct(product models.ImportProduct) error {
for _, property := range product.Properties {
property.ProductID = product.ID // Set the ProductID for the Property
property.ProductGroupID = product.ProductGroupID // Clear ProductGroupID for Product properties
err := r.ImportProperty(property)
log.Printf("Getting PropertyTypeID for label: %s", property.Label)
ptid, err := r.valueRepo.GetPropertyTypeIDByLabel(property.Label)
if err != nil {
return err
}
log.Printf("Retrieved PropertyTypeID: %d for label: %s", ptid, property.Label)
property.PropertyTypeID = ptid // Set PropertyTypeID to the retrieved ID for ProductGroup properties
err = r.ImportProperty(property)
if err != nil {
return err
}