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

Product options (unstable) #2482

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Product options (unstable) #2482

wants to merge 14 commits into from

Conversation

wizardlyhel
Copy link
Contributor

@wizardlyhel wizardlyhel commented Aug 29, 2024

Reworking product page to anticipate the new unstable API on product options and variants

WHY are these changes introduced?

2024-10 SFAPI will be introducing some changes to the product api.

WHAT is this pull request doing?

  • Clean up routes/product.$handle.tsx - We should no longer need all variants (WIP)
  • Provide convenient data function getProductOption to correctly maps variants to various new api data

HOW to test your changes?

This PR has to run on the unstable SFAPI version

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 Aug 29, 2024

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

Storefront Status Preview link Deployment details Last update (UTC)
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM
sitemap ✅ Successful (Logs) Preview deployment Inspect deployment September 18, 202410:12 PM

Learn more about Hydrogen's GitHub integration.


// Get the variant for the current option value if exists, else use the first selectable variant
// @ts-ignore
const variant: ProductVariant = variants[targetKey] || value.firstSelectableVariant;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be:

Suggested change
const variant: ProductVariant = variants[targetKey] || value.firstSelectableVariant;
const variant: ProductVariant = variants[targetKey] || product.selectedOrFirstAvailableVariant;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not. product.options.optionValues.firstSelectableVariant is the first available variant of this product variant. For example ...

We have product options as follows and the selected option is ['Red', 'Small'] and colors options is a combined listing.

[
  ['Red', 'Blue'],
  ['Small', 'Medium', 'Large]
]

Let's say I need to generate a link for Blue option, however, ['Blue', 'Small'] is an option that doesn't exist and the first available variant is ['Blue', 'Medium'].

This is where we need the product.options.optionValues.firstSelectableVariant which will return the variant for ['Blue', 'Medium']

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