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

fix: get first available item (sku) instead of first item (sku) #2141

Closed
wants to merge 2 commits into from

Conversation

eduardoformiga
Copy link
Member

@eduardoformiga eduardoformiga commented Dec 1, 2023

What's the purpose of this pull request?

This PR aims to get first available item (sku) instead of first item (sku) in products and suggestions queries.

Reference in v1: #1834

Address this issue

How it works?

While in search Page and PLP, FastStore API products/suggestions search query was getting always the first item (sku) from the product.items. In this case, we should get the first available item.

Before After
Screenshot 2023-11-30 at 19 29 12 Screenshot 2023-12-01 at 18 11 04

How to test it?

Check the preview link from starters store, with the tests mentioned in the issue.

Starters Deploy Preview

PR

Preview

References

https://storeframework.myvtex.com/api/io/_v/api/intelligent-search/product_search/trade-policy/1/?hideUnavailableItems=true&q=Apple%20Magic%20Mouse

Copy link

vercel bot commented Dec 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
faststore-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2023 8:33pm

Copy link

codesandbox-ci bot commented Dec 1, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2964077:

Sandbox Source
Store UI Typescript Configuration

Comment on lines 49 to 51
const maybeSku = product.items.find((item) =>
item.sellers.some((item) => inStock(item.commertialOffer))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized one thing: if a product has no available SKUs but matches the search query, previously, it would return as an Out Of Stock item.

The proposed logic would make it not appear at the search page in those cases.

I think for us to match the same behavior and fix the issue, we should make something like the suggestion below. I think we have to change this in v1 as well.

Suggested change
const maybeSku = product.items.find((item) =>
item.sellers.some((item) => inStock(item.commertialOffer))
)
const maybeSku = product.items.find((item) =>
item.sellers.some((item) => inStock(item.commertialOffer))
) ?? product.items[0]

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. we kind of do that in the product query, but it is missing for products and suggestions.

Done here

@eduardoformiga
Copy link
Member Author

after some discussion with the team, we understand that

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.

2 participants