pricing in app
This commit is contained in:
@@ -1065,11 +1065,15 @@ func (r *productRepository) GetProductByVariant(tenantid, variantid, locationid,
|
|||||||
// query just computed, so the entry cannot disagree with the row it
|
// query just computed, so the entry cannot disagree with the row it
|
||||||
// came from.
|
// came from.
|
||||||
self := models.Productvariant{
|
self := models.Productvariant{
|
||||||
Tenantid: data[i].Tenantid,
|
Tenantid: data[i].Tenantid,
|
||||||
Productid: data[i].Productid,
|
Productid: data[i].Productid,
|
||||||
Variantproductid: data[i].Productid,
|
Variantproductid: data[i].Productid,
|
||||||
Variantname: variantLabelFor(data[i]),
|
Variantname: variantLabelFor(data[i]),
|
||||||
Status: "Active",
|
Status: "Active",
|
||||||
|
// The parent is one of its own sizes, so its entry has to carry
|
||||||
|
// money in the same field the others do. Without this the first
|
||||||
|
// option in every picker read 0 while the rest were priced.
|
||||||
|
Price: data[i].Price,
|
||||||
Variantproductname: data[i].Productname,
|
Variantproductname: data[i].Productname,
|
||||||
Variantprice: data[i].Price,
|
Variantprice: data[i].Price,
|
||||||
Variantstock: data[i].Productstock,
|
Variantstock: data[i].Productstock,
|
||||||
|
|||||||
@@ -118,6 +118,17 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
|
|||||||
return out, nil
|
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
|
var rows []models.Productvariant
|
||||||
err := r.db.
|
err := r.db.
|
||||||
Table("productvariants v").
|
Table("productvariants v").
|
||||||
@@ -126,6 +137,11 @@ func (r *productRepository) VariantsForProducts(tenantid, locationid int, produc
|
|||||||
p.productname AS variantproductname,
|
p.productname AS variantproductname,
|
||||||
COALESCE(p.unitvalue, '') AS variantunitvalue,
|
COALESCE(p.unitvalue, '') AS variantunitvalue,
|
||||||
COALESCE(p.productunit, '') AS variantproductunit,
|
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
|
-- The variant’s own override wins, then the outlet’s price, then the
|
||||||
-- master price. The override was being ignored entirely: a size
|
-- master price. The override was being ignored entirely: a size
|
||||||
-- priced differently from its product was sold at the product’s
|
-- 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
|
FROM productstocks ps
|
||||||
WHERE ps.productid = v.variantproductid AND ps.tenantid = v.tenantid AND ps.locationid = ?
|
WHERE ps.productid = v.variantproductid AND ps.tenantid = v.tenantid AND ps.locationid = ?
|
||||||
), 0) AS variantstock
|
), 0) AS variantstock
|
||||||
`, locationid, locationid).
|
`, locationid, locationid, locationid).
|
||||||
// INNER, and that is the intended filter: a variant whose product was
|
// INNER, and that is the intended filter: a variant whose product was
|
||||||
// deleted is not a size a shopper can be offered.
|
// deleted is not a size a shopper can be offered.
|
||||||
Joins("JOIN products p ON p.productid = v.variantproductid AND p.tenantid = v.tenantid").
|
Joins("JOIN products p ON p.productid = v.variantproductid AND p.tenantid = v.tenantid").
|
||||||
|
|||||||
Reference in New Issue
Block a user