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

feat: product list return kitlook array #98

Closed
wants to merge 3 commits into from

Conversation

jonathanwlopes
Copy link
Contributor

Here we need an array with all kitlook products

The isKit property was added to the loader because this mapping needs to go through each item in the list, and in stores that do not use kitlook it will not be necessary to activate

When mapped and a kitlook product is found, the main product will have an array of kitItems

This array has the kit products, with the standard product information

Reason: In some cases the retailer needs to remove items from stock individually from the kit created on the platform, with this array we can handle item by item in the frontend, previously when used this loader only had the entire kit product without its individual items

Comment on lines 149 to 174
const [product] = await vcsDeprecated
[
`GET /api/catalog_system/pub/products/search/:term?`
](
{
...params,
fq: [`skuId:${item.items[0].itemId}`],
},
{
deco: { cache: "stale-while-revalidate" },
headers: withSegmentCookie(segment),
},
).then((res: Response) => res.json()) as VTEXProduct[];

const kitItems: VTEXProduct[] =
product.items[0].isKit && product.items[0].kitItems
? await vcsDeprecated
["GET /api/catalog_system/pub/products/search/:term?"]({
...params,
fq: product.items[0].kitItems.map((item) =>
`skuId:${item.itemId}`
),
}, { deco: { cache: "stale-while-revalidate" } }).then((
res: Response,
) => res.json())
: [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're doing multiple requests here when you could batch it

Please, follow the withIsSimilarTo function down below that you'll find something already implemented for this.

Copy link
Contributor Author

@jonathanwlopes jonathanwlopes Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code.

Now we have a single source of truth to return products with kitlook, facilitating implementation in other layers after this has been agreed.

The API: /api/io/_v/api/intelligent-search/product_search/*facets it does not return kit information, which is why when you activate the kit option we look for the products it contains in the legacy API

The legacy API itself returns if the product is a kit and if it is the ids of the items that make up the kitlook

Therefore, I make a request to have these products and format in schema.org standards

The return we have is:

image

[!EDIT]
If the product does not have a kit or the Active Kit Items option is not activated, the return remains unchanged.

With this data in the product, we can manipulate kit products on shelves on any page, as well as send each kit item to checkout

Thanks.

@Brunight
Copy link
Contributor

Hi guys! @jonathanwlopes went on a trip so I'm resuming his PR at #120; this one should be closed

@tlgimenes
Copy link
Collaborator

tlgimenes commented Oct 11, 2023

related to #119

@tlgimenes tlgimenes closed this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants