|
| 1 | +import { LineItem } from '../line-item'; |
| 2 | + |
| 3 | +import { HeadlessLineItem } from './headless-cart'; |
| 4 | + |
| 5 | +export default function mapToLineItem(lineItem: HeadlessLineItem): LineItem { |
| 6 | + const { |
| 7 | + entityId, |
| 8 | + name, |
| 9 | + quantity, |
| 10 | + productEntityId, |
| 11 | + brand, |
| 12 | + couponAmount, |
| 13 | + discountedAmount, |
| 14 | + discounts, |
| 15 | + extendedListPrice, |
| 16 | + extendedSalePrice, |
| 17 | + imageUrl, |
| 18 | + isTaxable, |
| 19 | + listPrice, |
| 20 | + salePrice, |
| 21 | + sku, |
| 22 | + url, |
| 23 | + variantEntityId, |
| 24 | + selectedOptions, |
| 25 | + } = lineItem; |
| 26 | + |
| 27 | + return { |
| 28 | + id: entityId, |
| 29 | + name, |
| 30 | + quantity, |
| 31 | + productId: productEntityId, |
| 32 | + brand, |
| 33 | + couponAmount: couponAmount.value, |
| 34 | + discountAmount: discountedAmount.value, |
| 35 | + discounts: discounts.map((discount) => ({ |
| 36 | + discountedAmount: discount.discountedAmount.value, |
| 37 | + // TODO:: discount item does not have name field in response body when making request using REST API, but there is name in interface, for a while set name as entityID |
| 38 | + name: discount.entityId, |
| 39 | + })), |
| 40 | + extendedListPrice: extendedListPrice.value, |
| 41 | + extendedSalePrice: extendedSalePrice.value, |
| 42 | + imageUrl, |
| 43 | + isTaxable, |
| 44 | + listPrice: listPrice.value, |
| 45 | + salePrice: salePrice.value, |
| 46 | + sku, |
| 47 | + url, |
| 48 | + variantId: variantEntityId, |
| 49 | + options: selectedOptions?.map((option) => ({ |
| 50 | + name: option.name, |
| 51 | + nameId: option.entityId, |
| 52 | + value: option.value, |
| 53 | + valueId: option.valueEntityId, |
| 54 | + })), |
| 55 | + |
| 56 | + // TODO:: we do not have any information regarding to fields below in the GraphQL Storefront doc |
| 57 | + addedByPromotion: false, |
| 58 | + comparisonPrice: 0, |
| 59 | + extendedComparisonPrice: 0, |
| 60 | + retailPrice: 0, |
| 61 | + }; |
| 62 | +} |
0 commit comments