diff --git a/components/product/ProductVariantSelector.tsx b/components/product/ProductVariantSelector.tsx
index c3cc686c..8d3f62f5 100644
--- a/components/product/ProductVariantSelector.tsx
+++ b/components/product/ProductVariantSelector.tsx
@@ -19,12 +19,11 @@ function VariantSelector({ product }: Props) {
{name}
{Object.entries(possibilities[name]).map(([value, link]) => {
- // TODO: bring it back on fresh 1.5.3
- // const partial = usePartialSection({ href: link });
+ const partial = usePartialSection({ href: link });
return (
-
-
+
+
);
})}
diff --git a/deno.json b/deno.json
index 31e2733d..dcfd60a7 100644
--- a/deno.json
+++ b/deno.json
@@ -3,7 +3,7 @@
"$store/": "./",
"deco/": "https://denopkg.com/deco-cx/deco@1.44.1/",
"apps/": "https://denopkg.com/deco-cx/apps@0.17.2/",
- "$fresh/": "https://deno.land/x/fresh@1.5.2/",
+ "$fresh/": "https://denopkg.com/denoland/fresh@7ad4610e3a42aba42638cbc1041b96ee58a9b29e/",
"preact": "https://esm.sh/preact@10.15.1",
"preact/": "https://esm.sh/preact@10.15.1/",
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
diff --git a/sdk/useVariantPossiblities.ts b/sdk/useVariantPossiblities.ts
index 14fb357d..6740d20a 100644
--- a/sdk/useVariantPossiblities.ts
+++ b/sdk/useVariantPossiblities.ts
@@ -1,39 +1,42 @@
-import type { ProductLeaf } from "apps/commerce/types.ts";
+import type { ProductLeaf, PropertyValue } from "apps/commerce/types.ts";
export type Possibilities = Record>;
+const hash = ({ name, value }: PropertyValue) => `${name}::${value}`;
+
+const omit = new Set(["category", "cluster", "RefId"]);
+
export const useVariantPossibilities = (
variants: ProductLeaf[],
selected: ProductLeaf,
): Possibilities => {
const possibilities: Possibilities = {};
- const selectedSpecs = new Map(
- (selected.additionalProperty ?? [])
- .map((s) => [s.name, s] as const),
- );
+ const selectedSpecs = new Set(selected.additionalProperty?.map(hash));
for (const variant of variants) {
- const { url, additionalProperty: specs = [] } = variant;
+ const { url, additionalProperty = [], productID } = variant;
+ const isSelected = productID === selected.productID;
+ const specs = additionalProperty.filter(({ name }) => !omit.has(name!));
for (let it = 0; it < specs.length; it++) {
const name = specs[it].name!;
const value = specs[it].value!;
+ if (omit.has(name)) continue;
+
if (!possibilities[name]) {
possibilities[name] = {};
}
- if (!possibilities[name][value]) {
- possibilities[name][value] = it === 0 ? url : undefined;
- }
-
- const isSelectable = specs.every((s) =>
- s.name === name || selectedSpecs.get(s.name)?.value === s.value
- );
+ // First row is always selectable
+ const isSelectable = it === 0 ||
+ specs.every((s) => s.name === name || selectedSpecs.has(hash(s)));
- if (isSelectable) {
- possibilities[name][value] = url;
- }
+ possibilities[name][value] = isSelected
+ ? url
+ : isSelectable
+ ? possibilities[name][value] || url
+ : possibilities[name][value];
}
}