Skip to content

International pricing

In Afosto, you have the flexibility to define different price lists for different countries. To implement these price lists for a specific country in the context of a cart, we can set a country code on the cart.

WARNING This property only affects the cart's pricing. It is the responsibility of the developer to ensure the correct prices are displayed on the storefront based on the selected country.

Setting a country code can be achieved using the Afosto client or a GraphQL mutation.

Using Afosto client

Here's how you can set a country code using the Afosto JavaScript client:

```js
const cart = await client.setCountryCodeOnCart('FR');

In this example, we're setting the country code to 'FR' for France. You can replace 'FR' with the appropriate country code.

### Using GraphQL

Alternatively, you can set a country code on the cart using a GraphQL mutation. The setCountryCodeOnCart mutation allows you to specify a country code for a given cart.

import { gql } from '@afosto/storefront';
import StorefrontClient, { CoreCartFragment } from '@afosto/storefront';

const client = StorefrontClient({
  storefrontToken: 'STOREFRONT_TOKEN',
});

const query = gql`
  ${CoreCartFragment}
  mutation SetCountryCodeOnCart($set_country_code_on_cart_input: SetCountryCodeOnCartInput!) {
    setCountryCodeOnCart(input: $set_country_code_on_cart_input) {
      cart {
        ...CoreCartFragment
      }
    }
  }
`;

const variables = {
  setCountryCodeOnCartInput: {
		cartId: client.getCartTokenFromStorage(),
    countryCode: 'FR',
  },
};

const response = await client.query(query, variables);

Here we're using the SetCountryCodeOnCart mutation, passing in the cart ID and the country code. Note that we're using 'FR' as the country code in this example. You should replace 'FR' with the desired country code.

This GraphQL mutation will return a cart object (with the applied country code), which can then be used as needed within your application.

Related documentation