9028: added pattern and extra wide option to facets (#191)
This commit is contained in:
@@ -86,9 +86,12 @@ WHERE product_category.product_id = ?
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCategoryBasedFacets(
|
async getCategoryBasedFacets(productId: number): Promise<{
|
||||||
productId: number,
|
room: string[];
|
||||||
): Promise<{ room: string[]; color: string[]; style: string[] }> {
|
color: string[];
|
||||||
|
style: string[];
|
||||||
|
pattern: string[];
|
||||||
|
}> {
|
||||||
ScopeAccess.validate(this.user).some([
|
ScopeAccess.validate(this.user).some([
|
||||||
Scopes.CATEGORIES_READ,
|
Scopes.CATEGORIES_READ,
|
||||||
Scopes.CATEGORIES_PUBLIC_READ,
|
Scopes.CATEGORIES_PUBLIC_READ,
|
||||||
@@ -97,6 +100,7 @@ WHERE product_category.product_id = ?
|
|||||||
const ROOMS_PARENT_ID = 270;
|
const ROOMS_PARENT_ID = 270;
|
||||||
const COLORS_PARENT_ID = 1665;
|
const COLORS_PARENT_ID = 1665;
|
||||||
const STYLES_PARENT_ID = 1814;
|
const STYLES_PARENT_ID = 1814;
|
||||||
|
const PATTERNS_PARENT_ID = 1414;
|
||||||
|
|
||||||
const { rows } = await this.cachedRaw(
|
const { rows } = await this.cachedRaw(
|
||||||
`
|
`
|
||||||
@@ -108,6 +112,9 @@ WHERE product_category.product_id = ?
|
|||||||
),
|
),
|
||||||
styles AS (
|
styles AS (
|
||||||
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
|
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
|
||||||
|
),
|
||||||
|
patterns AS (
|
||||||
|
SELECT lft, rgt FROM categories_v2_lft_rgt WHERE id = ?
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
array_remove(
|
array_remove(
|
||||||
@@ -133,12 +140,21 @@ WHERE product_category.product_id = ?
|
|||||||
END
|
END
|
||||||
),
|
),
|
||||||
NULL
|
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
|
FROM product_category pc
|
||||||
JOIN categories_v2_lft_rgt c ON c.id = pc.category_id
|
JOIN categories_v2_lft_rgt c ON c.id = pc.category_id
|
||||||
CROSS JOIN rooms
|
CROSS JOIN rooms
|
||||||
CROSS JOIN colors
|
CROSS JOIN colors
|
||||||
CROSS JOIN styles
|
CROSS JOIN styles
|
||||||
|
CROSS JOIN patterns
|
||||||
WHERE pc.product_id = ?
|
WHERE pc.product_id = ?
|
||||||
AND (
|
AND (
|
||||||
(c.lft > rooms.lft AND c.rgt < rooms.rgt)
|
(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)
|
(c.lft > colors.lft AND c.rgt < colors.rgt)
|
||||||
OR
|
OR
|
||||||
(c.lft > styles.lft AND c.rgt < styles.rgt)
|
(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
|
// @ts-ignore
|
||||||
.cache(MINUTE * 5);
|
.cache(MINUTE * 5);
|
||||||
|
|
||||||
const facetRow = rows[0] ?? { room: [], color: [], style: [] };
|
const facetRow = rows[0] ?? { room: [], color: [], style: [], pattern: [] };
|
||||||
const roomCategories: string[] = facetRow.room ?? [];
|
const roomCategories: string[] = facetRow.room ?? [];
|
||||||
const colorCategories: string[] = facetRow.color ?? [];
|
const colorCategories: string[] = facetRow.color ?? [];
|
||||||
const styleCategories: string[] = facetRow.style ?? [];
|
const styleCategories: string[] = facetRow.style ?? [];
|
||||||
|
const patternCategories: string[] = facetRow.pattern ?? [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
room: roomCategories,
|
room: roomCategories,
|
||||||
color: colorCategories,
|
color: colorCategories,
|
||||||
style: styleCategories,
|
style: styleCategories,
|
||||||
|
pattern: patternCategories,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import { getOrientationString, isRepeatingPattern } from '../datasources/utils';
|
|||||||
import { sendMessage } from '../aws/sqs';
|
import { sendMessage } from '../aws/sqs';
|
||||||
import { sendProductUpdatedEvent } from '../bernard/client';
|
import { sendProductUpdatedEvent } from '../bernard/client';
|
||||||
|
|
||||||
|
const EXTRA_WIDE_RATIO_LIMIT = 2.4;
|
||||||
|
|
||||||
const ProductBlacklist = {
|
const ProductBlacklist = {
|
||||||
async market(parent, _args, { dataSources }) {
|
async market(parent, _args, { dataSources }) {
|
||||||
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getMarketById(
|
return (<MarketLocaleAPI>dataSources.marketLocaleApi).getMarketById(
|
||||||
@@ -115,6 +117,12 @@ const Product = {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const patterns = product.printProducts.some(
|
||||||
|
(pp) => pp.groupId === ProductGroup.WALLPAPER,
|
||||||
|
)
|
||||||
|
? categoryBasedFacets.pattern
|
||||||
|
: [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
attribute: 'color',
|
attribute: 'color',
|
||||||
@@ -122,11 +130,21 @@ const Product = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
attribute: 'orientation',
|
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: 'type', values: types },
|
||||||
{ attribute: 'room', values: categoryBasedFacets.room },
|
{ attribute: 'room', values: categoryBasedFacets.room },
|
||||||
{ attribute: 'style', values: categoryBasedFacets.style },
|
{ attribute: 'style', values: categoryBasedFacets.style },
|
||||||
|
{ attribute: 'pattern', values: patterns },
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user