From 471fcff5ff155cd460c2cd332c555d9af9f3c4c4 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 8 Jan 2025 15:46:50 +0530 Subject: [PATCH] fix: correct line item calculations when admentments exist --- src/modules/common/components/line-item-price/index.tsx | 8 +------- .../common/components/line-item-unit-price/index.tsx | 6 ++---- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/modules/common/components/line-item-price/index.tsx b/src/modules/common/components/line-item-price/index.tsx index ba9704ce..20f17e9a 100644 --- a/src/modules/common/components/line-item-price/index.tsx +++ b/src/modules/common/components/line-item-price/index.tsx @@ -15,14 +15,8 @@ const LineItemPrice = ({ currencyCode, }: LineItemPriceProps) => { const { total, original_total } = item - - const adjustmentsSum = (item.adjustments || []).reduce( - (acc, adjustment) => adjustment.amount + acc, - 0 - ) - const originalPrice = original_total - const currentPrice = total - adjustmentsSum + const currentPrice = total const hasReducedPrice = currentPrice < originalPrice return ( diff --git a/src/modules/common/components/line-item-unit-price/index.tsx b/src/modules/common/components/line-item-unit-price/index.tsx index 7391422b..82050525 100644 --- a/src/modules/common/components/line-item-unit-price/index.tsx +++ b/src/modules/common/components/line-item-unit-price/index.tsx @@ -1,4 +1,3 @@ -import { getPricesForVariant } from "@lib/util/get-product-price" import { convertToLocale } from "@lib/util/money" import { HttpTypes } from "@medusajs/types" import { clx } from "@medusajs/ui" @@ -14,8 +13,7 @@ const LineItemUnitPrice = ({ style = "default", currencyCode, }: LineItemUnitPriceProps) => { - const { total, original_total, unit_price } = item - + const { total, original_total } = item const hasReducedPrice = total < original_total const percentage_diff = Math.round( @@ -52,7 +50,7 @@ const LineItemUnitPrice = ({ data-testid="product-unit-price" > {convertToLocale({ - amount: unit_price, + amount: total / item.quantity, currency_code: currencyCode, })}