Skip to content
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

fix: Cart item with additionalProperty #1325

Merged
merged 2 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions packages/api/src/platforms/vtex/resolvers/validateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
IStoreCart,
IStoreOffer,
IStoreOrder,
IStorePropertyValue,
} from '../../../__generated__/schema'
import type {
OrderForm,
Expand All @@ -20,17 +21,18 @@ import {

type Indexed<T> = T & { index?: number }

const getAttachments = (item: IStoreOffer) =>
item.itemOffered.additionalProperty?.filter(
(i) => i.valueReference === VALUE_REFERENCES.attachment
)
const isAttachment = (value: IStorePropertyValue) =>
value.valueReference === VALUE_REFERENCES.attachment

const getId = (item: IStoreOffer) =>
[
item.itemOffered.sku,
item.seller.identifier,
item.price,
item.itemOffered.additionalProperty?.map(getPropertyId).join('-'),
item.itemOffered.additionalProperty
?.filter(isAttachment)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this function be the same in the starters as well? How can we manage the fact that the starters can't know what attachments are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the starters side I think it's ok. The issue arises when mixing checkout API with @faststore/api. If you are using only one or the other I think you're safe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So by that logic, we are able to insert VTEX concepts in the starters, as long as they follow @faststore/api schemas, right? That way we can guarantee they won't break if used with another platform (although it's not going to be a graceful experience).

Copy link
Contributor Author

@tlgimenes tlgimenes May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I mean, we do that with the channel. Channel is a concept of @faststore, but what goes inside that string differs from each platform.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it!

.map(getPropertyId)
.join('-'),
]
.filter(Boolean)
.join('::')
Expand Down Expand Up @@ -59,7 +61,9 @@ const offerToOrderItemInput = (
seller: offer.seller.identifier,
id: offer.itemOffered.sku,
index: offer.index,
attachments: (getAttachments(offer) ?? []).map((attachment) => ({
attachments: (
offer.itemOffered.additionalProperty?.filter(isAttachment) ?? []
).map((attachment) => ({
name: attachment.name,
content: attachment.value,
})),
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/typeDefs/propertyValue.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type StorePropertyValue {
}

input IStorePropertyValue {
"""
Property id. This propert changes according to the content of the object.
"""
propertyID: String
"""
Property value. May hold a string or the string representation of an object.
"""
Expand Down