This commit is contained in:
2026-08-28 11:56:57 +05:30
parent edb9c2803f
commit 46da26c452
4 changed files with 366 additions and 11 deletions

View File

@@ -574,19 +574,27 @@ func (ctl *ProductController) ImportCatalogueProduct(c *fiber.Ctx) error {
}
for _, req := range data {
// `categoryid` is deliberately NOT required.
// `categoryid` IS required, and the comment that used to sit here
// argued the opposite. It said an unclassified product is "visibly
// unfinished" and therefore harmless, and that importing "reaches no
// shop and cannot be sold".
//
// Importing adds a product to the admin catalogue and nothing else — it
// reaches no shop and cannot be sold — so there is nothing yet that
// depends on it being classified. The console matches the tenant's own
// category against the catalogue's where one lines up and sends 0 where
// none does, and the admin corrects it there.
// Both halves were wrong, and a sweep of all 262 tenants measured it:
// 7 products across 3 tenants sat with categoryid 0, and 6 outlets were
// serving shoppers an EMPTY shop while their consoles listed stock.
// Nothing was visibly unfinished — `getlocationproducts` does not filter
// on category, so the product looked entirely normal to the merchant.
// And import DOES reach a shop: it writes productlocations.
//
// Requiring it forced the console to send *something*, and what it sent
// was the tenant's first category regardless of the product. That is
// worse than uncategorised: an unclassified product is visibly
// unfinished, while a wrongly classified one looks done and is only
// found by someone browsing the wrong aisle.
// The state was also unrecoverable. GetProductsBySubcategory rejects
// categoryid 0 outright, `UpdateProduct` writes only
// productlocations.status, and re-import corrected pricing alone — so
// no request could put it right. Re-import now repairs the category
// (productService.ImportCatalogueProduct), and this refuses to create
// the state in the first place.
//
// A wrongly filed product remains the better failure: it is findable,
// and it is fixable by re-importing. An unfiled one was neither.
// Named individually rather than as one list of five.
//
// The old message recited every required field whichever one was
@@ -607,6 +615,9 @@ func (ctl *ProductController) ImportCatalogueProduct(c *fiber.Ctx) error {
if req.Catalogueid == 0 {
missing = append(missing, "catalogueid")
}
if req.Categoryid == 0 {
missing = append(missing, "categoryid")
}
if len(missing) > 0 {
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
"code": http.StatusBadRequest,