product images added to the catalogue

This commit is contained in:
2026-08-11 15:05:27 +05:30
parent d35caf34d3
commit c179e4d642
9 changed files with 412 additions and 11 deletions

View File

@@ -1,7 +1,9 @@
package services
import (
"encoding/json"
"fmt"
"log"
"nearle/models"
"nearle/repositories"
"time"
@@ -284,7 +286,22 @@ func (s *productService) ImportCatalogueProduct(reqs []models.ImportCataloguePro
Approve: 1,
}
if len(catalogueProduct.Images) > 0 {
// The first stays where every reader already looks for it.
snapshot.Productimage = catalogueProduct.Images[0]
// The rest used to be dropped on the floor here — a product with
// ten photos in the global catalogue arrived in a shop with one,
// and there was no way to get them back short of re-importing.
//
// Encoding failure is swallowed: the product itself is fine
// without a gallery, and refusing an import over a photo list
// would be the wrong trade.
if encoded, err := json.Marshal(catalogueProduct.Images); err == nil {
snapshot.Productimages = string(encoded)
} else {
log.Printf("import: could not encode images for catalogue %s/%d: %v",
req.Brand, req.Catalogueid, err)
}
}
productID, err = s.repo.CreateProductReturningID(snapshot)