add labels
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-05-30 03:03:39 +07:00
parent 59e60c4be1
commit 4335d14090
5 changed files with 304 additions and 201 deletions
@@ -22,6 +22,7 @@ type Product struct {
Variants []*crm.Variant `json:"variants"`
Characteristics []*crm.Characteristic `json:"characteristics"`
Category int64 `json:"category"`
Labels []*crm.Label `json:"labels"`
}
var (
@@ -58,6 +59,7 @@ func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product,
res := make([]*crm.Product, 0, len(products))
for _, product := range products {
if id == 0 || product.Category == id {
s.enrichedProduct(product)
res = append(res, product)
}
}
@@ -96,7 +98,9 @@ func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, err
Variants: product.Variants,
Characteristics: product.Characteristics,
Category: product.Category,
Labels: product.Labels,
}
s.enrichedProduct(res)
for _, p := range products {
if p.Group == product.Group {
image := ""
@@ -133,6 +137,12 @@ func (s *storageFile) GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Cate
return breadcrumbs, nil
}
func (s *storageFile) enrichedProduct(product *crm.Product) {
if len(product.Variants) > 1 {
product.Labels = append(product.Labels, &crm.Label{Name: "Оптом дешевле"})
}
}
func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {
for _, category := range categories {
if category.Id == id {