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

Support 2k variant, combined listing usage with getProductOptions #2659

Merged
merged 24 commits into from
Dec 10, 2024

Conversation

wizardlyhel
Copy link
Contributor

WHY are these changes introduced?

Uses the new product fields to build the product form in support of 2k variant and combined listing:

Provides:

  • getProductOptions function that will return product options along with the states of this current variant

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

shopify bot commented Nov 28, 2024

Oxygen deployed a preview of your hl-getProductOptions branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment December 10, 2024 5:13 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment December 10, 2024 5:13 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment December 10, 2024 5:13 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment December 10, 2024 5:13 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment December 10, 2024 5:13 PM

Learn more about Hydrogen's GitHub integration.

@wizardlyhel wizardlyhel marked this pull request as ready for review December 3, 2024 22:28

This comment has been minimized.

@wizardlyhel
Copy link
Contributor Author

Doubled checked on the newly generated types - the SitemapQuery is suppose to go away since it got migrated to the Hydrogen package. We just forgot to update the generated types in the examples.

product: RecursivePartial<Product>,
): ProductVariant[] {
// Checks for valid product input
const checkedProduct = checkProductParam(product);
Copy link
Contributor

@blittle blittle Dec 9, 2024

Choose a reason for hiding this comment

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

Why does sometimes checkProductParm "checkAll" vs other times not? Looks like it has to do with whether it checks for PRODUCT_INPUTS_EXTRA existing on the return product object. But why would we want to check that in one spot but not the other?

Copy link
Contributor Author

@wizardlyhel wizardlyhel Dec 9, 2024

Choose a reason for hiding this comment

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

I want to reuse the checkProductParam with the getAdjacentAndFirstAvailableVariants.

The purpose of getAdjacentAndFirstAvailableVariants is to return an unique list of variants found in options.optionValues.firstAvailableVariant, adjacentVariants, and selectedOrFirstAvailableVariant.

The getAdjacentAndFirstAvailableVariants doesn't require other fields to be present like encodedVariantExistence, and encodedVariantAvailability.

Copy link
Contributor

@blittle blittle left a comment

Choose a reason for hiding this comment

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

In testing it, I noticed going from the collection page to a product, I often landed directly on an unavailable variant. This confused me because we have all the logic for firstAvailableVariant. It turns out we hard-code adding the first selected option in the template: https://github.com/Shopify/hydrogen/blob/main/templates/skeleton/app/lib/variants.ts#L45

I suggest we update that code to remove the selected option query parameter. That will make it automatically find and select the first available variant.

@wizardlyhel
Copy link
Contributor Author

Good catch - I thought I found all of them

@wizardlyhel
Copy link
Contributor Author

@blittle I have addressed the following:

  • All product anchor links are now without selected option params
    • collection.$handle and collection.all routes renders normal products/$handle link and continues utilizing useVariantUrl (to maintain locale paths)
    • search and predictive search queries for selectedOrFirstAvailableVariant in place of first variant
  • I have exported a new hook useSelectedOptionInUrlParam
    • test and docs are written for this new hook
    • It will add the selected option of the selectedOrFirstAvailableVariant to the url when landing on a product page, even if the url itself may contain other search params
  • I left the export of mapSelectedProductOptionToObject as is. I think it is still useful to have but you think we shouldn't export it, let me know and I'll take it out
  • I have remove the displaying single option value so that we keep the same product form UI look as before

@blittle
Copy link
Contributor

blittle commented Dec 10, 2024

/snapit

Copy link
Contributor

🫰✨ Thanks @blittle! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20241210144810",
"@shopify/hydrogen": "0.0.0-snapshot-20241210144810"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

'@shopify/hydrogen': patch
---

Introduce `getProductOptions`, `getAdjacentAndFirstAvailableVariants`, and `mapSelectedProductOptionToObject` to support combined listing products and products with 2000 variants limit.

Choose a reason for hiding this comment

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

Also needs the new useSelectedOptionInUrlParam hook now

@wizardlyhel
Copy link
Contributor Author

/snapit

Copy link
Contributor

🫰✨ Thanks @wizardlyhel! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20241210171242",
"@shopify/hydrogen": "0.0.0-snapshot-20241210171242"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

@wizardlyhel wizardlyhel merged commit a57d526 into main Dec 10, 2024
12 checks passed
@wizardlyhel wizardlyhel deleted the hl-getProductOptions branch December 10, 2024 21:17
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.

4 participants