0

How can we add products in the cart according to the website?

I have multiple websites in a single Magento installation. When I am adding a product by GraphQl then it's adding the product on the base website. Not in the targeted website.

Even my all website URL is different and Graphql endpoint also using according to the website. But it's adding in base website

For example, My endpoint is below

www.example-website2.com/graphql

But it's adding the product in below website

www.example-website1.com/graphql

Where I need to pass website id in below mutation. I have created token and cart id from this URL www.example-website2.com/graphql

mutation {
  addSimpleProductsToCart(
    input: {
      cart_id: "{ CART_ID }"
      cart_items: [
        {
          data: {
            quantity: 1
            sku: "simple-product"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        id
        product {
          sku
          stock_status
        }
        quantity
      }
    }
  }
}

1 Answer 1

2

The official documentation says Magento accepts the following headers in a GraphQL request: Store code is one among them, so you can pass store code as a header parameter.

  • Authorization
  • Content-Currency
  • Content-Type
  • Preview-Version
  • Store

https://devdocs.magento.com/guides/v2.4/graphql/send-request.html

Never tested though, but this will guide you.

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.