Skip to content

Commit

Permalink
update changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardlyhel committed Dec 10, 2024
1 parent b8955ad commit f0b3fb7
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions .changeset/lemon-beans-drum.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import {
Analytics,
useOptimisticVariant,
getAdjacentAndFirstAvailableVariants,
+ mapSelectedProductOptionToObject,
+ useSelectedOptionInUrlParam,
} from '@shopify/hydrogen';

export default function Product() {
Expand All @@ -130,23 +130,7 @@ export default function Product() {

+ // Sets the search param to the selected variant without navigation
+ // only when no search params are set in the url
+ useEffect(() => {
+ const searchParams = new URLSearchParams(
+ mapSelectedProductOptionToObject(
+ selectedVariant.selectedOptions || [],
+ ),
+ );

+ if (window.location.search === '' && searchParams.toString() !== '') {
+ window.history.replaceState(
+ {},
+ '',
+ `${location.pathname}?${searchParams.toString()}`,
+ );
+ }
+ }, [
+ JSON.stringify(selectedVariant.selectedOptions),
+ ]);
+ useSelectedOptionInUrlParam(selectedVariant.selectedOptions);
```

5. Get the product options array using `getProductOptions`
Expand All @@ -158,7 +142,7 @@ import {
useOptimisticVariant,
+ getProductOptions,
getAdjacentAndFirstAvailableVariants,
mapSelectedProductOptionToObject,
useSelectedOptionInUrlParam,
} from '@shopify/hydrogen';

export default function Product() {
Expand Down

0 comments on commit f0b3fb7

Please sign in to comment.