8832 - Add style to facets (#188)

This commit is contained in:
Anders Gustafsson
2026-03-03 09:57:11 +01:00
committed by GitHub
parent f9e670e1c3
commit d25a8878f0
2 changed files with 25 additions and 7 deletions
+24 -7
View File
@@ -88,7 +88,7 @@ WHERE product_category.product_id = ?
async getCategoryBasedFacets(
productId: number,
): Promise<{ room: string[]; color: string[] }> {
): Promise<{ room: string[]; color: string[]; style: string[] }> {
ScopeAccess.validate(this.user).some([
Scopes.CATEGORIES_READ,
Scopes.CATEGORIES_PUBLIC_READ,
@@ -96,14 +96,18 @@ WHERE product_category.product_id = ?
const ROOMS_PARENT_ID = 270;
const COLORS_PARENT_ID = 1665;
const STYLES_PARENT_ID = 1814;
const { rows } = await this.cachedRaw(
`
WITH rooms AS (
SELECT lft, rgt FROM categories WHERE id = ?
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
),
colors AS (
SELECT lft, rgt FROM categories WHERE id = ?
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
),
styles AS (
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
)
SELECT
array_remove(
@@ -121,30 +125,43 @@ WHERE product_category.product_id = ?
END
),
NULL
) AS color
) AS color,
array_remove(
array_agg(
DISTINCT CASE
WHEN c.lft > styles.lft AND c.rgt < styles.rgt THEN c.name
END
),
NULL
) AS style
FROM product_category pc
JOIN categories c ON c.id = pc.category_id
JOIN categories_v2_lft_rgt c ON c.id = pc.category_id
CROSS JOIN rooms
CROSS JOIN colors
CROSS JOIN styles
WHERE pc.product_id = ?
AND (
(c.lft > rooms.lft AND c.rgt < rooms.rgt)
OR
(c.lft > colors.lft AND c.rgt < colors.rgt)
OR
(c.lft > styles.lft AND c.rgt < styles.rgt)
)
`,
[ROOMS_PARENT_ID, COLORS_PARENT_ID, productId],
[ROOMS_PARENT_ID, COLORS_PARENT_ID, STYLES_PARENT_ID, productId],
)
// @ts-ignore
.cache(MINUTE * 5);
const facetRow = rows[0] ?? { room: [], color: [] };
const facetRow = rows[0] ?? { room: [], color: [], style: [] };
const roomCategories: string[] = facetRow.room ?? [];
const colorCategories: string[] = facetRow.color ?? [];
const styleCategories: string[] = facetRow.style ?? [];
return {
room: roomCategories,
color: colorCategories,
style: styleCategories,
};
}
+1
View File
@@ -126,6 +126,7 @@ const Product = {
},
{ attribute: 'type', values: types },
{ attribute: 'room', values: categoryBasedFacets.room },
{ attribute: 'style', values: categoryBasedFacets.style },
];
},
};