-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feat/create cart #19
Feat/create cart #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SyliusCart, SyliusCartItem } from '../sylius-types/cart-types'; | ||
import { SyliusProductOption, SyliusProductOptionValue } from '../sylius-types/product-types'; | ||
import { Cart, CartItem } from '../types'; | ||
import { normalizeProduct } from './product-normalizer'; | ||
import { normalizePrice } from './utils-normalizer'; | ||
|
||
export const normalizeCart = (syliusCart: SyliusCart): Cart => { | ||
return { | ||
id: syliusCart.tokenValue, | ||
checkoutUrl: '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pourquoi on la laisse vide là ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parce que le checkout est pas géré pour le moment et j'ai aucune idée de ce qu'on va faire :D |
||
cost: { | ||
subtotalAmount: normalizePrice(syliusCart.itemsTotal), | ||
totalAmount: normalizePrice(syliusCart.total), | ||
totalTaxAmount: normalizePrice(syliusCart.taxTotal) | ||
}, | ||
lines: syliusCart.items.map((item) => normalizeCartItem(item)), | ||
totalQuantity: syliusCart.items.reduce((acc, item) => acc + item.quantity, 0) | ||
}; | ||
}; | ||
|
||
const normalizeCartItem = (syliusCartItem: SyliusCartItem): CartItem => { | ||
return { | ||
id: syliusCartItem.id.toString(), | ||
quantity: syliusCartItem.quantity, | ||
cost: { | ||
totalAmount: normalizePrice(syliusCartItem.total) | ||
}, | ||
merchandise: { | ||
id: syliusCartItem.variant.id.toString(), | ||
title: syliusCartItem.variant.name, | ||
selectedOptions: syliusCartItem.variant.optionValues.map((optionValue) => | ||
normalizeOrderItemOptionValue(optionValue, syliusCartItem.product.options) | ||
), | ||
product: normalizeProduct(syliusCartItem.product) | ||
} | ||
}; | ||
}; | ||
|
||
const normalizeOrderItemOptionValue = ( | ||
optionValue: SyliusProductOptionValue, | ||
options: SyliusProductOption[] | ||
): { name: string; value: string } => { | ||
const selectedOption = options.filter((option) => | ||
option.values.some((value) => value.code === optionValue.code) | ||
)[0]; | ||
return { | ||
name: selectedOption?.name ?? '', | ||
value: optionValue.value | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Money } from '../types'; | ||
|
||
export const normalizePrice = (amount: number): Money => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on pourrait mettre la currency en param optionnel avec EUR en défaut ? |
||
amount: centsPriceToUnitsPrice(amount).toString(), | ||
currencyCode: 'EUR' | ||
}); | ||
|
||
export const centsPriceToUnitsPrice = (amount: number): number => amount / 100; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { SyliusProduct, SyliusProductOptionValue, SyliusProductVariant } from './product-types'; | ||
|
||
export interface SyliusCart { | ||
id: number; | ||
tokenValue: string; | ||
currencyCode: string; | ||
taxTotal: number; | ||
itemsTotal: number; | ||
total: number; | ||
taxExcludedTotal: number; | ||
taxIncludedTotal: number; | ||
shippingTotal: number; | ||
orderPromotionTotal: number; | ||
items: SyliusCartItem[]; | ||
} | ||
|
||
export interface SyliusCartItem { | ||
id: number; | ||
productName: string; | ||
quantity: number; | ||
unitPrice: number; | ||
discountedUnitPrice: number; | ||
variant: SyliusProductVariant; | ||
optionValues: SyliusProductOptionValue[]; | ||
product: SyliusProduct; | ||
adjustments: SyliusAdjustment[]; | ||
total: number; | ||
} | ||
|
||
export interface SyliusAdjustment { | ||
id: number; | ||
type: string; | ||
label: string; | ||
amount: number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
faudrait pas juste qu'on configure le prettier ? surtout si j'arrive à faire marcher mon front et que je commence à coder haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Si 👍