Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 2.48 KB

checkout-shopping-cart.md

File metadata and controls

78 lines (60 loc) · 2.48 KB
layout group title subtitle level3_subgroup return_to menu_order functional_areas contributor_name contributor_link
tutorial
graphql
Step 2. Create an empty cart
GraphQL checkout tutorial
graphql-checkout
title url
GraphQL Overview
graphql/index.html
20
Integration
Atwix

The procedure for creating a cart varies for logged-in customers and guests.

The customerCart query returns the active cart for the logged-in customer. If the cart does not exist, the query creates one. You must specify the customer’s authorization token in the headers. Otherwise, the query fails. ["Get customer authorization token"]({{ page.baseurl }}/graphql/authorization-tokens.html) describes these tokens.

For guests, use the createEmptyCart mutation to create an empty shopping cart and generate a cart ID for a guest user. If the guest later logs in as a customer, use the mergeCarts mutation to transfer the contents of the guest cart into the customer's cart.

Create a customer cart

The customer created in the previous step does not have an active cart. The following query creates an empty cart and returns the cart ID. You must specify the customer’s authorization token in the headers of the call.

Request:

{
  customerCart{
    id
  }
}

Response:

{
  "data": {
    "customerCart": {
      "id": "pXVxnNg4PFcK1lD60O5evqF7f4SkiRR1"
    }
  }
}

In the subsequent tutorial steps, the unique shopping cart identifier pXVxnNg4PFcK1lD60O5evqF7f4SkiRR1 will be listed as { CART_ID }. Copy the value of the id attribute. Use this value in subsequent steps wherever the { CART_ID } variable is specified.

Create a guest cart

The following example creates an empty cart for a guest. Do not include an authorization token on any call made on behalf of a guest.

Request:

mutation {
  createEmptyCart
}

Response:

{
  "data": {
    "createEmptyCart": "A7jCcOmUjjCh7MxDIzu1SeqdqETqEa5h"
  }
}

In the subsequent tutorial steps, the unique shopping cart identifier A7jCcOmUjjCh7MxDIzu1SeqdqETqEa5h will be listed as { CART_ID }. Copy the value of the id attribute. Use this value in subsequent steps wherever the { CART_ID } variable is specified.

Verify this step {#verify-step}

There are no additional verification steps. The value of id is not displayed on the website or in the Admin.