mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 03:31:23 +00:00
✨ feat: show bill discount and total
:%s
This commit is contained in:
@@ -93,8 +93,10 @@ export type Cart = {
|
||||
// The sum of all the prices of all the items in the cart.
|
||||
// Duties, taxes and discounts included.
|
||||
totalPrice: number
|
||||
totalQuantity: number
|
||||
// Discounts that have been applied on the cart.
|
||||
discounts?: Discount[]
|
||||
totalDiscount: number
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,7 @@
|
||||
export type Discount = {
|
||||
// The value of the discount, can be an amount or percentage
|
||||
value: number
|
||||
description?: string
|
||||
}
|
||||
|
||||
export type Measurement = {
|
||||
|
4
framework/vendure/schema.d.ts
vendored
4
framework/vendure/schema.d.ts
vendored
@@ -3053,7 +3053,9 @@ export type CartFragment = { __typename?: 'Order' } & Pick<
|
||||
| 'currencyCode'
|
||||
> & {
|
||||
shippingAddress?: Maybe<{ __typename?: 'OrderAddress' } & Pick<OrderAddress, 'streetLine1' | 'fullName' | 'city' | 'province' | 'postalCode' |'countryCode' | 'phoneNumber'>>
|
||||
discounts?: Maybe<{ __typename?: 'Discount' } & Pick<Discount, 'type' | 'amount' | 'amountWithTax'>>
|
||||
discounts: Array<
|
||||
{ __typename?: 'Discount' } & Pick<Discount, 'type' | 'description' | 'amount' | 'amountWithTax'>
|
||||
>
|
||||
customer?: Maybe<{ __typename?: 'Customer' } & Pick<Customer, 'id' | 'firstName' | 'lastName' | 'emailAddress'>>
|
||||
lines: Array<
|
||||
{ __typename?: 'OrderLine' } & Pick<
|
||||
|
@@ -9,6 +9,12 @@ export const cartFragment = /* GraphQL */ `
|
||||
total
|
||||
totalWithTax
|
||||
currencyCode
|
||||
discounts {
|
||||
type
|
||||
description
|
||||
amount
|
||||
amountWithTax
|
||||
}
|
||||
customer {
|
||||
id
|
||||
firstName
|
||||
|
@@ -36,10 +36,12 @@ export function normalizeFavoriteProductResult(item: Favorite) {
|
||||
|
||||
|
||||
export function normalizeCart(order: CartFragment): Cart {
|
||||
console.log("raw rs: ", order)
|
||||
return {
|
||||
id: order.id.toString(),
|
||||
createdAt: order.createdAt,
|
||||
taxesIncluded: true,
|
||||
totalQuantity: order.totalQuantity,
|
||||
lineItemsSubtotalPrice: order.subTotalWithTax / 100,
|
||||
currency: { code: order.currencyCode },
|
||||
subtotalPrice: order.subTotalWithTax / 100,
|
||||
@@ -58,6 +60,10 @@ export function normalizeCart(order: CartFragment): Cart {
|
||||
countryCode: order.shippingAddress?.countryCode || '',
|
||||
phoneNumber: order.shippingAddress?.phoneNumber || '',
|
||||
},
|
||||
totalDiscount: order.discounts?.reduce((total, item) => total + item.amountWithTax, 0) / 100 || 0,
|
||||
discounts: order.discounts.map(item => {
|
||||
return { value: item.amountWithTax, description: item.description }
|
||||
}),
|
||||
lineItems: order.lines?.map((l) => ({
|
||||
id: l.id,
|
||||
name: l.productVariant.name,
|
||||
|
Reference in New Issue
Block a user