-
$50.00
+
{price}
diff --git a/components/cart/CartSidebarView/CartSidebarView.tsx b/components/cart/CartSidebarView/CartSidebarView.tsx
index c918cf67a..5fa3c04d5 100644
--- a/components/cart/CartSidebarView/CartSidebarView.tsx
+++ b/components/cart/CartSidebarView/CartSidebarView.tsx
@@ -50,7 +50,11 @@ const CartSidebarView: FC = () => {
{items.map((item) => (
-
+
))}
diff --git a/components/ui/context.tsx b/components/ui/context.tsx
index 0c29063f9..f9014c194 100644
--- a/components/ui/context.tsx
+++ b/components/ui/context.tsx
@@ -43,7 +43,6 @@ export const useUI = () => {
}
function uiReducer(state: State, action: Action) {
- console.log(action)
switch (action.type) {
case 'OPEN_SIDEBAR': {
return {
diff --git a/utils/format-item-price.ts b/utils/format-item-price.ts
new file mode 100644
index 000000000..180f12182
--- /dev/null
+++ b/utils/format-item-price.ts
@@ -0,0 +1,41 @@
+function formatPrice({
+ amount,
+ currencyCode,
+ locale,
+}: {
+ amount: number
+ currencyCode: string
+ locale: string
+}) {
+ const formatCurrency = new Intl.NumberFormat(locale, {
+ style: 'currency',
+ currency: currencyCode,
+ })
+
+ return formatCurrency.format(amount)
+}
+
+export default function formatVariantPrice({
+ listPrice,
+ salePrice,
+ currencyCode,
+ locale,
+}: {
+ listPrice: number
+ salePrice: number
+ currencyCode: string
+ locale: string
+}) {
+ const hasDiscount = listPrice > salePrice
+ const formatDiscount = new Intl.NumberFormat(locale, { style: 'percent' })
+ const discount = hasDiscount
+ ? formatDiscount.format((listPrice - salePrice) / listPrice)
+ : null
+
+ const price = formatPrice({ amount: salePrice, currencyCode, locale })
+ const compareAtPrice = hasDiscount
+ ? formatPrice({ amount: listPrice, currencyCode, locale })
+ : null
+
+ return { price, compareAtPrice, discount }
+}