Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct line item calculations when amendments exist #450

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 1 addition & 7 deletions src/modules/common/components/line-item-price/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 2 additions & 4 deletions src/modules/common/components/line-item-unit-price/index.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -52,7 +50,7 @@ const LineItemUnitPrice = ({
data-testid="product-unit-price"
>
{convertToLocale({
amount: unit_price,
amount: total / item.quantity,
currency_code: currencyCode,
})}
</span>
Expand Down