Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupBy editable in Recommendations by Cross Selling #467

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Parameter `groupBy` into `recommendations` and `productRecommendations` resolvers and `groupByProduct` in `crossSelling` search client.

## [1.67.1] - 2023-10-18

Expand Down
4 changes: 2 additions & 2 deletions node/clients/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ export class Search extends AppClient {
metric: 'search-category',
})

public crossSelling = (id: string, type: SearchCrossSellingTypes) =>
public crossSelling = (id: string, type: SearchCrossSellingTypes, groupByProduct = true) =>
this.get<SearchProduct[]>(
`/pub/products/crossselling/${type}/${id}?groupByProduct=true`,
`/pub/products/crossselling/${type}/${id}?groupByProduct=${groupByProduct}`,
{
metric: 'search-crossSelling',
}
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/node": "^12.0.0",
"@types/qs": "^6.5.1",
"@types/ramda": "^0.26.21",
"@vtex/api": "6.45.22",
"@vtex/api": "6.46.1",
"@vtex/tsconfig": "^0.6.0",
"eslint": "^5.15.3",
"eslint-config-vtex": "^10.1.0",
Expand Down
13 changes: 11 additions & 2 deletions node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ enum CrossSellingInput {
accessories = 'accessories',
}

enum CrossSellingGroupByInput {
PRODUCT = 'PRODUCT',
NONE = 'NONE',
}
iago1501 marked this conversation as resolved.
Show resolved Hide resolved

interface ProductRecommendationArg {
identifier?: ProductIndentifier
type?: CrossSellingInput
groupBy?: CrossSellingGroupByInput
}

interface ProductsByIdentifierArgs {
Expand Down Expand Up @@ -585,7 +591,7 @@ export const queries = {

productRecommendations: async (
_: any,
{ identifier, type }: ProductRecommendationArg,
{ identifier, type, groupBy }: ProductRecommendationArg,
ctx: Context
) => {
if (identifier == null || type == null) {
Expand All @@ -598,9 +604,12 @@ export const queries = {
productId = product!.productId
}

const groupByProduct = groupBy === CrossSellingGroupByInput.PRODUCT ? true : false

const products = await ctx.clients.search.crossSelling(
productId,
searchType
searchType,
groupByProduct
)

searchFirstElements(products, 0, ctx.clients.search)
Expand Down
5 changes: 4 additions & 1 deletion node/resolvers/search/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ export const resolvers = {
return objToNameValue('name', 'values', omit(notPG, product))
},

recommendations: (product: SearchProduct) => product,
recommendations: (product: SearchProduct, args: any) => {
const { groupBy } = args
return { product, groupBy }
},

description: formatTranslatableProp<SearchProduct, 'description', 'productId'>(
'description',
Expand Down
54 changes: 45 additions & 9 deletions node/resolvers/search/recommendation.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,64 @@
import { SearchCrossSellingTypes } from './utils'
import { GroupByCrossSellingTypes, SearchCrossSellingTypes } from './utils'

interface RecommendationParentProps {
product: SearchProduct
groupBy: string
}

export const resolvers = {
Recommendation: {
buy: (
{ productId }: SearchProduct,
{ product: {productId},
groupBy = GroupByCrossSellingTypes.PRODUCT
}: RecommendationParentProps,
_: any,
{ clients: { search } }: Context
) =>
search.crossSelling(
{
const groupByProduct =
groupBy === GroupByCrossSellingTypes.PRODUCT ? true : false

return search.crossSelling(
productId,
SearchCrossSellingTypes.whoboughtalsobought
),
SearchCrossSellingTypes.whoboughtalsobought,
groupByProduct
)
},

similars: (
{ productId }: SearchProduct,
{ product: {productId},
groupBy = GroupByCrossSellingTypes.PRODUCT
}: RecommendationParentProps,
_: any,
{ clients: { search } }: Context
) => search.crossSelling(productId, SearchCrossSellingTypes.similars),
) =>
{
const groupByProduct =
groupBy === GroupByCrossSellingTypes.PRODUCT ? true : false

return search.crossSelling(
productId,
SearchCrossSellingTypes.similars,
groupByProduct
)
},

view: (
{ productId }: SearchProduct,
{ product: {productId},
groupBy = GroupByCrossSellingTypes.PRODUCT
}: RecommendationParentProps,
_: any,
{ clients: { search } }: Context
) =>
search.crossSelling(productId, SearchCrossSellingTypes.whosawalsosaw),
{
const groupByProduct =
groupBy === GroupByCrossSellingTypes.PRODUCT ? true : false

return search.crossSelling(
productId,
SearchCrossSellingTypes.whosawalsosaw,
groupByProduct
)
},
},
}
5 changes: 5 additions & 0 deletions node/resolvers/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export enum SearchCrossSellingTypes {
suggestions = 'suggestions',
}

export enum GroupByCrossSellingTypes {
PRODUCT = 'PRODUCT',
NONE = 'NONE',
}

const pageTypeMapping: Record<string, string> = {
Brand: 'brand',
Department: 'department',
Expand Down
8 changes: 4 additions & 4 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,10 @@
lodash.unescape "4.0.1"
semver "5.5.0"

"@vtex/api@6.45.22":
version "6.45.22"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.22.tgz#fa9bbfde1a4d4fbbaf6cce9f6dbc9bb9ee929ba3"
integrity sha512-g5cGUDhF4FADgSMpQmce/bnIZumwGlPG2cabwbQKIQ+cCFMZqOEM/n+YQb1+S8bCyHkzW3u/ZABoyCKi5/nxxg==
"@vtex/api@6.46.1":
version "6.46.1"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.46.1.tgz#55a8755ae48f5400e7f1ed1921cd547950bb7a2a"
integrity sha512-geoxVvyWoQpOQ70Zmx3M8SBkRoGOS/bp9Gy26M+iCue63jofVSwmFz1zf66EaHA1PKOJNRgQPFwY+oeDE1U2lQ==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand Down
Loading