9028: added pattern and extra wide option to facets (#191)

This commit is contained in:
Erik Tiekstra
2026-04-02 07:14:50 +02:00
committed by GitHub
parent d25a8878f0
commit bbb750e5f4
2 changed files with 51 additions and 7 deletions
+32 -6
View File
@@ -86,9 +86,12 @@ WHERE product_category.product_id = ?
return res;
}
async getCategoryBasedFacets(
productId: number,
): Promise<{ room: string[]; color: string[]; style: string[] }> {
async getCategoryBasedFacets(productId: number): Promise<{
room: string[];
color: string[];
style: string[];
pattern: string[];
}> {
ScopeAccess.validate(this.user).some([
Scopes.CATEGORIES_READ,
Scopes.CATEGORIES_PUBLIC_READ,
@@ -97,6 +100,7 @@ WHERE product_category.product_id = ?
const ROOMS_PARENT_ID = 270;
const COLORS_PARENT_ID = 1665;
const STYLES_PARENT_ID = 1814;
const PATTERNS_PARENT_ID = 1414;
const { rows } = await this.cachedRaw(
`
@@ -108,6 +112,9 @@ WHERE product_category.product_id = ?
),
styles AS (
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
),
patterns AS (
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
)
SELECT
array_remove(
@@ -133,12 +140,21 @@ WHERE product_category.product_id = ?
END
),
NULL
) AS style
) AS style,
array_remove(
array_agg(
DISTINCT CASE
WHEN c.lft > patterns.lft AND c.rgt < patterns.rgt THEN c.name
END
),
NULL
) AS pattern
FROM product_category pc
JOIN categories_v2_lft_rgt c ON c.id = pc.category_id
CROSS JOIN rooms
CROSS JOIN colors
CROSS JOIN styles
CROSS JOIN patterns
WHERE pc.product_id = ?
AND (
(c.lft > rooms.lft AND c.rgt < rooms.rgt)
@@ -146,22 +162,32 @@ WHERE product_category.product_id = ?
(c.lft > colors.lft AND c.rgt < colors.rgt)
OR
(c.lft > styles.lft AND c.rgt < styles.rgt)
OR
(c.lft > patterns.lft AND c.rgt < patterns.rgt)
)
`,
[ROOMS_PARENT_ID, COLORS_PARENT_ID, STYLES_PARENT_ID, productId],
[
ROOMS_PARENT_ID,
COLORS_PARENT_ID,
STYLES_PARENT_ID,
PATTERNS_PARENT_ID,
productId,
],
)
// @ts-ignore
.cache(MINUTE * 5);
const facetRow = rows[0] ?? { room: [], color: [], style: [] };
const facetRow = rows[0] ?? { room: [], color: [], style: [], pattern: [] };
const roomCategories: string[] = facetRow.room ?? [];
const colorCategories: string[] = facetRow.color ?? [];
const styleCategories: string[] = facetRow.style ?? [];
const patternCategories: string[] = facetRow.pattern ?? [];
return {
room: roomCategories,
color: colorCategories,
style: styleCategories,
pattern: patternCategories,
};
}
+19 -1
View File
@@ -25,6 +25,8 @@ import { getOrientationString, isRepeatingPattern } from '../datasources/utils';
import { sendMessage } from '../aws/sqs';
import { sendProductUpdatedEvent } from '../bernard/client';
const EXTRA_WIDE_RATIO_LIMIT = 2.4;
const ProductBlacklist = {
async market(parent, _args, { dataSources }) {
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getMarketById(
@@ -115,6 +117,12 @@ const Product = {
}),
]);
const patterns = product.printProducts.some(
(pp) => pp.groupId === ProductGroup.WALLPAPER,
)
? categoryBasedFacets.pattern
: [];
return [
{
attribute: 'color',
@@ -122,11 +130,21 @@ const Product = {
},
{
attribute: 'orientation',
values: orientations.map((value) => value.toLowerCase()),
values: orientations.map((value) => {
if (
product.fields.width / product.fields.height >
EXTRA_WIDE_RATIO_LIMIT
) {
return 'extra-wide';
}
return value.toLowerCase();
}),
},
{ attribute: 'type', values: types },
{ attribute: 'room', values: categoryBasedFacets.room },
{ attribute: 'style', values: categoryBasedFacets.style },
{ attribute: 'pattern', values: patterns },
];
},
};