-
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 1 commit
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: '', | ||
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 rightOption = options.filter((option) => | ||
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. je pense qu'en terme de naming option ça passe, et tu peux utiliser option.value pour le return |
||
option.values.some((value) => value.code === optionValue.code) | ||
)[0]; | ||
return { | ||
name: rightOption?.name ?? '', | ||
value: optionValue.value | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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: (amount / 100).toString(), | ||
currencyCode: 'EUR' | ||
}); |
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.
pourquoi on la laisse vide là ?
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.
Parce que le checkout est pas géré pour le moment et j'ai aucune idée de ce qu'on va faire :D