variants as a single product
This commit is contained in:
@@ -85,3 +85,35 @@ func InStockOnlyGrouped(groups []models.Tenantproducts) []models.Tenantproducts
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// WithoutVariantChildren drops the products that are a size of another one.
|
||||
//
|
||||
// The companion to InStockOnlyGrouped, and applied only for the customer app.
|
||||
// A shop stocking Aachi Baby Fryums in 100g, 500g and 1kg has three rows; the
|
||||
// shopper should meet one product with three sizes, not three near-identical
|
||||
// listings they have to read the suffix of to tell apart.
|
||||
//
|
||||
// The group's visible row is the PARENT, and it carries the whole set in
|
||||
// `variantoptions` — including its own size — so nothing is unreachable: every
|
||||
// size is one tap away from the one row that remains.
|
||||
//
|
||||
// The console is deliberately unaffected. A merchant prices, restocks and
|
||||
// publishes each size separately, so all three must stay visible there.
|
||||
func WithoutVariantChildren(groups []models.Tenantproducts, isChild map[int]bool) []models.Tenantproducts {
|
||||
if len(isChild) == 0 {
|
||||
return groups
|
||||
}
|
||||
out := make([]models.Tenantproducts, 0, len(groups))
|
||||
for _, group := range groups {
|
||||
kept := make([]models.Products, 0, len(group.Products))
|
||||
for _, product := range group.Products {
|
||||
if isChild[product.Productid] {
|
||||
continue
|
||||
}
|
||||
kept = append(kept, product)
|
||||
}
|
||||
group.Products = kept
|
||||
out = append(out, group)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user