mirror of
https://github.com/vercel/commerce.git
synced 2025-05-14 13:47:49 +00:00
variants
This commit is contained in:
parent
5027363c3e
commit
2b9fe58832
@ -84,6 +84,7 @@ export function VariantSelector({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
// TODO: Does now work under old Next.js
|
// TODO: Does now work under old Next.js
|
||||||
// router.replace(optionUrl, { scroll: false });
|
// router.replace(optionUrl, { scroll: false });
|
||||||
|
router.replace(optionUrl);
|
||||||
}}
|
}}
|
||||||
title={`${option.name} ${value}${!isAvailableForSale ? ' (Out of Stock)' : ''}`}
|
title={`${option.name} ${value}${!isAvailableForSale ? ' (Out of Stock)' : ''}`}
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
@ -541,53 +541,16 @@ export function transformToProduct(adventure: any): Product {
|
|||||||
title: adventure.title,
|
title: adventure.title,
|
||||||
availableForSale: true, // We're assuming that all adventures are available for sale
|
availableForSale: true, // We're assuming that all adventures are available for sale
|
||||||
selectedOptions: [
|
selectedOptions: [
|
||||||
{ name: 'activity', value: adventure.activity },
|
{ name: 'Stay Duration', value: 'Normal' },
|
||||||
{ name: 'adventureType', value: adventure.adventureType },
|
|
||||||
{ name: 'tripLength', value: adventure.tripLength },
|
|
||||||
{ name: 'Group Size', value: 'Normal' }
|
{ name: 'Group Size', value: 'Normal' }
|
||||||
// { name: 'difficulty', value: adventure.difficulty }
|
|
||||||
],
|
],
|
||||||
price
|
price
|
||||||
};
|
};
|
||||||
|
|
||||||
const smallGroupVariant = {
|
const groupSizeValues = ['Small', 'Normal', 'Large'];
|
||||||
id: 'smallGroupVariant',
|
const durationValues = ['Short', 'Normal', 'Extended Stay'];
|
||||||
title: 'Small Group',
|
|
||||||
availableForSale: true,
|
|
||||||
selectedOptions: [
|
|
||||||
{
|
|
||||||
name: 'Group Size',
|
|
||||||
value: 'Small'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
price: price
|
|
||||||
};
|
|
||||||
|
|
||||||
const normalGroupVariant = {
|
const variants: ProductVariant[] = [];
|
||||||
id: 'normalGroupVariant',
|
|
||||||
title: 'Normal Group',
|
|
||||||
availableForSale: true,
|
|
||||||
selectedOptions: [
|
|
||||||
{
|
|
||||||
name: 'Group Size',
|
|
||||||
value: 'Normal'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
price: price
|
|
||||||
};
|
|
||||||
|
|
||||||
const largeGroupVariant = {
|
|
||||||
id: 'largeGroupVariant',
|
|
||||||
title: 'Large Group',
|
|
||||||
availableForSale: true,
|
|
||||||
selectedOptions: [
|
|
||||||
{
|
|
||||||
name: 'Group Size',
|
|
||||||
value: 'Large'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
price: price
|
|
||||||
};
|
|
||||||
|
|
||||||
const groupSizeProductOption = {
|
const groupSizeProductOption = {
|
||||||
id: 'groupSizeProductOption',
|
id: 'groupSizeProductOption',
|
||||||
@ -601,6 +564,27 @@ export function transformToProduct(adventure: any): Product {
|
|||||||
values: ['Short', 'Normal', 'Extended Stay']
|
values: ['Short', 'Normal', 'Extended Stay']
|
||||||
};
|
};
|
||||||
|
|
||||||
|
groupSizeValues.forEach((groupSize) => {
|
||||||
|
durationValues.forEach((duration) => {
|
||||||
|
variants.push({
|
||||||
|
id: `${id}-${groupSize}-${duration}-variant`,
|
||||||
|
title: `${groupSize} / ${duration}`,
|
||||||
|
availableForSale: true, // We're assuming that all adventures are available for sale
|
||||||
|
selectedOptions: [
|
||||||
|
{ name: 'Group Size', value: groupSize },
|
||||||
|
{ name: 'Stay Duration', value: duration }
|
||||||
|
],
|
||||||
|
price: {
|
||||||
|
amount:
|
||||||
|
priceParts[0].substring(1) +
|
||||||
|
(groupSize === 'Small' ? -100 : groupSize === 'Large' ? 600 : 0) +
|
||||||
|
(duration === 'Short' ? -100 : duration === 'Extended Stay' ? 700 : 0),
|
||||||
|
currencyCode: priceParts[1]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const product: Product = {
|
const product: Product = {
|
||||||
id,
|
id,
|
||||||
handle,
|
handle,
|
||||||
@ -608,7 +592,7 @@ export function transformToProduct(adventure: any): Product {
|
|||||||
title: adventure.title,
|
title: adventure.title,
|
||||||
description: adventure.description.html,
|
description: adventure.description.html,
|
||||||
descriptionHtml: adventure.itinerary.html,
|
descriptionHtml: adventure.itinerary.html,
|
||||||
options: [groupSizeProductOption],
|
options: [groupSizeProductOption, durationProductOption],
|
||||||
priceRange: {
|
priceRange: {
|
||||||
maxVariantPrice: price,
|
maxVariantPrice: price,
|
||||||
minVariantPrice: price
|
minVariantPrice: price
|
||||||
@ -626,8 +610,7 @@ export function transformToProduct(adventure: any): Product {
|
|||||||
description: adventure.description.html
|
description: adventure.description.html
|
||||||
},
|
},
|
||||||
tags: [],
|
tags: [],
|
||||||
//variants: { edges: [{ node: mockProductVariant }] },
|
variants: variants,
|
||||||
variants: [smallGroupVariant, normalGroupVariant, largeGroupVariant],
|
|
||||||
updatedAt: new Date().toISOString()
|
updatedAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user