Skip to content

Commit

Permalink
b2b examples
Browse files Browse the repository at this point in the history
Generate README

Update Insomnia package

folder rename

folder rename

formatting

one line comment

Generate README

Update Insomnia package

Generate README

Update Insomnia package

added trailing newlines

Generate README

Update Insomnia package

oneline input

Generate README

Update Insomnia package
  • Loading branch information
dustinfirman committed Jul 24, 2024
1 parent 88baef5 commit b55cbce
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2112,3 +2112,92 @@ variables
</details>

---
### B2B
<details><summary><strong>Get contextualized products</strong></summary>
<p>

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)

```gql
query getB2BProducts ($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
}
}
}
}
}
}
}
}

variables
{
"buyer": {
"customerAccessToken": "shpsb_eyJh123456789",
"companyLocationId": "gid://shopify/CompanyLocation/10079785100"
}
}
```
</p>
</details>
<details><summary><strong>Create a cart with buyer identity</strong></summary>
<p>

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)

```gql
mutation createCart($cartInput: CartInput) {
cartCreate(input: $cartInput) {
cart {
id
createdAt
updatedAt
buyerIdentity {
email
phone
customer {
id
}
countryCode
}
}
}
}

variables
{
"cartInput": {
"buyerIdentity": {
"customerAccessToken": "shpsb_eyJh123456789",
"companyLocationId": "gid://shopify/CompanyLocation/10079785100"
}
}
}
```
</p>
</details>

---
2 changes: 1 addition & 1 deletion builds/storefront-api-learning-kit-insomnia.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions examples/10_B2B/01_get_contextualized_products/query.graphql
Original file line number Diff line number Diff line change
@@ -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 getB2BProducts ($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
}
}
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions examples/10_B2B/01_get_contextualized_products/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"buyer": {
"customerAccessToken": "shpsb_eyJh123456789",
"companyLocationId": "gid://shopify/CompanyLocation/10079785100"
}
}
21 changes: 21 additions & 0 deletions examples/10_B2B/02_create_a_cart_with_buyer_identity/query.graphql
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"cartInput": {
"buyerIdentity": {
"customerAccessToken": "shpsb_eyJh123456789",
"companyLocationId": "gid://shopify/CompanyLocation/10079785100"
}
}
}

0 comments on commit b55cbce

Please sign in to comment.