Hey, what’s up everyone. All good?
I’m trying to add items to the orderForm, already with a selected attachment.
First I tried using the addItems hook from “vtex.order-items/OrderItems”
const items = selectedProducts.map(product => {
return {
id: product.skuId,
quantity: product.selectedQuantity,
seller: product.sellerId,
attachments: [
{
content: {"vtex.subscription.key.frequency": "1 month"},
name: "vtex.subscription.teste"
}
]
}
})
await addItems([...items]);
It adds to the cart, but without the attachment I passed in.
Another alternative was to try using the checkout GraphQL:
I put together the mutation in the admin, but it returns 400 “BAD_USER_INPUT” — I believe I’m passing the “attachmentContent” incorrectly, but in the GraphQL docs it doesn’t have a defined type, so I’m not exactly sure how to pass it, I’ve already tried every possible way.
Is there any other way to pass an attachment so that when the product reaches checkout it’s already selected??
Eu já tentei usar a API graphql para isso, mas infelizmente a VTEX ainda não documentou os tipos de algumas mutations, por conta disso tambem nao consegui usar uma mudation/query para isso, mas eu consegui fazer isso usando uma API rest do checkout, segue o exemplo
fetch(
/api/checkout/pub/orderForm/${ID DO ORDERFORM}/items/${POSICAO DO SKU NO CARRINHO}/attachments/${NOME DO ANEXO CADASTRADO NO ADMIN},
{
headers: {
},
body: JSON.stringify({
content: {
‘NOME DO ITEM DO ANEXO’: ‘VALOR DO ANEXO’
},
expectedOrderFormSections: [
‘items’,
‘totalizers’,
‘clientProfileData’,
‘shippingData’,
‘paymentData’,
‘sellers’,
‘messages’,
‘marketingData’,
‘clientPreferencesData’,
‘storePreferencesData’,
‘giftRegistryData’,
‘ratesAndBenefitsData’,
‘openTextField’,
‘commercialConditionData’,
‘customData’,
],
noSplitItem: true,
}),
method: ‘POST’,
mode: ‘cors’,
credentials: ‘include’,
}
)
tenta isso e me avise se funcionar para voce!
Hey, @Erislandio. Sorry for the late reply.
Dude, the solution I found here was to set a localStorage and then at checkout use vtex.js’s addItemsAttachments to add them.
VTEX also got back to me about checkout-graphql, saying they don’t recommend using it since it’s experimental code.
I did try your option, but since I have to send a lot of items, it ends up taking too long to add all of them. But thanks a lot for the reply, cheers!