Lab - Query Practice
Lab - Query Practice
Lab - Query Practice
The cart created in this lab activity will be maintained across requests because of the storefront session cookie used in the GraphQL Playground environment.
In this mutation, we will create a cart using a simple product (ID = 81).
createCartInput that contains the line item in the cart. Note that what you input for the quantity and productEntityId will be different than what is shown below.cart field and specify that we want to createCart based on the variable, and that you want the response to show the entityId, name, and quantity of the physical item added to the cart.When there is customer context for the GraphQL request that creates a cart (whether from a client-side session or a customer access token), the cart will be assigned to and accessible only by that customer.
In this query, we will ask for the cart ID, currency, and line items. We will further ask for product pricing information and shipping requirements.
root, site field, and cart field. Specify next to the cart field that we want the entityId, currencyCode, and amount in the response.entityId, sku, name, and quantity of the physicalItems in the cart.In this mutation, we will add another physical item to the cart.
addCartLineItemsInput that contains the cartEntityId and lineItems that will be added to the cart. Note that what you input for the cartEntityId and productEntityId will be different than what is shown below.cart field and specify that we want to addCartLineItems based on the variable and want the response to show the cart entityId.In order to load the cart that was created in a headless storefront into the BigCommerce storefront’s own session, you will need to create a cart redirect URL. The steps below will walk you through creating a cart redirect URL with the GraphQL Storefront API. You have the option to create a redirect URL for embedded checkout and redirected checkout, but the example below only shows redirectedCheckoutURL.
Before completing the steps below, you will need the cartEntityId from the cart created in previous lab steps.
cartId that contains the cartEntityId of the cart you want to use for the redirect URL. Note that what you input for cartId will be different than what is shown below.cart field and specify that we want to createCartRedirectUrls based on the variable and want the response to show the redirectedCheckoutUrl and embeddedCheckoutUrl.When a cart belongs to a registered customer, it’s important that the customer’s logged-in session be maintained when redirecting to checkout.
For client-side requests relying on the BigCommerce storefront session cookie, this is taken care of automatically, as the same session that establishes the customer context for the GraphQL requests is also responsible for their logged-in status in Stencil.
For server-side requests, as long as the appropriate customer access token is provided in the createCartRedirectUrls request, the redirect URL will automatically log the user into this customer session in addition to loading the cart.
In this mutation, you will delete a cart.
This step is optional because the next lab activity (Get Checkout) uses the information from the cart you created in the previous steps.
deleteCartInput that contains the entityId of the cart that will be deleted. Note that what you input for the cartEntityId and will be different than what is shown below.cart field and specify that we want to deleteCart based on the variable and want the response to show the cart deletedCartEntityId.In this query, we will request checkout information such as the billing address, order ID, subtotal, grand total, and outstanding balance.
If you completed the optional step above and deleted the cart, you will need to create a new cart. Go back to the beginning of this lab and follow the steps to create a new cart.
root, site field, and checkout field. Specify next to the checkout field that we want the entityId, billingAddress, orderId, subTotal, grandTotal, and outstandingBalance in the response.In this mutation, we will add a billing address to the checkout we queried in the previous step.
addCheckoutBillingAddressInput that contains the billing address information to be added. Note that what you input for the checkoutEntityId and in the address fields will be different than what is shown below.checkout field and specify that we want to addCheckoutBillingAddress based on the variable and want the response to show the checkout entityId.In this mutation, we will add a shipping address to the checkout.
lineItem entityIds. In the GraphQL playground, begin writing the query with the root, site field, and cart field. Specify next to the cart field that we want the entityId for each lineItem in the response.addCheckoutShippingConsignmentsInput that contains the checkout entityId, shipping address, entityId, and quantity for each lineItem. Note that what you input for the checkoutEntityId, address, and lineItems fields will be different than what is shown below. Additionally, you can add more or less lineItems to this variable if needed.checkout field and specify that we want to addCheckoutShippingConsignments based on the variable and want the response to show the checkout entityId, shipping consignment entityId, available shipping options, and selected shipping option.In this mutation, we will select a shipping option for the checkout.
root, site field, checkout field, and shipping consignments field. Specify next to the shipping consignments field that we want the entityId, description, and type for each availableShippingOptions in the response.selectCheckoutShippingOptionInput that contains the checkout entityId, consignment entityId, and shipping option entityId.checkout field and specify that we want to selectCheckoutShippingOption based on the variable and want the response to show the checkout entityId.In this mutation, we will complete the checkout that we created in the previous steps.
completeCheckoutInput that contains the checkout entityId.checkout field and specify that we want to completeCheckout based on the variable and want the response to show the order entityId and payment access token.