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: Consider shouldSplitItem value from ValidateCart mutation response #2528

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion packages/api/src/__generated__/schema.ts

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

8 changes: 5 additions & 3 deletions packages/api/src/platforms/vtex/resolvers/validateCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ const joinItems = (form: OrderForm) => {

const orderFormToCart = async (
form: OrderForm,
skuLoader: Context['loaders']['skuLoader']
skuLoader: Context['loaders']['skuLoader'],
shouldSplitItem?: boolean | null
) => {
return {
order: {
Expand All @@ -176,6 +177,7 @@ const orderFormToCart = async (
...item,
product: await skuLoader.load(`${item.id}-invisibleItems`),
})),
shouldSplitItem,
},
messages: form.messages.map(({ text, status }) => ({
text,
Expand Down Expand Up @@ -371,7 +373,7 @@ export const validateCart = async (
joinItems
)
if (orderNumber) {
return orderFormToCart(newOrderForm, skuLoader)
return orderFormToCart(newOrderForm, skuLoader, shouldSplitItem)
}
}

Expand Down Expand Up @@ -460,5 +462,5 @@ export const validateCart = async (
}

// Step6: There were changes, convert orderForm to StoreCart
return orderFormToCart(updatedOrderForm, skuLoader)
return orderFormToCart(updatedOrderForm, skuLoader, shouldSplitItem)
}
2 changes: 1 addition & 1 deletion packages/api/src/typeDefs/cart.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Shopping cart information.
"""
type StoreCart {
"""
Order information, including `orderNumber` and `acceptedOffer`.
Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`.
"""
order: StoreOrder!
"""
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/typeDefs/order.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type StoreOrder {
Array with information on each accepted offer.
"""
acceptedOffer: [StoreOffer!]!
"""
Indicates whether or not items with attachments should be split.
"""
shouldSplitItem: Boolean
}

"""
Expand Down
4 changes: 2 additions & 2 deletions packages/core/@generated/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const documents = {
types.ServerCollectionPageQueryDocument,
'\n query ServerProductQuery($locator: [IStoreSelectedFacet!]!) {\n ...ServerProduct\n product(locator: $locator) {\n id: productID\n\n seo {\n title\n description\n canonical\n }\n\n brand {\n name\n }\n\n sku\n gtin\n name\n description\n releaseDate\n\n breadcrumbList {\n itemListElement {\n item\n name\n position\n }\n }\n\n image {\n url\n alternateName\n }\n\n offers {\n lowPrice\n highPrice\n lowPriceWithTaxes\n priceCurrency\n offers {\n availability\n price\n priceValidUntil\n priceCurrency\n itemCondition\n seller {\n identifier\n }\n }\n }\n\n isVariantOf {\n productGroupID\n }\n\n ...ProductDetailsFragment_product\n }\n }\n':
types.ServerProductQueryDocument,
'\n mutation ValidateCartMutation($cart: IStoreCart!, $session: IStoreSession!) {\n validateCart(cart: $cart, session: $session) {\n order {\n orderNumber\n acceptedOffer {\n ...CartItem\n }\n }\n messages {\n ...CartMessage\n }\n }\n }\n\n fragment CartMessage on StoreCartMessage {\n text\n status\n }\n\n fragment CartItem on StoreOffer {\n seller {\n identifier\n }\n quantity\n price\n priceWithTaxes\n listPrice\n listPriceWithTaxes\n itemOffered {\n ...CartProductItem\n }\n }\n\n fragment CartProductItem on StoreProduct {\n sku\n name\n unitMultiplier\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n skuVariants {\n activeVariations\n slugsMap\n availableVariations\n }\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n':
'\n mutation ValidateCartMutation($cart: IStoreCart!, $session: IStoreSession!) {\n validateCart(cart: $cart, session: $session) {\n order {\n orderNumber\n acceptedOffer {\n ...CartItem\n }\n shouldSplitItem\n }\n messages {\n ...CartMessage\n }\n }\n }\n\n fragment CartMessage on StoreCartMessage {\n text\n status\n }\n\n fragment CartItem on StoreOffer {\n seller {\n identifier\n }\n quantity\n price\n priceWithTaxes\n listPrice\n listPriceWithTaxes\n itemOffered {\n ...CartProductItem\n }\n }\n\n fragment CartProductItem on StoreProduct {\n sku\n name\n unitMultiplier\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n skuVariants {\n activeVariations\n slugsMap\n availableVariations\n }\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n':
types.ValidateCartMutationDocument,
'\n mutation SubscribeToNewsletter($data: IPersonNewsletter!) {\n subscribeToNewsletter(data: $data) {\n id\n }\n }\n':
types.SubscribeToNewsletterDocument,
Expand Down Expand Up @@ -140,7 +140,7 @@ export function gql(
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(
source: '\n mutation ValidateCartMutation($cart: IStoreCart!, $session: IStoreSession!) {\n validateCart(cart: $cart, session: $session) {\n order {\n orderNumber\n acceptedOffer {\n ...CartItem\n }\n }\n messages {\n ...CartMessage\n }\n }\n }\n\n fragment CartMessage on StoreCartMessage {\n text\n status\n }\n\n fragment CartItem on StoreOffer {\n seller {\n identifier\n }\n quantity\n price\n priceWithTaxes\n listPrice\n listPriceWithTaxes\n itemOffered {\n ...CartProductItem\n }\n }\n\n fragment CartProductItem on StoreProduct {\n sku\n name\n unitMultiplier\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n skuVariants {\n activeVariations\n slugsMap\n availableVariations\n }\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n'
source: '\n mutation ValidateCartMutation($cart: IStoreCart!, $session: IStoreSession!) {\n validateCart(cart: $cart, session: $session) {\n order {\n orderNumber\n acceptedOffer {\n ...CartItem\n }\n shouldSplitItem\n }\n messages {\n ...CartMessage\n }\n }\n }\n\n fragment CartMessage on StoreCartMessage {\n text\n status\n }\n\n fragment CartItem on StoreOffer {\n seller {\n identifier\n }\n quantity\n price\n priceWithTaxes\n listPrice\n listPriceWithTaxes\n itemOffered {\n ...CartProductItem\n }\n }\n\n fragment CartProductItem on StoreProduct {\n sku\n name\n unitMultiplier\n image {\n url\n alternateName\n }\n brand {\n name\n }\n isVariantOf {\n productGroupID\n name\n skuVariants {\n activeVariations\n slugsMap\n availableVariations\n }\n }\n gtin\n additionalProperty {\n propertyID\n name\n value\n valueReference\n }\n }\n'
): typeof import('./graphql').ValidateCartMutationDocument
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
Expand Down
7 changes: 5 additions & 2 deletions packages/core/@generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ export type StoreBreadcrumbList = {
export type StoreCart = {
/** List of shopping cart messages. */
messages: Array<StoreCartMessage>
/** Order information, including `orderNumber` and `acceptedOffer`. */
/** Order information, including `orderNumber`, `acceptedOffer` and `shouldSplitItem`. */
order: StoreOrder
}

Expand Down Expand Up @@ -887,6 +887,8 @@ export type StoreOrder = {
acceptedOffer: Array<StoreOffer>
/** ID of the order in [VTEX order management](https://help.vtex.com/en/tutorial/license-manager-resources-oms--60QcBsvWeum02cFi3GjBzg#). */
orderNumber: Scalars['String']['output']
/** Indicates whether or not items with attachments should be split. */
shouldSplitItem: Maybe<Scalars['Boolean']['output']>
}

/** Organization. */
Expand Down Expand Up @@ -1320,6 +1322,7 @@ export type ValidateCartMutationMutation = {
validateCart: {
order: {
orderNumber: string
shouldSplitItem: boolean | null
acceptedOffer: Array<{
quantity: number
price: number
Expand Down Expand Up @@ -2069,7 +2072,7 @@ export const ServerProductQueryDocument = {
export const ValidateCartMutationDocument = {
__meta__: {
operationName: 'ValidateCartMutation',
operationHash: '324471076994dca94a47adcaf1c6b8f7896e1b4f',
operationHash: 'c2b3f8bff73ebf6ac79d758c66cabbc21ba9fcc0',
},
} as unknown as TypedDocumentString<
ValidateCartMutationMutation,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/sdk/cart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ValidateCartMutation = gql(`
acceptedOffer {
...CartItem
}
shouldSplitItem
}
messages {
...CartMessage
Expand Down Expand Up @@ -144,6 +145,7 @@ const validateCart = async (cart: Cart): Promise<Cart | null> => {
id: getItemId(item),
})),
messages: validated.messages,
shouldSplitItem: validated.order.shouldSplitItem,
}
)
}
Expand Down
Loading