Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How to get the selected Location from a B2B customer using Checkout UI Extension

How to get the selected Location from a B2B customer using Checkout UI Extension

jbriceno
Shopify Partner
3 0 4

Hi,

 

We are creating a Checkout UI extension for our own store, where we need to show a drop-down list for the Buyer to select the Sales Rep for this order. Available Sales Reps are a list on the Company Location's Metafields.

 

How can we get the selected Location and the Location's Metafileds for a B2B customer from the UI Extension.

 

useCustomer is returning undefined, buyerIdentity from useExtensionAPI() only gets the customer email and we cant find a way to get B2B variables.

 

We get more details from a non-B2B customer, which makes no sense, the UI extension and checkout functions are  supposed to be the way to customize the checkout for B2B customers. For D2C customer we already do it using liquid and JS files.

 

Appreciate any help.

Replies 3 (3)

Liam
Community Manager
3108 344 910

Hi Jbriceno, You're correct that the `useCustomer` hook and `buyerIdentity` do not provide direct access to B2B-related variables in Shopify. In order to access B2B-related variables, such as the selected location, within a Checkout UI extension, you'll need to use a different approach. One possible solution is to leverage the Shopify Storefront API to retrieve the necessary information.

Here's a general outline of the steps you can follow:

  1. Create a custom API endpoint or GraphQL resolver on your Shopify app's backend to fetch the B2B-related information for a specific customer.
  2. From your Checkout UI extension, make an API request or GraphQL query to the custom endpoint or resolver, passing the customer's identifier (e.g., customer ID or email) as a parameter.
  3. Implement the logic on your backend to retrieve the selected location and its metafields for the given customer. You can use the Shopify Storefront API or GraphQL to fetch this information. Ensure that the necessary permissions are set up for your app to access the required data.
  4. Return the retrieved data from the custom endpoint or resolver as a response to the frontend.
  5. Handle the response in your Checkout UI extension and utilize the received data to populate the dropdown list for selecting the sales rep.

This will allow you to fetch B2B-related variables and make them available in your Checkout UI extension. 

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

MartinKrauser
Shopify Partner
2 0 1
buyerIdentity {
  purchasingCompany {
    company
  }
}

Why wouldn't this query work?

jbriceno
Shopify Partner
3 0 4

Hi Martin,

 

This works from a Checkout Function but not from a UI Extension. Not a clue why would Shopify restrict the data on the UI Extension....