feat: show bill discount and total

:%s
This commit is contained in:
lytrankieio123
2021-10-19 19:32:42 +07:00
parent 693935a480
commit 3abada4777
9 changed files with 61 additions and 29 deletions

View File

@@ -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
}
/**

View File

@@ -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 = {

View File

@@ -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<

View File

@@ -9,6 +9,12 @@ export const cartFragment = /* GraphQL */ `
total
totalWithTax
currencyCode
discounts {
type
description
amount
amountWithTax
}
customer {
id
firstName

View File

@@ -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,