pricing in app
This commit is contained in:
@@ -118,6 +118,17 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// `price` is emitted as the EFFECTIVE price, not the raw override.
|
||||
//
|
||||
// The column holds an override where 0 means "no override", so a client
|
||||
// reading the obvious field name got 0 for every size while the real figure
|
||||
// sat in `variantprice` beside it. Measured on R mart: a grouped product
|
||||
// whose three sizes are priced 50, 250 and 500 was emitting price 0 on all
|
||||
// three, so the app showed them as free.
|
||||
//
|
||||
// Selected after `v.*` so it overwrites the raw column on the way out — the
|
||||
// same trick GetProductByVariant uses for `quantity`. The stored override is
|
||||
// untouched; only what is emitted changes.
|
||||
var rows []models.Productvariant
|
||||
err := r.db.
|
||||
Table("productvariants v").
|
||||
@@ -126,6 +137,11 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
|
||||
p.productname AS variantproductname,
|
||||
COALESCE(p.unitvalue, '') AS variantunitvalue,
|
||||
COALESCE(p.productunit, '') AS variantproductunit,
|
||||
COALESCE(NULLIF(v.price, 0), NULLIF((
|
||||
SELECT pl.price FROM productlocations pl
|
||||
WHERE pl.productid = v.variantproductid AND pl.tenantid = v.tenantid AND pl.locationid = ?
|
||||
LIMIT 1
|
||||
), 0), p.retailprice, 0) AS price,
|
||||
-- The variant’s own override wins, then the outlet’s price, then the
|
||||
-- master price. The override was being ignored entirely: a size
|
||||
-- priced differently from its product was sold at the product’s
|
||||
@@ -142,7 +158,7 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
|
||||
FROM productstocks ps
|
||||
WHERE ps.productid = v.variantproductid AND ps.tenantid = v.tenantid AND ps.locationid = ?
|
||||
), 0) AS variantstock
|
||||
`, locationid, locationid).
|
||||
`, locationid, locationid, locationid).
|
||||
// INNER, and that is the intended filter: a variant whose product was
|
||||
// deleted is not a size a shopper can be offered.
|
||||
Joins("JOIN products p ON p.productid = v.variantproductid AND p.tenantid = v.tenantid").
|
||||
|
||||
Reference in New Issue
Block a user