0

Can I create a cart and add the products to cart in same request? Maybe using something like variables to pass by the cartId.

1
  • describe some more detail, what you are looking for? Aug 1, 2020 at 13:42

1 Answer 1

0

Yes, but you'd need to create your own graphql endpoint.

For your case, if you want to implement that type of custom graphql call, you'd need to take a look at vendor/magento/module-quote-graph-ql/etc/schema.graphqls

specifically both graphql calls:

   type Mutation {
        createEmptyCart(input: createEmptyCartInput): String @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CreateEmptyCart") @doc(description:"Creates an empty shopping cart for a guest or logged in user")
        addSimpleProductsToCart(input: AddSimpleProductsToCartInput): AddSimpleProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")

then, the difficult part is to combine

\Magento\QuoteGraphQl\Model\Resolver\CreateEmptyCart with \Magento\QuoteGraphQl\Model\Resolver\AddSimpleProductsToCart into your own custom resolver.

it is doable but challenging. The customisation duplicates a lot of code out of these 2 resolvers and I do wonder whether that is worth the try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.