Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-toys-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@godaddy/react": patch
---

Add currency code from sku for product card
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ export function useAddToCart(options?: UseAddToCartOptions) {
storeId: context?.storeId || '',
channelId: context?.channelId || '',
},
totals: {
subTotal: { value: 0, currencyCode: 'USD' },
shippingTotal: { value: 0, currencyCode: 'USD' },
discountTotal: { value: 0, currencyCode: 'USD' },
feeTotal: { value: 0, currencyCode: 'USD' },
taxTotal: { value: 0, currencyCode: 'USD' },
total: { value: 0, currencyCode: 'USD' },
},
},
context.storeId!,
context.clientId!,
Expand Down
9 changes: 6 additions & 3 deletions packages/react/src/components/storefront/product-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function ProductCard({
const priceMax = product?.priceRange?.max || priceMin;
const compareAtMin = product?.compareAtPriceRange?.min;
const isOnSale = compareAtMin && compareAtMin > priceMin;
const currencyCode =
product?.skus?.edges?.find(
edge => edge?.node?.prices?.edges?.[0]?.node?.value?.currencyCode
)?.node?.prices?.edges?.[0]?.node?.value?.currencyCode || 'USD';
const hasOptions = false;
const isPriceRange = priceMin !== priceMax;

Expand Down Expand Up @@ -225,12 +229,11 @@ export function ProductCard({
</p>
<div className='flex items-center justify-between pt-2 mt-auto'>
<span className='text-md font-semibold text-foreground'>
{/* TODO: Use dynamic currency from store/product when available instead of hardcoded USD */}
{isPriceRange
? `${formatCurrency({ amount: priceMin, currencyCode: 'USD', inputInMinorUnits: true })} - ${formatCurrency({ amount: priceMax, currencyCode: 'USD', inputInMinorUnits: true })}`
? `${formatCurrency({ amount: priceMin, currencyCode, inputInMinorUnits: true })} - ${formatCurrency({ amount: priceMax, currencyCode, inputInMinorUnits: true })}`
: formatCurrency({
amount: priceMin,
currencyCode: 'USD',
currencyCode,
inputInMinorUnits: true,
})}
</span>
Expand Down
16 changes: 12 additions & 4 deletions packages/react/src/components/storefront/product-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ export function ProductDetails({
const compareAtMax = selectedSku
? compareAtMin
: product?.compareAtPriceRange?.max;
const currencyCode =
skuPrice?.value?.currencyCode ||
product?.skus?.edges?.find(
edge => edge?.node?.prices?.edges?.[0]?.node?.value?.currencyCode
)?.node?.prices?.edges?.[0]?.node?.value?.currencyCode ||
'USD';
const compareAtCurrencyCode =
skuPrice?.compareAtValue?.currencyCode || currencyCode;
const isOnSale = compareAtMin && compareAtMin > priceMin;
const isPriceRange = priceMin !== priceMax;
const isCompareAtPriceRange =
Expand Down Expand Up @@ -540,20 +548,20 @@ export function ProductDetails({
<div className='flex items-baseline gap-3 mb-4'>
<span className='text-2xl font-bold text-foreground'>
{isPriceRange
? `${formatCurrency({ amount: priceMin, currencyCode: 'USD', inputInMinorUnits: true })} - ${formatCurrency({ amount: priceMax, currencyCode: 'USD', inputInMinorUnits: true })}`
? `${formatCurrency({ amount: priceMin, currencyCode, inputInMinorUnits: true })} - ${formatCurrency({ amount: priceMax, currencyCode, inputInMinorUnits: true })}`
: formatCurrency({
amount: priceMin,
currencyCode: 'USD',
currencyCode,
inputInMinorUnits: true,
})}
</span>
{isOnSale && compareAtMin && (
<span className='text-lg text-muted-foreground line-through'>
{isCompareAtPriceRange
? `${formatCurrency({ amount: compareAtMin, currencyCode: 'USD', inputInMinorUnits: true })} - ${formatCurrency({ amount: compareAtMax!, currencyCode: 'USD', inputInMinorUnits: true })}`
? `${formatCurrency({ amount: compareAtMin, currencyCode: compareAtCurrencyCode, inputInMinorUnits: true })} - ${formatCurrency({ amount: compareAtMax!, currencyCode: compareAtCurrencyCode, inputInMinorUnits: true })}`
: formatCurrency({
amount: compareAtMin,
currencyCode: 'USD',
currencyCode: compareAtCurrencyCode,
inputInMinorUnits: true,
})}
</span>
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/lib/godaddy/catalog-storefront-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export const SkuGroupsQuery = graphql(`
id
label
name
prices(first: 1) {
edges {
node {
value {
currencyCode
}
}
}
}
inventoryCounts {
edges {
node {
Expand Down Expand Up @@ -133,6 +142,15 @@ export const SkuGroupQuery = graphql(`
id
label
name
prices(first: 1) {
edges {
node {
value {
currencyCode
}
}
}
}
inventoryCounts {
edges {
node {
Expand Down