product variant id

This commit is contained in:
2026-09-02 13:11:01 +05:30
parent 9f9b05ed1c
commit 68871cb043
8 changed files with 450 additions and 5 deletions

View File

@@ -56,6 +56,9 @@ type ProductRepository interface {
UpdateProductPricing(productid int, retailprice, productcost, taxpercent float64) error
UpdateProductCategory(productid, categoryid, subcategoryid int) error
UpdateProductVariant(productid, variantid int) error
AddProductVariant(v models.Productvariant) (models.Productvariant, error)
RemoveProductVariant(tenantid, variantid int) error
VariantsForProducts(tenantid, locationid int, productids []int) (map[int][]models.Productvariant, error)
}
type productRepository struct {
@@ -1023,6 +1026,31 @@ func (r *productRepository) GetProductByVariant(tenantid, variantid, locationid,
return nil, err
}
// The sizes, attached to the products they belong to.
//
// This is what makes one call enough to draw the ordering screen: the app
// asks for the product it was tapped on and gets back the product plus every
// size hanging under it. A product with none comes back with an empty list,
// which is the answer that lets an order proceed.
//
// A failure here does not fail the request. The product and its price are
// the answer; the sizes are an enrichment, and returning the product without
// them beats returning nothing at all.
ids := make([]int, 0, len(data))
for i := range data {
ids = append(ids, data[i].Productid)
}
if byParent, vErr := r.VariantsForProducts(tenantid, locationid, ids); vErr == nil {
for i := range data {
data[i].Variantoptions = byParent[data[i].Productid]
if data[i].Variantoptions == nil {
// An explicit empty list, never a JSON null: a client that does
// `variantoptions.length` must not have to null-check first.
data[i].Variantoptions = []models.Productvariant{}
}
}
}
return data, nil
}