Skip to content

Commit

Permalink
chore: inlining additionalProperty serialization for cart item id
Browse files Browse the repository at this point in the history
  • Loading branch information
icazevedo committed May 25, 2022
1 parent 9366100 commit 41eb7a6
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/sdk/cart/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,16 @@ export const ValidateCartMutation = gql`

export const isGift = (item: CartItem) => item.price === 0

const serializeAdditionalProperty = (itemOffered: CartItem['itemOffered']) => {
if (
!itemOffered.additionalProperty ||
itemOffered.additionalProperty?.length === 0
) {
return null
}

return itemOffered.additionalProperty
.map(({ propertyID }) => propertyID)
.join('-')
}

export const getItemId = (
item: Pick<CartItem, 'itemOffered' | 'seller' | 'price'>
) =>
[
item.itemOffered.sku,
item.seller.identifier,
item.price,
serializeAdditionalProperty(item.itemOffered),
item.itemOffered.additionalProperty
?.map(({ propertyID }) => propertyID)
.join('-'),
]
.filter(Boolean)
.join('::')
Expand Down

0 comments on commit 41eb7a6

Please sign in to comment.