From 9e67677d471773fd793639b2c2b8c11b718d5158 Mon Sep 17 00:00:00 2001 From: Dustin Firman Date: Wed, 24 Jul 2024 10:34:14 -0400 Subject: [PATCH] B2B examples --- .../query.graphql | 33 +++++++++++++++++++ .../variables.json | 6 ++++ .../query.graphql | 21 ++++++++++++ .../variables.json | 8 +++++ 4 files changed, 68 insertions(+) create mode 100644 examples/10_B2B/01_get_contextualized_products/query.graphql create mode 100644 examples/10_B2B/01_get_contextualized_products/variables.json create mode 100644 examples/10_B2B/02_create_a_cart_with_buyer_identity/query.graphql create mode 100644 examples/10_B2B/02_create_a_cart_with_buyer_identity/variables.json diff --git a/examples/10_B2B/01_get_contextualized_products/query.graphql b/examples/10_B2B/01_get_contextualized_products/query.graphql new file mode 100644 index 0000000..49e9251 --- /dev/null +++ b/examples/10_B2B/01_get_contextualized_products/query.graphql @@ -0,0 +1,33 @@ +# Including the buyer argument on the @inContext directive will contextualize any storefront queries for a B2B customer. + +# With a contextualized query, you can access a quantityRule and quantityPriceBreaks on a product variant, as well as get a price that's contextualized for the B2B customer. + +# The customerAccessToken and companyLocationId in the BuyerInput are obtained from the Customers API. For details on how to obtain those, see [Headless with B2B](https://shopify.dev/docs/storefronts/headless/bring-your-own-stack/b2b) + +query getProductsQuantityRules ($buyer: BuyerInput) @inContext(buyer: $buyer) { + products(first: 5) { + nodes { + id + variants(first: 5) { + nodes { + id + price + quantityRule { + maximum + minimum + increment + } + quantityPriceBreaks(first: 5) { + nodes { + minimumQuantity + price { + amount + currencyCode + } + } + } + } + } + } + } +} diff --git a/examples/10_B2B/01_get_contextualized_products/variables.json b/examples/10_B2B/01_get_contextualized_products/variables.json new file mode 100644 index 0000000..79f4249 --- /dev/null +++ b/examples/10_B2B/01_get_contextualized_products/variables.json @@ -0,0 +1,6 @@ +{ + "buyer": { + "customerAccessToken": "shpsb_eyJh123456789", + "companyLocationId": "gid://shopify/CompanyLocation/10079785100" + } +} diff --git a/examples/10_B2B/02_create_a_cart_with_buyer_identity/query.graphql b/examples/10_B2B/02_create_a_cart_with_buyer_identity/query.graphql new file mode 100644 index 0000000..5d2eee4 --- /dev/null +++ b/examples/10_B2B/02_create_a_cart_with_buyer_identity/query.graphql @@ -0,0 +1,21 @@ +# Including the buyerIdentity of a B2B customer will create a contexualized cart. Checkouts made with this cart will be B2B checkouts. + +# The customerAccessToken and companyLocationId in the buyerIdentity are obtained from the Customers API. For details on how to obtain those, see [Headless with B2B](https://shopify.dev/docs/storefronts/headless/bring-your-own-stack/b2b) + +mutation createCart($cartInput: CartInput) { + cartCreate(input: $cartInput) { + cart { + id + createdAt + updatedAt + buyerIdentity { + email + phone + customer { + id + } + countryCode + } + } + } +} diff --git a/examples/10_B2B/02_create_a_cart_with_buyer_identity/variables.json b/examples/10_B2B/02_create_a_cart_with_buyer_identity/variables.json new file mode 100644 index 0000000..7219df8 --- /dev/null +++ b/examples/10_B2B/02_create_a_cart_with_buyer_identity/variables.json @@ -0,0 +1,8 @@ +{ + "cartInput": { + "buyerIdentity": { + "customerAccessToken": "shpsb_eyJh123456789", + "companyLocationId": "gid://shopify/CompanyLocation/10079785100" + } + } +}