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

fix: Cart item with additionalProperty #1325

merged 2 commits into from
May 30, 2022

Conversation

tlgimenes
Copy link
Contributor

@tlgimenes tlgimenes commented May 27, 2022

What's the purpose of this pull request?

When adding a product to cart with additionalProperties we were receiving the following error:

GraphQLError [Object]: Variable "$additionalProperty" got invalid value { propertyID: "4ba0a4d37b7f733da5ddb281ea50d883", name: "activeSubscriptions", value: "abonnements", valueReference: "SPECIFICATION" }; Field "propertyID" is not defined by type IStorePropertyValue.

This PR addresses this issue

Starters

@tlgimenes tlgimenes requested a review from a team as a code owner May 27, 2022 22:20
@vercel
Copy link

vercel bot commented May 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
faststore ✅ Ready (Inspect) Visit Preview May 30, 2022 at 2:12PM (UTC)

Copy link
Contributor

@icazevedo icazevedo left a comment

Choose a reason for hiding this comment

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

Doesn't this defeat the whole purpose of not having to serialize the attachment id on the frontend?

@tlgimenes
Copy link
Contributor Author

Doesn't this defeat the whole purpose of not having to serialize the attachment id on the frontend?

Not really. We still don't need to serialize anything on the frontend.

@icazevedo
Copy link
Contributor

Doesn't this defeat the whole purpose of not having to serialize the attachment id on the frontend?

Not really. We still don't need to serialize anything on the frontend.

It's not clear to me how it wouldn't. This is a required property on input, and we use it for the validateCart mutation. When people are sending attachments to the cart with the items, they don't have the id yet because they're creating this object on the frontend, and to have it, they must serialize it.

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 30, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 00fef03:

Sandbox Source
Store UI Typescript Configuration

@tlgimenes tlgimenes changed the title fix property id fix: Cart item with additionalProperty May 30, 2022
@tlgimenes
Copy link
Contributor Author

tlgimenes commented May 30, 2022

Doesn't this defeat the whole purpose of not having to serialize the attachment id on the frontend?

Not really. We still don't need to serialize anything on the frontend.

It's not clear to me how it wouldn't. This is a required property on input, and we use it for the validateCart mutation. When people are sending attachments to the cart with the items, they don't have the id yet because they're creating this object on the frontend, and to have it, they must serialize it.

Ok, I think I've precipitated myself on openning this PR that early, however I think it's working now.

We had two issues. The first one is that when fetching a product, additionalProperties was fetched alongside the propertyID. When adding this product to cart, this propertyID would be send to the backend, causing this error:

GraphQLError [Object]: Variable "$additionalProperty" got invalid value { propertyID: "4ba0a4d37b7f733da5ddb281ea50d883", name: "activeSubscriptions", value: "abonnements", valueReference: "SPECIFICATION" }; Field "propertyID" is not defined by type IStorePropertyValue.

To fix this issue, I added a non required field on IStorePropertyValue

The second issue was that adding a product to cart with additionalProperties would result in the item being removed from cart. This was because of the orderForm item lacking specifications and only having attachments. Adding a filter to getId functions seems to have fixed this issue.

A good case for this PR is this store , that has specifications set and after this PR, should have the bug fixed and the cart should work as intended. Also, I added links to this PR on our official starters

Copy link
Contributor

@icazevedo icazevedo left a comment

Choose a reason for hiding this comment

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

I understand the issues now. Thanks!


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!

@tlgimenes tlgimenes merged commit 8fa6aa1 into main May 30, 2022
@tlgimenes tlgimenes deleted the fix/propertyid branch May 30, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants